[PATCH v11 05/23] powerpc/pseries: Clear memory after making it shared
Aneesh Kumar K.V (Arm)
aneesh.kumar at kernel.org
Wed Dec 2 01:54:28 PST 2026
Clear the final shared mapping after uv_share_page(). Firmware may scrub
memory with nonzero values during conversion, so clearing before sharing
would not guarantee a zeroed result. Also clear the range when memory
encryption is inactive.
Cc: Madhavan Srinivasan <maddy at linux.ibm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar at kernel.org>
---
arch/powerpc/platforms/pseries/svm.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
index 7a403dbd35ee..0970f1fb76d7 100644
--- a/arch/powerpc/platforms/pseries/svm.c
+++ b/arch/powerpc/platforms/pseries/svm.c
@@ -9,6 +9,7 @@
#include <linux/mm.h>
#include <linux/memblock.h>
#include <linux/mem_encrypt.h>
+#include <linux/string.h>
#include <linux/cc_platform.h>
#include <asm/machdep.h>
#include <asm/svm.h>
@@ -53,13 +54,17 @@ int set_memory_encrypted(unsigned long addr, int numpages)
int set_memory_decrypted(unsigned long addr, int numpages)
{
- if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
- return 0;
-
if (!PAGE_ALIGNED(addr))
return -EINVAL;
- uv_share_page(PHYS_PFN(__pa(addr)), numpages);
+ if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
+ uv_share_page(PHYS_PFN(__pa(addr)), numpages);
+ /*
+ * 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.
+ */
+ memset((void *)addr, 0, (size_t)numpages << PAGE_SHIFT);
return 0;
}
--
2.43.0
More information about the linux-arm-kernel
mailing list