[PATCH v11 12/23] mm: Avoid zeroing CoCo shared allocations twice
Aneesh Kumar K.V (Arm)
aneesh.kumar at kernel.org
Wed Dec 2 01:54:35 PST 2026
cc_make_shared() now clears memory as part of the private-to-shared
transition. The subsequent memset() in alloc_cc_shared_node() therefore
clears the same allocation again.
Remove that memset() and leave __GFP_ZERO masked when memory encryption
is active. When encryption is inactive, set __GFP_ZERO so the page
allocator supplies zeroed memory.
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar at kernel.org>
---
mm/cc_shared.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/mm/cc_shared.c b/mm/cc_shared.c
index e60e2269adb6..7f114ea68ae4 100644
--- a/mm/cc_shared.c
+++ b/mm/cc_shared.c
@@ -120,6 +120,9 @@ int cc_make_private(void *addr, size_t size)
* allocation or free individual pages. Release the entire allocation with
* free_cc_shared().
*
+ * When memory encryption is active, making the allocation shared always
+ * zeroes it. Clear __GFP_ZERO before allocating to avoid zeroing it twice.
+ *
* Must be called from sleepable context.
* Return: The allocation's linear-map address, or NULL on failure.
*/
@@ -148,7 +151,10 @@ void *alloc_cc_shared_node(int nid, gfp_t gfp, size_t len)
*/
gfp &= ~(__GFP_HIGHMEM | __GFP_MOVABLE);
gfp |= __GFP_COMP;
- gfp &= ~__GFP_ZERO;
+ if (encrypted)
+ gfp &= ~__GFP_ZERO;
+ else
+ gfp |= __GFP_ZERO;
if (nid == NUMA_NO_NODE)
page = alloc_pages(gfp, order);
@@ -171,7 +177,6 @@ void *alloc_cc_shared_node(int nid, gfp_t gfp, size_t len)
return NULL;
}
- memset(addr, 0, size);
return addr;
}
EXPORT_SYMBOL_GPL(alloc_cc_shared_node);
--
2.43.0
More information about the linux-arm-kernel
mailing list