[PATCH v2 1/4] irqchip/gic-v3-its: Zero shared pages after conversion

From: Steven Price

Date: Thu Aug 20 2026 - 11:07:07 EST


its_alloc_pages_node() passes __GFP_ZERO to the page allocator before
calling set_memory_decrypted(). This assumes that converting a page from
private to shared preserves its contents.

For Arm CCA with MEC (Memory Encryption Contexts) the key used to access
the page will change, and so by default the visible data will change.
The host could ensure that it zeros the page, but rather than relying on
the host's behaviour it's best if the guest simply zeros after the
decryption rather than before. Specifically in this case the ITS tables
are required to be zeroed.

Mask out __GFP_ZERO from the allocation request, and do the zeroing as a
separate step after decryption.

Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
Fixes: b08e2f42e86b ("irqchip/gic-v3-its: Share ITS tables with a non-trusted hypervisor")
Signed-off-by: Steven Price <steven.price@xxxxxxx>
---
drivers/irqchip/irq-gic-v3-its.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 6f5811aae59c..a055837832bc 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -213,16 +213,18 @@ static gfp_t gfp_flags_quirk;
static struct page *its_alloc_pages_node(int node, gfp_t gfp,
unsigned int order)
{
+ bool want_zero = gfp & __GFP_ZERO;
struct page *page;
int ret = 0;

- page = alloc_pages_node(node, gfp | gfp_flags_quirk, order);
+ page = alloc_pages_node(node, (gfp & ~__GFP_ZERO) | gfp_flags_quirk,
+ order);

if (!page)
return NULL;

ret = set_memory_decrypted((unsigned long)page_address(page),
- 1 << order);
+ BIT(order));
/*
* If set_memory_decrypted() fails then we don't know what state the
* page is in, so we can't free it. Instead we leak it.
@@ -231,6 +233,9 @@ static struct page *its_alloc_pages_node(int node, gfp_t gfp,
if (ret)
return NULL;

+ if (want_zero)
+ clear_pages(page_address(page), BIT(order));
+
return page;
}

--
2.43.0