From: Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>
To: x86@kernel.org
Cc: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Ard Biesheuvel <ardb@kernel.org>,
Nathan Chancellor <nathan@kernel.org>, Rong Xu <xur@google.com>,
Kees Cook <kees@kernel.org>,
linux-kernel@vger.kernel.org,
Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>
Subject: [PATCH v4] x86/mm/64: free the gap between BSS_MAIN and BSS_DECRYPTED
Date: Mon, 20 Jul 2026 07:20:10 -0400 [thread overview]
Message-ID: <20260720112010.1095917-1-hamzamahfooz@linux.microsoft.com> (raw)
This region is unused and takes up, up to 2 MiB
of memory if AMD_MEM_ENCRYPT is enabled. So, free it in
mem_encrypt_free_decrypted_mem().
Signed-off-by: Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>
---
arch/x86/include/asm/mem_encrypt.h | 3 ++-
arch/x86/kernel/vmlinux.lds.S | 2 ++
arch/x86/mm/mem_encrypt_amd.c | 6 ++++++
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h
index ea6494628cb0..c9722be2808f 100644
--- a/arch/x86/include/asm/mem_encrypt.h
+++ b/arch/x86/include/asm/mem_encrypt.h
@@ -112,7 +112,8 @@ void add_encrypt_protection_map(void);
#define __sme_pa(x) (__pa(x) | sme_me_mask)
#define __sme_pa_nodebug(x) (__pa_nodebug(x) | sme_me_mask)
-extern char __start_bss_decrypted[], __end_bss_decrypted[], __start_bss_decrypted_unused[];
+extern char __start_bss_decrypted_gap[], __start_bss_decrypted[],
+ __end_bss_decrypted[], __start_bss_decrypted_unused[];
#endif /* __ASSEMBLER__ */
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 4711a35e706c..179578a08da1 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -88,6 +88,8 @@ const_cpu_current_top_of_stack = cpu_current_top_of_stack;
* decrypted to avoid exposing more than we wish.
*/
#define BSS_DECRYPTED \
+ . = ALIGN(PAGE_SIZE); \
+ __start_bss_decrypted_gap = .; \
. = ALIGN(PMD_SIZE); \
__start_bss_decrypted = .; \
__pi___start_bss_decrypted = .; \
diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c
index 2f8c32173972..8d518571ae5c 100644
--- a/arch/x86/mm/mem_encrypt_amd.c
+++ b/arch/x86/mm/mem_encrypt_amd.c
@@ -566,4 +566,10 @@ void __init mem_encrypt_free_decrypted_mem(void)
}
free_init_pages("unused decrypted", vaddr, vaddr_end);
+
+ vaddr = PFN_ALIGN(__start_bss_decrypted_gap);
+ vaddr_end = PFN_ALIGN(__start_bss_decrypted);
+
+ free_kernel_image_pages("unused kernel image (bss_decrypted gap)",
+ (void *)vaddr, (void *)vaddr_end);
}
--
2.55.0
next reply other threads:[~2026-07-20 11:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 11:20 Hamza Mahfooz [this message]
2026-07-20 12:10 ` Dave Hansen
2026-07-20 16:02 ` Hamza Mahfooz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260720112010.1095917-1-hamzamahfooz@linux.microsoft.com \
--to=hamzamahfooz@linux.microsoft.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=nathan@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
--cc=xur@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome