[PATCH v3 04/14] irqchip/gic-v5: Retain the L2 IST when mapping times out
From: Sascha Bischoff
Date: Wed Nov 18 2026 - 12:36:23 EST
If the IDLE poll after IRS_MAP_L2_ISTR times out, the mapping
operation has not been cancelled and could arguably still happen at a
later stage. Clearing the L1 entry and freeing the L2 IST can
therefore race with hardware completing the map and accessing the
freed table.
Retain the L1 entry and L2 IST on failure. Reject a subsequent
allocation that finds a nonzero but invalid L1 entry, so it cannot
overwrite the entry while the earlier mapping may still be
pending. Mark the retained table as intentional for kmemleak on both
success and failure.
Fixes: 0f01013258768 ("irqchip/gic-v5: Add GICv5 LPI/IPI support")
Reported-by: Fuad Tabba <fuad.tabba@xxxxxxxxx>
Signed-off-by: Sascha Bischoff <sascha.bischoff@xxxxxxx>
Link: https://lore.kernel.org/r/20261112145814.853424-1-fuad.tabba@xxxxxxxxx
---
drivers/irqchip/irq-gic-v5-irs.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/irqchip/irq-gic-v5-irs.c b/drivers/irqchip/irq-gic-v5-irs.c
index ead76560ea08f..78deb46baa784 100644
--- a/drivers/irqchip/irq-gic-v5-irs.c
+++ b/drivers/irqchip/irq-gic-v5-irs.c
@@ -217,6 +217,10 @@ int gicv5_irs_iste_alloc(const u32 lpi)
if (FIELD_GET(GICV5_ISTL1E_VALID, le64_to_cpu(l1ist[index])))
return 0;
+ /* A previous map timed out; do not overwrite its pending L1 entry. */
+ if (READ_ONCE(l1ist[index]))
+ return -EBUSY;
+
l2ist = kzalloc(l2size, GFP_KERNEL);
if (!l2ist)
return -ENOMEM;
@@ -235,13 +239,11 @@ int gicv5_irs_iste_alloc(const u32 lpi)
l2istr = FIELD_PREP(GICV5_IRS_MAP_L2_ISTR_ID, lpi);
irs_writel_relaxed(irs_data, l2istr, GICV5_IRS_MAP_L2_ISTR);
+ /* The map cannot be cancelled, so retain the table even on timeout. */
+ kmemleak_ignore(l2ist);
ret = gicv5_irs_ist_synchronise(irs_data);
- if (ret) {
- l1ist[index] = 0;
- kfree(l2ist);
+ if (ret)
return ret;
- }
- kmemleak_ignore(l2ist);
/*
* Make sure we invalidate the cache line pulled before the IRS
--
2.34.1