linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] irqchip/gic-v3-its: Fixes to table allocation and the ITT pool
@ 2026-11-27 12:06 Fuad Tabba
  2026-11-27 12:06 ` [PATCH v3 3/5] irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes Fuad Tabba
  2026-11-27 12:06 ` [PATCH v3 5/5] irqchip/gic-v3-its: Free the page when gen_pool_add() fails Fuad Tabba
  0 siblings, 2 replies; 3+ messages in thread
From: Fuad Tabba @ 2026-11-27 12:06 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 v2 [1]:
  - Dropped __GFP_ZERO from the pages added to the ITT pool. (Marc)
  - Added Cc: stable to patch 3. (Marc)
  - Changed patch 2's prefix to irqchip/gic-v4.1. (Zenghui)
  - Collected Reviewed-by from Zenghui. (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.

With patch 4, a pKVM guest shares each new pool page with the host
before anything zeroes it. The pkvm-guest patch [2] makes
pkvm_set_memory_decrypted() zero what it shares, which closes that.

Based on Linux 7.4-rc3 (aebb727447640).

Cheers,
/fuad

[1] https://lore.kernel.org/all/20261116192933.3266502-1-fuad.tabba@linux.dev/
[2] 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-v4.1: Clean the 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 | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)


base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.47.3



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

* [PATCH v3 3/5] irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes
  2026-11-27 12:06 [PATCH v3 0/5] irqchip/gic-v3-its: Fixes to table allocation and the ITT pool Fuad Tabba
@ 2026-11-27 12:06 ` Fuad Tabba
  2026-11-27 12:06 ` [PATCH v3 5/5] irqchip/gic-v3-its: Free the page when gen_pool_add() fails Fuad Tabba
  1 sibling, 0 replies; 3+ messages in thread
From: Fuad Tabba @ 2026-11-27 12:06 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, stable

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>
Reviewed-by: Zenghui Yu <yuzenghui@huawei.com>
Cc: stable@vger.kernel.org
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] 3+ messages in thread

* [PATCH v3 5/5] irqchip/gic-v3-its: Free the page when gen_pool_add() fails
  2026-11-27 12:06 [PATCH v3 0/5] irqchip/gic-v3-its: Fixes to table allocation and the ITT pool Fuad Tabba
  2026-11-27 12:06 ` [PATCH v3 3/5] irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes Fuad Tabba
@ 2026-11-27 12:06 ` Fuad Tabba
  1 sibling, 0 replies; 3+ messages in thread
From: Fuad Tabba @ 2026-11-27 12:06 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>
Reviewed-by: Zenghui Yu <yuzenghui@huawei.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 6eb2dbec5f0ed..cb352ce69147d 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] 3+ messages in thread

end of thread, other threads:[~2026-11-27 12:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 12:06 [PATCH v3 0/5] irqchip/gic-v3-its: Fixes to table allocation and the ITT pool Fuad Tabba
2026-11-27 12:06 ` [PATCH v3 3/5] irqchip/gic-v3-its: Align sub-page ITTs to 256 bytes Fuad Tabba
2026-11-27 12:06 ` [PATCH v3 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;
as well as URLs for NNTP newsgroup(s).