Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] irqchip/gic-v3-its: Fixes to table allocation and the ITT pool
@ 2026-11-16 19:29 Fuad Tabba
  2026-11-16 19:29 ` [PATCH v2 1/5] irqchip/gic-v3-its: Order table zeroing before the GIC can see it Fuad Tabba
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Fuad Tabba @ 2026-11-16 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Thomas Gleixner
  Cc: Radu Rendec, Zenghui Yu, Lorenzo Pieralisi, Steven Price,
	Suzuki K Poulose, Aneesh Kumar K . V, Will Deacon, Fuad Tabba,
	linux-arm-kernel, linux-kernel

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/20261106092625.3977163-1-fuad.tabba@linux.dev/
[2] https://lore.kernel.org/all/20261106120221.347309-1-fuad.tabba@linux.dev/
[3] https://lore.kernel.org/all/20261116110549.1863653-1-fuad.tabba@linux.dev/

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
-- 
2.47.3



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/5] irqchip/gic-v3-its: Order table zeroing before the GIC can see it
  2026-11-16 19:29 [PATCH v2 0/5] irqchip/gic-v3-its: Fixes to table allocation and the ITT pool Fuad Tabba
@ 2026-11-16 19:29 ` Fuad Tabba
  2026-11-16 19:29 ` [PATCH v2 2/5] irqchip/gic-v3-its: Clean the GICv4.1 vPE table to PoC Fuad Tabba
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Fuad Tabba @ 2026-11-16 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Thomas Gleixner
  Cc: Radu Rendec, Zenghui Yu, Lorenzo Pieralisi, Steven Price,
	Suzuki K Poulose, Aneesh Kumar K . V, Will Deacon, Fuad Tabba,
	linux-arm-kernel, linux-kernel

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.

Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
 drivers/irqchip/irq-gic-v3-its.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index c952c069f9373..9900c6a53526e 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -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;
 }
 
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/5] irqchip/gic-v3-its: Clean the GICv4.1 vPE table to PoC
  2026-11-16 19:29 [PATCH v2 0/5] irqchip/gic-v3-its: Fixes to table allocation and the ITT pool Fuad Tabba
  2026-11-16 19:29 ` [PATCH v2 1/5] irqchip/gic-v3-its: Order table zeroing before the GIC can see it Fuad Tabba
@ 2026-11-16 19:29 ` Fuad Tabba
  2026-11-16 19:29 ` [PATCH v2 3/5] irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes Fuad Tabba
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Fuad Tabba @ 2026-11-16 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Thomas Gleixner
  Cc: Radu Rendec, Zenghui Yu, Lorenzo Pieralisi, Steven Price,
	Suzuki K Poulose, Aneesh Kumar K . V, Will Deacon, Fuad Tabba,
	linux-arm-kernel, linux-kernel

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")
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
 drivers/irqchip/irq-gic-v3-its.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 9900c6a53526e..6932dd0a02c42 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -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;
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/5] irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes
  2026-11-16 19:29 [PATCH v2 0/5] irqchip/gic-v3-its: Fixes to table allocation and the ITT pool Fuad Tabba
  2026-11-16 19:29 ` [PATCH v2 1/5] irqchip/gic-v3-its: Order table zeroing before the GIC can see it Fuad Tabba
  2026-11-16 19:29 ` [PATCH v2 2/5] irqchip/gic-v3-its: Clean the GICv4.1 vPE table to PoC Fuad Tabba
@ 2026-11-16 19:29 ` Fuad Tabba
  2026-11-16 19:29 ` [PATCH v2 4/5] irqchip/gic-v3-its: Zero ITTs reused from the ITT pool Fuad Tabba
  2026-11-16 19:29 ` [PATCH v2 5/5] irqchip/gic-v3-its: Free the page when gen_pool_add() fails Fuad Tabba
  4 siblings, 0 replies; 6+ messages in thread
From: Fuad Tabba @ 2026-11-16 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Thomas Gleixner
  Cc: Radu Rendec, Zenghui Yu, Lorenzo Pieralisi, Steven Price,
	Suzuki K Poulose, Aneesh Kumar K . V, Will Deacon, Fuad Tabba,
	linux-arm-kernel, linux-kernel

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")
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
 drivers/irqchip/irq-gic-v3-its.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 6932dd0a02c42..5756ffe4ec13e 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -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;
 
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 4/5] irqchip/gic-v3-its: Zero ITTs reused from the ITT pool
  2026-11-16 19:29 [PATCH v2 0/5] irqchip/gic-v3-its: Fixes to table allocation and the ITT pool Fuad Tabba
                   ` (2 preceding siblings ...)
  2026-11-16 19:29 ` [PATCH v2 3/5] irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes Fuad Tabba
@ 2026-11-16 19:29 ` Fuad Tabba
  2026-11-16 19:29 ` [PATCH v2 5/5] irqchip/gic-v3-its: Free the page when gen_pool_add() fails Fuad Tabba
  4 siblings, 0 replies; 6+ messages in thread
From: Fuad Tabba @ 2026-11-16 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Thomas Gleixner
  Cc: Radu Rendec, Zenghui Yu, Lorenzo Pieralisi, Steven Price,
	Suzuki K Poulose, Aneesh Kumar K . V, Will Deacon, Fuad Tabba,
	linux-arm-kernel, linux-kernel

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")
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
 drivers/irqchip/irq-gic-v3-its.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 5756ffe4ec13e..33aa8a355ec65 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -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)
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 5/5] irqchip/gic-v3-its: Free the page when gen_pool_add() fails
  2026-11-16 19:29 [PATCH v2 0/5] irqchip/gic-v3-its: Fixes to table allocation and the ITT pool Fuad Tabba
                   ` (3 preceding siblings ...)
  2026-11-16 19:29 ` [PATCH v2 4/5] irqchip/gic-v3-its: Zero ITTs reused from the ITT pool Fuad Tabba
@ 2026-11-16 19:29 ` Fuad Tabba
  4 siblings, 0 replies; 6+ messages in thread
From: Fuad Tabba @ 2026-11-16 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Thomas Gleixner
  Cc: Radu Rendec, Zenghui Yu, Lorenzo Pieralisi, Steven Price,
	Suzuki K Poulose, Aneesh Kumar K . V, Will Deacon, Fuad Tabba,
	linux-arm-kernel, linux-kernel

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")
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
 drivers/irqchip/irq-gic-v3-its.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 33aa8a355ec65..74fda3a6efed0 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -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;
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-16 19:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 19:29 [PATCH v2 0/5] irqchip/gic-v3-its: Fixes to table allocation and the ITT pool Fuad Tabba
2026-11-16 19:29 ` [PATCH v2 1/5] irqchip/gic-v3-its: Order table zeroing before the GIC can see it Fuad Tabba
2026-11-16 19:29 ` [PATCH v2 2/5] irqchip/gic-v3-its: Clean the GICv4.1 vPE table to PoC Fuad Tabba
2026-11-16 19:29 ` [PATCH v2 3/5] irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes Fuad Tabba
2026-11-16 19:29 ` [PATCH v2 4/5] irqchip/gic-v3-its: Zero ITTs reused from the ITT pool Fuad Tabba
2026-11-16 19:29 ` [PATCH v2 5/5] irqchip/gic-v3-its: Free the page when gen_pool_add() fails Fuad Tabba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox