Skip to contentSkip to conversation

irqchip/gic-v5: GICv5 KVM IRS review fixes

PATCH Applied Sascha Bischoff 3 participants 6 messages Aug 11 – Aug 20

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover irqchip/gic-v5: GICv5 KVM IRS review fixes

Hi all,

v1 [1] combined irqchip and KVM fixes identified by Sashiko [2] while reviewing the GICv5 KVM IRS series [3]. Following feedback, v2 splits the fixes into separate irqchip and KVM postings. This posting contains the irqchip fixes; the KVM fixes are posted separately.

Changes since v1:

* Split the combined series into irqchip and KVM postings.

* Dropped the setting of a CPU's IAFFID to 0 on clear as this might be a valid IAFFID.

* Added a reviewed by tag to "irqchip/gic-v5: Clear per-CPU IRS data on teardown".

The fixes are:

* Clear the per-CPU IRS pointer and IAFFID state when host IRS initialisation fails or an IRS is removed. This prevents the per-CPU state from retaining a pointer to freed IRS data.

* Add an isb() after disabling the GICv5 CPU interface. This ensures that interrupts are disabled before the helper returns.

These changes are based on v7.2-rc7.

Thanks,
Sascha

[1] https://lore.kernel.org/all/[email protected]/
[2] https://sashiko.dev/#/patchset/20260724104819.1296803-1-sascha.bischoff%40arm.com
[3] https://lore.kernel.org/all/[email protected]/

Sascha Bischoff (2):
irqchip/gic-v5: Clear per-CPU IRS data on teardown irqchip/gic-v5: Synchronize CPU interface disable

 drivers/irqchip/irq-gic-v5-irs.c | 15 +++++++++++++++
 drivers/irqchip/irq-gic-v5.c     |  1 +
 2 files changed, 16 insertions(+)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/2 irqchip/gic-v5: Clear per-CPU IRS data on teardown

IRS affinity setup publishes an IRS pointer and IAFFID state in the per-CPU data before the remaining IRS initialization can fail. The error path then frees the IRS data without clearing that published state, leaving CPUs associated with freed memory.

On initialization failure and normal IRS teardown, clear the per-CPU IRS association by removing the stale pointer to irs_data. Also invalidate the per-CPU IAFFID state for any CPUs that were tied to the IRS before it was freed.

Fixes 5cb1b6dab2de ("irqchip/gic-v5: Add GICv5 IRS/SPI support")
Fixes 35866efa52fe ("irqchip/gic-v5: Add ACPI IRS probing")
---
 drivers/irqchip/irq-gic-v5-irs.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/irqchip/irq-gic-v5-irs.c +15 -0
index f3fce0b1e25d9..3028a8bbbf68b 100644
@@ -651,6 +651,18 @@ static int __init gicv5_irs_of_init_affinity(struct device_node *node,
 	return ret;
 }
 
+static void __init gicv5_irs_clear_affinity(struct gicv5_irs_chip_data *irs_data)
+{
+	int cpu;
+
+	for_each_possible_cpu(cpu) {
+		if (per_cpu(per_cpu_irs_data, cpu) == irs_data) {
+			per_cpu(cpu_iaffid, cpu).valid = false;
+			per_cpu(per_cpu_irs_data, cpu) = NULL;
+		}
+	}
+}
+
 static void irs_setup_pri_bits(u32 idr1)
 {
 	switch (FIELD_GET(GICV5_IRS_IDR1_PRIORITY_BITS, idr1)) {
@@ -773,6 +785,7 @@ static int __init gicv5_irs_of_init(struct device_node *node)
 	return ret;
 
 out_iomem:
+	gicv5_irs_clear_affinity(irs_data);
 	iounmap(irs_base);
 out_err:
 	kfree(irs_data);
@@ -787,6 +800,7 @@ void __init gicv5_irs_remove(void)
 	gicv5_deinit_lpis();
 
 	list_for_each_entry_safe(irs_data, tmp_data, &irs_nodes, entry) {
+		gicv5_irs_clear_affinity(irs_data);
 		iounmap(irs_data->irs_base);
 		list_del(&irs_data->entry);
 		kfree(irs_data);
@@ -951,6 +965,7 @@ static int __init gic_acpi_parse_madt_irs(union acpi_subtable_headers *header,
 	return 0;
 
 out_map:
+	gicv5_irs_clear_affinity(irs_data);
 	iounmap(irs_base);
 out_release:
 	release_mem_region(r->start, resource_size(r));
Signature · 1 line
2.34.1
#2 lore raw

[tip: irq/urgent] irqchip/gic-v5: Clear per-CPU IRS data on teardown

The following commit has been merged into the irq/urgent branch of tip:

The following commit has been merged into the irq/urgent branch of tip:

Commit-ID:     3dfc0ab5fefd052c6028c4632b1fad8bdaf7967e
Gitweb:        https://git.kernel.org/tip/3dfc0ab5fefd052c6028c4632b1fad8bdaf7967e
Author:        Sascha Bischoff <[email protected]>
AuthorDate:    Tue, 11 Aug 2026 15:27:00 
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Thu, 20 Aug 2026 10:23:53 +02:00

irqchip/gic-v5: Clear per-CPU IRS data on teardown

IRS affinity setup publishes an IRS pointer and IAFFID state in the per-CPU data before the remaining IRS initialization can fail. The error path then frees the IRS data without clearing that published state, leaving CPUs associated with freed memory.

On initialization failure and normal IRS teardown, clear the per-CPU IRS association by removing the stale pointer to irs_data. Also invalidate the per-CPU IAFFID state for any CPUs that were tied to the IRS before it was freed.

Fixes 5cb1b6dab2de ("irqchip/gic-v5: Add GICv5 IRS/SPI support")
Fixes 35866efa52fe ("irqchip/gic-v5: Add ACPI IRS probing")
---
 drivers/irqchip/irq-gic-v5-irs.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/irqchip/irq-gic-v5-irs.c +15 -0
index f3fce0b..3028a8b 100644
@@ -651,6 +651,18 @@ static int __init gicv5_irs_of_init_affinity(struct device_node *node,
 	return ret;
 }
 
+static void __init gicv5_irs_clear_affinity(struct gicv5_irs_chip_data *irs_data)
+{
+	int cpu;
+
+	for_each_possible_cpu(cpu) {
+		if (per_cpu(per_cpu_irs_data, cpu) == irs_data) {
+			per_cpu(cpu_iaffid, cpu).valid = false;
+			per_cpu(per_cpu_irs_data, cpu) = NULL;
+		}
+	}
+}
+
 static void irs_setup_pri_bits(u32 idr1)
 {
 	switch (FIELD_GET(GICV5_IRS_IDR1_PRIORITY_BITS, idr1)) {
@@ -773,6 +785,7 @@ static int __init gicv5_irs_of_init(struct device_node *node)
 	return ret;
 
 out_iomem:
+	gicv5_irs_clear_affinity(irs_data);
 	iounmap(irs_base);
 out_err:
 	kfree(irs_data);
@@ -787,6 +800,7 @@ void __init gicv5_irs_remove(void)
 	gicv5_deinit_lpis();
 
 	list_for_each_entry_safe(irs_data, tmp_data, &irs_nodes, entry) {
+		gicv5_irs_clear_affinity(irs_data);
 		iounmap(irs_data->irs_base);
 		list_del(&irs_data->entry);
 		kfree(irs_data);
@@ -951,6 +965,7 @@ static int __init gic_acpi_parse_madt_irs(union acpi_subtable_headers *header,
 	return 0;
 
 out_map:
+	gicv5_irs_clear_affinity(irs_data);
 	iounmap(irs_base);
 out_release:
 	release_mem_region(r->start, resource_size(r));
#3 lore raw

PATCH v2 2/2 irqchip/gic-v5: Synchronize CPU interface disable

In reply to Sascha Bischoff

The write disabling the GICv5 CPU interface is only guaranteed to take effect after a context synchronization event. Without one, execution can return from gicv5_cpu_disable_interrupts() while an interrupt is still able to be taken.

Add an ISB after the ICC_CR0_EL1 write to ensure interrupts are disabled before the function returns. No corresponding ISB is added when enabling the interface, as interrupt delivery is asynchronous and there is no obvious benefit to waiting for it.

Fixes 7ec80fb3f025 ("irqchip/gic-v5: Add GICv5 PPI support")
---
 drivers/irqchip/irq-gic-v5.c | 1 +
 1 file changed, 1 insertion(+)
drivers/irqchip/irq-gic-v5.c +1 -0
index e9d1795235a66..6a99c541b559b 100644
@@ -983,6 +983,7 @@ static void gicv5_cpu_disable_interrupts(void)
 
 	cr0 = FIELD_PREP(ICC_CR0_EL1_EN, 0);
 	write_sysreg_s(cr0, SYS_ICC_CR0_EL1);
+	isb();
 }
 
 static void gicv5_cpu_enable_interrupts(void)
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] irqchip/gic-v5: Synchronize CPU interface disable

Quoted 10 lines · Sascha Bischoff

The write disabling the GICv5 CPU interface is only guaranteed to take effect after a context synchronization event. Without one, execution can return from gicv5_cpu_disable_interrupts() while an interrupt is still able to be taken.

Add an ISB after the ICC_CR0_EL1 write to ensure interrupts are disabled before the function returns. No corresponding ISB is added when enabling the interface, as interrupt delivery is asynchronous and there is no obvious benefit to waiting for it.

Quoted 6 lines
Fixes 7ec80fb3f025 ("irqchip/gic-v5: Add GICv5 PPI support")
---
 drivers/irqchip/irq-gic-v5.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 14 lines
drivers/irqchip/irq-gic-v5.c +1 -0
index e9d1795235a66..6a99c541b559b 100644
@@ -983,6 +983,7 @@ static void gicv5_cpu_disable_interrupts(void)
 
 	cr0 = FIELD_PREP(ICC_CR0_EL1_EN, 0);
 	write_sysreg_s(cr0, SYS_ICC_CR0_EL1);
+	isb();
 }
 
 static void gicv5_cpu_enable_interrupts(void)
Signature · 1 line
2.34.1
#5 lore raw

[tip: irq/urgent] irqchip/gic-v5: Synchronize CPU interface disable

In reply to Sascha Bischoff
The following commit has been merged into the irq/urgent branch of tip:

The following commit has been merged into the irq/urgent branch of tip:

Commit-ID:     ac6db0e0bee18cd4385418c752a007e1aba4ec14
Gitweb:        https://git.kernel.org/tip/ac6db0e0bee18cd4385418c752a007e1aba4ec14
Author:        Sascha Bischoff <[email protected]>
AuthorDate:    Tue, 11 Aug 2026 15:27:31 
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Thu, 20 Aug 2026 10:23:53 +02:00

irqchip/gic-v5: Synchronize CPU interface disable

The write disabling the GICv5 CPU interface is only guaranteed to take effect after a context synchronization event. Without one, execution can return from gicv5_cpu_disable_interrupts() while an interrupt is still able to be taken.

Add an ISB after the ICC_CR0_EL1 write to ensure interrupts are disabled before the function returns. No corresponding ISB is added when enabling the interface, as interrupt delivery is asynchronous and there is no obvious benefit to waiting for it.

---
 drivers/irqchip/irq-gic-v5.c | 1 +
 1 file changed, 1 insertion(+)
drivers/irqchip/irq-gic-v5.c +1 -0
index 5dcf404..ca48c8b 100644
@@ -983,6 +983,7 @@ static void gicv5_cpu_disable_interrupts(void)
 
 	cr0 = FIELD_PREP(ICC_CR0_EL1_EN, 0);
 	write_sysreg_s(cr0, SYS_ICC_CR0_EL1);
+	isb();
 }
 
 static void gicv5_cpu_enable_interrupts(void)