Skip to contentSkip to conversation

irqchip/gic-v3-its: Fixes to table allocation and the ITT pool

PATCH In review Fuad Tabba 3 participants 16 messages Nov 16 – Nov 23

Subsystems (2)
lore
Share & tools
lore

Fuad Tabba

author
#0 lore raw

v2 cover irqchip/gic-v3-its: Fixes to table allocation and the ITT pool

Hi folks,

Changes since v1 [1] [2]:
- Combined the ITT pool fixes [1] and the table zeroing fixes [2] into one series. (Marc)
- Dropped "Zero ITS pages before sharing them with the host". A separate patch fixes it in pkvm_set_memory_decrypted() instead [3], for every caller. (Suzuki)
- Order the zeroing with dsb(ishst), as its_flush_cmd() does, rather

    than dma_wmb().

- Clean the vPE table to PoC unconditionally.
- Point the vPE table patch's Fixes: at the commit that added the table.
- Rebased on 7.4-rc3.
- Collected Reviewed-by from Suzuki on patches 3-5. (thanks!)

Five fixes to how the ITS driver sets up the memory the GIC reads.

The first adds the barrier that was missing between zeroing a table page and the write that makes the page visible to the GIC. The second cleans the GICv4.1 vPE table to PoC, as the driver already does for the pending table. Without the clean, only a redistributor that accesses the table as non-shareable can read stale contents from it.

The other three fix the ITT pool. Its 1-byte granule keeps ITTs aligned only while every ITT's size is a multiple of 256, which holds for power-of-two ITE sizes but not for QEMU's 12-byte ones. The third gives the pool a 256-byte granule. The fourth zeroes an ITT reused from the pool, as MAPD requires. The fifth frees the page when gen_pool_add() fails.

Based on Linux 7.4-rc3 (aebb727447640).

Cheers,
/fuad

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/

Fuad Tabba (5):
irqchip/gic-v3-its: Order table zeroing before the GIC can see it irqchip/gic-v3-its: Clean the GICv4.1 vPE table to PoC irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes irqchip/gic-v3-its: Zero ITTs reused from the ITT pool irqchip/gic-v3-its: Free the page when gen_pool_add() fails

 drivers/irqchip/irq-gic-v3-its.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.47.3
author
#1 lore raw

PATCH v2 1/5 irqchip/gic-v3-its: Order table zeroing before the GIC can see it

The ITS driver allocates the ITS tables and the vPE tables as zeroed pages. It exposes each table with a single store: a relaxed GICR_VPROPBASER write with Valid set, the relaxed GITS_CTLR write that enables the ITS, or a valid level-1 entry for a level-2 page. However, on a shareable table the zeroing isn't ordered before that store, so the GIC can read the page's previous contents as table entries, which the spec makes UNPREDICTABLE (IHI 0069H.b 5.2.1, and GICR_VPROPBASER.Z in 12.11.39). A level-2 page is exposed at runtime, when the GIC may already be walking the level-1 table for other IDs.

Add a dsb(ishst) at the end of its_alloc_pages_node(), as its_flush_cmd() does for a command. The allocator doesn't take a shareability argument, so the barrier is unconditional. On a non-shareable table it doesn't hurt.

---
 drivers/irqchip/irq-gic-v3-its.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v3-its.c +3 -0
index c952c069f9373..9900c6a53526e 100644
@@ -233,6 +233,9 @@ static struct page *its_alloc_pages_node(int node, gfp_t gfp,
 	if (ret)
 		return NULL;
 
+	/* Order the zeroing before any store that exposes the page to the GIC */
+	dsb(ishst);
+
 	return page;
 }
 
Signature · 1 line
2.47.3
Reviewed-by on v2 1/5
#2 lore raw

Re: [PATCH v2 1/5] irqchip/gic-v3-its: Order table zeroing before the GIC can see it

Quoted 15 lines · Fuad Tabba

The ITS driver allocates the ITS tables and the vPE tables as zeroed pages. It exposes each table with a single store: a relaxed GICR_VPROPBASER write with Valid set, the relaxed GITS_CTLR write that enables the ITS, or a valid level-1 entry for a level-2 page. However, on a shareable table the zeroing isn't ordered before that store, so the GIC can read the page's previous contents as table entries, which the spec makes UNPREDICTABLE (IHI 0069H.b 5.2.1, and GICR_VPROPBASER.Z in 12.11.39). A level-2 page is exposed at runtime, when the GIC may already be walking the level-1 table for other IDs.

Add a dsb(ishst) at the end of its_alloc_pages_node(), as its_flush_cmd() does for a command. The allocator doesn't take a shareability argument, so the barrier is unconditional. On a non-shareable table it doesn't hurt.

Quoted 4 lines
---
 drivers/irqchip/irq-gic-v3-its.c | 3 +++
 1 file changed, 3 insertions(+)
author
#3 lore raw

PATCH v2 2/5 irqchip/gic-v3-its: Clean the GICv4.1 vPE table to PoC

In reply to Fuad Tabba

On a GICv4.1 system, allocate_vpe_l1_table() sets Z and Valid in GICR_VPROPBASER and points it at a freshly zeroed vPE table, but leaves the zeroes in the CPU's cache. A redistributor that accesses the table as non-shareable reads it from memory, where it might not be zero, and the spec makes that UNPREDICTABLE (GICR_VPROPBASER.Z, IHI 0069H.b 12.11.39).

Clean the table to PoC unconditionally, as the driver does for the pending table. Testing rdists_support_shareable() isn't enough, since GICR_VPROPBASER can read back as non-shareable even when the helper returns true. allocate_vpe_l2_table() already cleans the level-2 pages in that case. A vPE table inherited from an ITS is cleaned by its_setup_baser() when the ITS is non-shareable.

Fixes 5e5168461c22c ("irqchip/gic-v4.1: VPE table (aka GICR_VPROPBASER) allocation")
---
 drivers/irqchip/irq-gic-v3-its.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v3-its.c +3 -0
index 9900c6a53526e..6932dd0a02c42 100644
@@ -3007,6 +3007,9 @@ static int allocate_vpe_l1_table(void)
 	pa = virt_to_phys(page_address(page));
 	WARN_ON(!IS_ALIGNED(pa, psz));
 
+	/* Make sure the GIC will observe the zeroed table */
+	gic_flush_dcache_to_poc(page_address(page), np * PAGE_SIZE);
+
 	val |= FIELD_PREP(GICR_VPROPBASER_4_1_ADDR, pa >> 12);
 	if (rdists_support_shareable()) {
 		val |= GICR_VPROPBASER_RaWb;
Signature · 1 line
2.47.3
Reviewed-by on v2 2/5
#4 lore raw

Re: [PATCH v2 2/5] irqchip/gic-v3-its: Clean the GICv4.1 vPE table to PoC

Hi Fuad,

Thanks for Cc'ing me on the GIC stuff. I'm happy to read them ;-)

Quoted 25 lines · Fuad Tabba

On a GICv4.1 system, allocate_vpe_l1_table() sets Z and Valid in GICR_VPROPBASER and points it at a freshly zeroed vPE table, but leaves the zeroes in the CPU's cache. A redistributor that accesses the table as non-shareable reads it from memory, where it might not be zero, and the spec makes that UNPREDICTABLE (GICR_VPROPBASER.Z, IHI 0069H.b 12.11.39).

Clean the table to PoC unconditionally, as the driver does for the pending table. Testing rdists_support_shareable() isn't enough, since GICR_VPROPBASER can read back as non-shareable even when the helper returns true. allocate_vpe_l2_table() already cleans the level-2 pages in that case. A vPE table inherited from an ITS is cleaned by its_setup_baser() when the ITS is non-shareable.

Fixes 5e5168461c22c ("irqchip/gic-v4.1: VPE table (aka GICR_VPROPBASER) allocation")
---
 drivers/irqchip/irq-gic-v3-its.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v3-its.c +0 -0
index 9900c6a53526e..6932dd0a02c42 100644

drivers/irqchip/irq-gic-v3-its.c static int allocate_vpe_l1_table(void) · line 3015

Quoted 9 lines
drivers/irqchip/irq-gic-v3-its.c +3 -0
@@ -3007,6 +3007,9 @@ static int allocate_vpe_l1_table(void)
 	pa = virt_to_phys(page_address(page));
 	WARN_ON(!IS_ALIGNED(pa, psz));
 
+	/* Make sure the GIC will observe the zeroed table */
+	gic_flush_dcache_to_poc(page_address(page), np * PAGE_SIZE);
+
 	val |= FIELD_PREP(GICR_VPROPBASER_4_1_ADDR, pa >> 12);
 	if (rdists_support_shareable()) {
 		val |= GICR_VPROPBASER_RaWb;

Nitpick: would "irqchip/gic-v4.1:" be a better prefix for this patch?

Otherwise looks good,

Thanks,
Zenghui

author
#5 lore raw

Re: [PATCH v2 2/5] irqchip/gic-v3-its: Clean the GICv4.1 vPE table to PoC

Hi Zenghui,

Quoted 4 lines · Zenghui Yu

Hi Fuad,

Thanks for Cc'ing me on the GIC stuff. I'm happy to read them ;-)

Thank you for the reviews! :)

[...]

Quoted 1 line

Nitpick: would "irqchip/gic-v4.1:" be a better prefix for this patch?

I'll use that in v3.

Cheers,
/fuad

author
#6 lore raw

PATCH v2 3/5 irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes

In reply to Fuad Tabba

Commit e36d4165f0796 ("irqchip/gic-v3-its: Rely on genpool alignment") dropped the ALIGN() of the ITT address in MAPD, on the premise that the ITT pool returns 256-byte aligned blocks. However, the pool's minimum allocation order is get_order(ITS_ITT_ALIGN), which is 0, so its granule is a single byte. An ITT whose size is not a multiple of 256 leaves the next device's ITT misaligned. MAPD drops the low bits of its address, so that device's ITEs land on the previous device's ITT. QEMU's emulated ITS has 12-byte ITEs, so two devices with 32 vectors each are enough to hit it.

Create the pool with a granule of ITS_ITT_ALIGN.

Fixes e36d4165f0796 ("irqchip/gic-v3-its: Rely on genpool alignment")
---
 drivers/irqchip/irq-gic-v3-its.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +1 -1
index 6932dd0a02c42..5756ffe4ec13e 100644
@@ -5854,7 +5854,7 @@ int __init its_init(struct fwnode_handle *handle, struct rdists *rdists,
 	bool has_v4_1 = false;
 	int err;
 
-	itt_pool = gen_pool_create(get_order(ITS_ITT_ALIGN), -1);
+	itt_pool = gen_pool_create(ilog2(ITS_ITT_ALIGN), -1);
 	if (!itt_pool)
 		return -ENOMEM;
 
Signature · 1 line
2.47.3
Reviewed-by on v2 3/5
#7 lore raw

Re: [PATCH v2 3/5] irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes

Quoted 10 lines · Fuad Tabba

Commit e36d4165f0796 ("irqchip/gic-v3-its: Rely on genpool alignment") dropped the ALIGN() of the ITT address in MAPD, on the premise that the ITT pool returns 256-byte aligned blocks. However, the pool's minimum allocation order is get_order(ITS_ITT_ALIGN), which is 0, so its granule is a single byte. An ITT whose size is not a multiple of 256 leaves the next device's ITT misaligned. MAPD drops the low bits of its address, so that device's ITEs land on the previous device's ITT. QEMU's emulated ITS has 12-byte ITEs, so two devices with 32 vectors each are enough to hit it.

Quoted 8 lines

Create the pool with a granule of ITS_ITT_ALIGN.

Fixes e36d4165f0796 ("irqchip/gic-v3-its: Rely on genpool alignment")
---
 drivers/irqchip/irq-gic-v3-its.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
maintainer
#8 lore raw

Re: [PATCH v2 3/5] irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes

In reply to Fuad Tabba
Quoted 25 lines · Fuad Tabba

Commit e36d4165f0796 ("irqchip/gic-v3-its: Rely on genpool alignment") dropped the ALIGN() of the ITT address in MAPD, on the premise that the ITT pool returns 256-byte aligned blocks. However, the pool's minimum allocation order is get_order(ITS_ITT_ALIGN), which is 0, so its granule is a single byte. An ITT whose size is not a multiple of 256 leaves the next device's ITT misaligned. MAPD drops the low bits of its address, so that device's ITEs land on the previous device's ITT. QEMU's emulated ITS has 12-byte ITEs, so two devices with 32 vectors each are enough to hit it.

Create the pool with a granule of ITS_ITT_ALIGN.

Fixes e36d4165f0796 ("irqchip/gic-v3-its: Rely on genpool alignment")
---
 drivers/irqchip/irq-gic-v3-its.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +0 -0
index 6932dd0a02c42..5756ffe4ec13e 100644

drivers/irqchip/irq-gic-v3-its.c int __init its_init(struct fwnode_handle *handle, struct rdists *rdists, · line 5860

Quoted 8 lines
drivers/irqchip/irq-gic-v3-its.c +1 -1
@@ -5854,7 +5854,7 @@ int __init its_init(struct fwnode_handle *handle, struct rdists *rdists,
 	bool has_v4_1 = false;
 	int err;
 
-	itt_pool = gen_pool_create(get_order(ITS_ITT_ALIGN), -1);
+	itt_pool = gen_pool_create(ilog2(ITS_ITT_ALIGN), -1);
 	if (!itt_pool)
 		return -ENOMEM;
 

This one really wants a

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author
#9 lore raw

Re: [PATCH v2 3/5] irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes

On Mon, 23 Nov 2026 at 13:01, Marc Zyngier <[email protected]> wrote:
[...]

Quoted 16 lines

drivers/irqchip/irq-gic-v3-its.c int __init its_init(struct fwnode_handle *handle, struct rdists *rdists, · line 5860

Quoted 13 lines
drivers/irqchip/irq-gic-v3-its.c +1 -1
index 6932dd0a02c42..5756ffe4ec13e 100644
@@ -5854,7 +5854,7 @@ int __init its_init(struct fwnode_handle *handle, struct rdists *rdists,
      bool has_v4_1 = false;
      int err;
 
-     itt_pool = gen_pool_create(get_order(ITS_ITT_ALIGN), -1);
+     itt_pool = gen_pool_create(ilog2(ITS_ITT_ALIGN), -1);
      if (!itt_pool)
              return -ENOMEM;
 

This one really wants a

Quoted 1 line

Will add it in v3.

Cheers,
/fuad

author
#10 lore raw

PATCH v2 4/5 irqchip/gic-v3-its: Zero ITTs reused from the ITT pool

In reply to Fuad Tabba

Commit b08e2f42e86b5 ("irqchip/gic-v3-its: Share ITS tables with a non-trusted hypervisor") moved sub-page ITTs from kzalloc_node() to a genpool. The pages added to the pool are zeroed, but an ITT freed back to it goes to the next device as the previous one left it. MAPD is then
UNPREDICTABLE: "When V == 1, the specified ITT does not contain all zeros" (IHI 0069H.b, 5.3.10).

Zero every ITT that comes from the pool.

Fixes b08e2f42e86b5 ("irqchip/gic-v3-its: Share ITS tables with a non-trusted hypervisor")
---
 drivers/irqchip/irq-gic-v3-its.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +3 -1
index 5756ffe4ec13e..33aa8a355ec65 100644
@@ -270,8 +270,10 @@ static void *itt_alloc_pool(int node, int size)
 
 	do {
 		addr = gen_pool_alloc(itt_pool, size);
-		if (addr)
+		if (addr) {
+			memset((void *)addr, 0, size);
 			break;
+		}
 
 		page = its_alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0);
 		if (!page)
Signature · 1 line
2.47.3
Reviewed-by on v2 4/5
#11 lore raw

Re: [PATCH v2 4/5] irqchip/gic-v3-its: Zero ITTs reused from the ITT pool

Quoted 7 lines · Fuad Tabba

Commit b08e2f42e86b5 ("irqchip/gic-v3-its: Share ITS tables with a non-trusted hypervisor") moved sub-page ITTs from kzalloc_node() to a genpool. The pages added to the pool are zeroed, but an ITT freed back to it goes to the next device as the previous one left it. MAPD is then
UNPREDICTABLE: "When V == 1, the specified ITT does not contain all zeros" (IHI 0069H.b, 5.3.10).

Quoted 8 lines

Zero every ITT that comes from the pool.

Fixes b08e2f42e86b5 ("irqchip/gic-v3-its: Share ITS tables with a non-trusted hypervisor")
---
 drivers/irqchip/irq-gic-v3-its.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
maintainer
#12 lore raw

Re: [PATCH v2 4/5] irqchip/gic-v3-its: Zero ITTs reused from the ITT pool

In reply to Fuad Tabba
Quoted 23 lines · Fuad Tabba

Commit b08e2f42e86b5 ("irqchip/gic-v3-its: Share ITS tables with a non-trusted hypervisor") moved sub-page ITTs from kzalloc_node() to a genpool. The pages added to the pool are zeroed, but an ITT freed back to it goes to the next device as the previous one left it. MAPD is then
UNPREDICTABLE: "When V == 1, the specified ITT does not contain all zeros" (IHI 0069H.b, 5.3.10).

Zero every ITT that comes from the pool.

Fixes b08e2f42e86b5 ("irqchip/gic-v3-its: Share ITS tables with a non-trusted hypervisor")
---
 drivers/irqchip/irq-gic-v3-its.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +0 -0
index 5756ffe4ec13e..33aa8a355ec65 100644
@@ -270,8 +270,10 @@ static void *itt_alloc_pool(int node, int size)
 

drivers/irqchip/irq-gic-v3-its.c static void *itt_alloc_pool(int node, int size) · line 279

Quoted 10 lines
drivers/irqchip/irq-gic-v3-its.c +3 -1
 	do {
 		addr = gen_pool_alloc(itt_pool, size);
-		if (addr)
+		if (addr) {
+			memset((void *)addr, 0, size);
 			break;
+		}
 
 		page = its_alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0);
 		if (!page)

If we are going to zero every ITT that is dished out to the driver, then there is no point in asking for the page to be zeroed the first place, is it?

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author
#13 lore raw

Re: [PATCH v2 4/5] irqchip/gic-v3-its: Zero ITTs reused from the ITT pool

Hi Marc,

On Mon, 23 Nov 2026 13:01:07 +0000, Marc Zyngier <[email protected]> wrote:
[...]

Quoted 1 line
Quoted 1 line
drivers/irqchip/irq-gic-v3-its.c +0 -0

[...]

Quoted 10 lines
Quoted 10 lines
drivers/irqchip/irq-gic-v3-its.c +3 -1
@@ -270,8 +270,10 @@ static void *itt_alloc_pool(int node, int size)
 
         do {
                 addr = gen_pool_alloc(itt_pool, size);
-                if (addr)
+                if (addr) {
+                        memset((void *)addr, 0, size);
                         break;
+                }
 
Quoted 6 lines

drivers/irqchip/irq-gic-v3-its.c static void *itt_alloc_pool(int node, int size) · line 279

Quoted 2 lines
drivers/irqchip/irq-gic-v3-its.c +0 -0
                 page = its_alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0);
                 if (!page)

If we are going to zero every ITT that is dished out to the driver, then there is no point in asking for the page to be zeroed the first place, is it?

I'll drop it in v3. Until [1] is in, __GFP_ZERO is what clears a page before a pKVM guest shares it with the host.

Cheers,
/fuad

[1] https://lore.kernel.org/all/[email protected]/

author
#14 lore raw

PATCH v2 5/5 irqchip/gic-v3-its: Free the page when gen_pool_add() fails

In reply to Fuad Tabba

When the ITT pool has no room, itt_alloc_pool() grows it by a page and retries. gen_pool_add() fails when it cannot allocate its chunk descriptor, but its return is ignored, so the page is leaked and the retry allocates another page to leak, until an add succeeds or a page allocation fails.

Free the page and fail the allocation instead.

Fixes b08e2f42e86b5 ("irqchip/gic-v3-its: Share ITS tables with a non-trusted hypervisor")
---
 drivers/irqchip/irq-gic-v3-its.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +4 -1
index 33aa8a355ec65..74fda3a6efed0 100644
@@ -279,7 +279,10 @@ static void *itt_alloc_pool(int node, int size)
 		if (!page)
 			break;
 
-		gen_pool_add(itt_pool, (unsigned long)page_address(page), PAGE_SIZE, node);
+		if (gen_pool_add(itt_pool, (unsigned long)page_address(page), PAGE_SIZE, node)) {
+			its_free_pages(page_address(page), 0);
+			break;
+		}
 	} while (!addr);
 
 	return (void *)addr;
Signature · 1 line
2.47.3
Reviewed-by on v2 5/5
#15 lore raw

Re: [PATCH v2 5/5] irqchip/gic-v3-its: Free the page when gen_pool_add() fails

Quoted 6 lines · Fuad Tabba

When the ITT pool has no room, itt_alloc_pool() grows it by a page and retries. gen_pool_add() fails when it cannot allocate its chunk descriptor, but its return is ignored, so the page is leaked and the retry allocates another page to leak, until an add succeeds or a page allocation fails.

Quoted 8 lines

Free the page and fail the allocation instead.

Fixes b08e2f42e86b5 ("irqchip/gic-v3-its: Share ITS tables with a non-trusted hypervisor")
---
 drivers/irqchip/irq-gic-v3-its.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)