Skip to content

Commit 8c89d3a

Browse files
ardbiesheuvelbp3tk0v
authored andcommitted
x86/sev: Don't emit BSS_DECRYPTED section unless it is in use
The BSS_DECRYPTED section that gets emitted into .bss will be empty if CONFIG_AMD_MEM_ENCRYPT is not defined. However, due to the fact that it is injected into .bss rather than emitted as a separate section, the 2 MiB alignment that it specifies is still taken into account unconditionally, pushing .bss out to the next 2 MiB boundary, leaving a gap that is never freed. So only emit a non-empty BSS_DECRYPTED section if it is going to be used. In that case, it would still be nice to free the padding, but that is left for later. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://patch.msgid.link/20260108092526.28586-23-ardb@kernel.org
1 parent af05e55 commit 8c89d3a

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

arch/x86/kernel/vmlinux.lds.S

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,18 @@ const_cpu_current_top_of_stack = cpu_current_top_of_stack;
6767

6868
#define ALIGN_ENTRY_TEXT_BEGIN . = ALIGN(PMD_SIZE);
6969
#define ALIGN_ENTRY_TEXT_END . = ALIGN(PMD_SIZE);
70+
#else
71+
72+
#define X86_ALIGN_RODATA_BEGIN
73+
#define X86_ALIGN_RODATA_END \
74+
. = ALIGN(PAGE_SIZE); \
75+
__end_rodata_aligned = .;
7076

77+
#define ALIGN_ENTRY_TEXT_BEGIN
78+
#define ALIGN_ENTRY_TEXT_END
79+
#endif
80+
81+
#ifdef CONFIG_AMD_MEM_ENCRYPT
7182
/*
7283
* This section contains data which will be mapped as decrypted. Memory
7384
* encryption operates on a page basis. Make this section PMD-aligned
@@ -88,17 +99,9 @@ const_cpu_current_top_of_stack = cpu_current_top_of_stack;
8899
__pi___end_bss_decrypted = .; \
89100

90101
#else
91-
92-
#define X86_ALIGN_RODATA_BEGIN
93-
#define X86_ALIGN_RODATA_END \
94-
. = ALIGN(PAGE_SIZE); \
95-
__end_rodata_aligned = .;
96-
97-
#define ALIGN_ENTRY_TEXT_BEGIN
98-
#define ALIGN_ENTRY_TEXT_END
99102
#define BSS_DECRYPTED
100-
101103
#endif
104+
102105
#if defined(CONFIG_X86_64) && defined(CONFIG_KEXEC_CORE)
103106
#define KEXEC_RELOCATE_KERNEL \
104107
. = ALIGN(0x100); \

0 commit comments

Comments
 (0)