[PATCH v11 07/23] x86/mm: Clear memory after successful decryption transitions
Aneesh Kumar K.V (Arm)
aneesh.kumar at kernel.org
Wed Dec 2 01:54:30 PST 2026
Clear the final mapping after __set_memory_enc_dec() succeeds.
Conversion may change the contents, so zeroing must follow the
successful transition. This applies to the common x86 wrapper, including
when no encryption change is needed.
The VGA caller already uses set_memory_decrypted_nozero() and therefore
does not acquire this new explicit clear. Leave existing caller clears
in place until the subsequent cleanup patches.
Cc: Dave Hansen <dave.hansen at linux.intel.com>
Cc: Andy Lutomirski <luto at kernel.org>
Cc: Peter Zijlstra <peterz at infradead.org>
Cc: Thomas Gleixner <tglx at kernel.org>
Cc: Ingo Molnar <mingo at redhat.com>
Cc: Borislav Petkov <bp at alien8.de>
Cc: x86 at kernel.org
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar at kernel.org>
---
arch/x86/mm/pat/set_memory.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index 16f3f57f973b..bf4466ef1220 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -2545,7 +2545,17 @@ EXPORT_SYMBOL_GPL(set_memory_encrypted);
int set_memory_decrypted(unsigned long addr, int numpages)
{
- return __set_memory_enc_dec(addr, numpages, false);
+ int ret = __set_memory_enc_dec(addr, numpages, false);
+
+ /*
+ * Firmware may scrub pages with nonzero values during private-to-shared
+ * conversion. Clear the final shared mapping after the transition so
+ * that callers receive zeroed memory.
+ */
+ if (!ret)
+ memset((void *)addr, 0, (size_t)numpages << PAGE_SHIFT);
+
+ return ret;
}
EXPORT_SYMBOL_GPL(set_memory_decrypted);
--
2.43.0
More information about the linux-arm-kernel
mailing list