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@linux.intel.com Cc: Andy Lutomirski luto@kernel.org Cc: Peter Zijlstra peterz@infradead.org Cc: Thomas Gleixner tglx@kernel.org Cc: Ingo Molnar mingo@redhat.com Cc: Borislav Petkov bp@alien8.de Cc: x86@kernel.org Signed-off-by: Aneesh Kumar K.V (Arm) aneesh.kumar@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);