[PATCH v2 1/5] x86/sme: Clear decrypted BSS separately

From: Brian Gerst

Date: Thu Jul 30 2026 - 16:00:51 EST


The decrypted BSS section needs to be cleared after it is remapped as
decrypted memory. Separate it so that the normal BSS section can be
cleared earlier.

Signed-off-by: Brian Gerst <brgerst@xxxxxxxxx>
---
arch/x86/kernel/vmlinux.lds.S | 2 +-
arch/x86/mm/mem_encrypt_amd.c | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 2438b89a4620..e64c797e06c7 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -365,9 +365,9 @@ SECTIONS
*(.bss..page_aligned)
. = ALIGN(PAGE_SIZE);
*(BSS_MAIN)
- BSS_DECRYPTED
. = ALIGN(PAGE_SIZE);
__bss_stop = .;
+ BSS_DECRYPTED
}

/*
diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c
index 2f8c32173972..50a53fa10c96 100644
--- a/arch/x86/mm/mem_encrypt_amd.c
+++ b/arch/x86/mm/mem_encrypt_amd.c
@@ -476,6 +476,10 @@ void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, unsigned long s

void __init sme_early_init(void)
{
+ /* Needs to be cleared even if encryption is not enabled */
+ memset(__start_bss_decrypted, 0,
+ (unsigned long) __end_bss_decrypted - (unsigned long) __start_bss_decrypted);
+
if (!sme_me_mask)
return;

--
2.55.0