From nobody Sat Jul 25 02:43:23 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A311133F8D9 for ; Mon, 20 Jul 2026 11:21:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784546490; cv=none; b=hgyPcIw6NINg9kmuUebwlE5onhCVWwfUJtiJTCgpnr69eohua50+Y0cB24MP8t0C3qxJ2SNjfrcOlVOZSP+x368FZMsZOAPjOlXlL+HG93ZA8ePnvHs02UQTkAfg7zzSCEQ1I7Cxps4qBoKIk1Kb5qbRACo+zdLeVj2EjKMO6m4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784546490; c=relaxed/simple; bh=EhKfN11aVJcQzoklIcPnX/WuQZktZ5O7pK31gcV3FNQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=A7Yv1PU7JtO7e9MMim8NXPkH+CuRJtu5wzDxyoSHWkgk8B3xxXi4g/G0z/IQCk2DRFW8YclrCuro+7G3lCSNmTl+f6YJJomBJALScTMELIAMtrHOZjRtSOdFjuRoY9gnaqlrlVw88wGbBeoAjH3Ei49/MtqV5fTPS1f9zl3SCwI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=jR8smO/z; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="jR8smO/z" Received: by linux.microsoft.com (Postfix, from userid 1216) id 21D8B20B7169; Mon, 20 Jul 2026 04:21:11 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 21D8B20B7169 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784546471; bh=u76vzQ5SOE+PZXdCqdCFpbCMAQ8jsEGFVNsd2Cv9hjQ=; h=From:To:Cc:Subject:Date:From; b=jR8smO/z59Jv0PI57uKI0Y9shk5D8YooKeV1Ve863J81bL6QTOfk49jIa5XMp/n3L JuzVWegB4B8p0zZmnqfLn/an3ki/05c68ySoEvTxmGn3SySIOp7iJL76RciAd8lDd6 ZHoaPuJhuUEn+6C2w078VAWrumPOnmEbVM2mepQE= From: Hamza Mahfooz To: x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Ard Biesheuvel , Nathan Chancellor , Rong Xu , Kees Cook , linux-kernel@vger.kernel.org, Hamza Mahfooz Subject: [PATCH v4] x86/mm/64: free the gap between BSS_MAIN and BSS_DECRYPTED Date: Mon, 20 Jul 2026 07:20:10 -0400 Message-ID: <20260720112010.1095917-1-hamzamahfooz@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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) =20 -extern char __start_bss_decrypted[], __end_bss_decrypted[], __start_bss_de= crypted_unused[]; +extern char __start_bss_decrypted_gap[], __start_bss_decrypted[], + __end_bss_decrypted[], __start_bss_decrypted_unused[]; =20 #endif /* __ASSEMBLER__ */ =20 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 =3D cpu_current_top_of_sta= ck; * decrypted to avoid exposing more than we wish. */ #define BSS_DECRYPTED \ + . =3D ALIGN(PAGE_SIZE); \ + __start_bss_decrypted_gap =3D .; \ . =3D ALIGN(PMD_SIZE); \ __start_bss_decrypted =3D .; \ __pi___start_bss_decrypted =3D .; \ 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) } =20 free_init_pages("unused decrypted", vaddr, vaddr_end); + + vaddr =3D PFN_ALIGN(__start_bss_decrypted_gap); + vaddr_end =3D PFN_ALIGN(__start_bss_decrypted); + + free_kernel_image_pages("unused kernel image (bss_decrypted gap)", + (void *)vaddr, (void *)vaddr_end); } --=20 2.55.0