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 Signed-off-by: Aneesh Kumar K.V (Arm) --- 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 #include #include +#include #include #include #include @@ -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