irqchip/gic-v5: Fix misc IRS and ITS host driver issues
Subsystems (4)
v2 cover irqchip/gic-v5: Fix misc IRS and ITS host driver issues
This series fixes issues in the GICv5 host IRS and ITS drivers.
The ITS invalidation serialisation fix addresses Sashiko's report of a race between event and device invalidation commands [1]. The other patches correct IRS allocation and routing behaviour, serialise IRS synchronisation, and fix ITS L1/L2 table selection, cache maintenance, ACPI coherency handling, and resource cleanup.
The IRS changes:
* Reject allocation of an SPI without an IRS, preventing a null-pointer dereference, and warn about low-quality firmware.
* Only program IRS_PE_CR0.DPS when 1-of-N routing is supported as this field is RES0, otherwise.
* Serialise IRS synchronisation requests, as the IRS ignores a request while an earlier one is still active.
The ITS changes:
* Serialise event and device cache invalidations because both use the ITS's shared DIDR register, so concurrent writes are a bad idea!
* Select linear device and interrupt translation tables when one L2 table covers the full ID space. Currently, this selects the wrong path, then the L1 table code rejects the attempt to create the table.
* Check the ACPI noncoherent flag with ACPI, rather than checking the DT's property.
* Correct cache-maintenance sizing after limiting the DeviceID width.
* Invalidate the device cache before freeing an ITT.
* Use firmware-node names in initialisation warnings.
* Release the reserved MMIO region if DT-based ITS initialisation fails.
I've CC'd stable for the IRS/ITS locking fixes, the ITS table alloc issue, and the ACPI coherency fix, as these are the most important changes to backport.
The series is based on v7.4-rc1. Thanks for taking a look!
Sascha
[1] https://sashiko.dev/#/patchset/[email protected]?part=11
---
Changes in v2:
- Explained why IRS synchronisation uses a raw spinlock in the KVM
affinity path.
- Clarified the ITS invalidation race and described the KVM forwarding path.
- Reworked to calculate the device-table size after capping the
DeviceID width.
- Reordered local declarations in the ITS probe function to be in
reverse fir tree order.
- Added Acked-by tags.
- Link to v1: https://patch.msgid.link/[email protected]
To: Lorenzo Pieralisi <[email protected]>
To: Marc Zyngier <[email protected]>
To: Thomas Gleixner <[email protected]>
To: Radu Rendec <[email protected]>
To: Sascha Bischoff <[email protected]>
To: Timothy Hayes <[email protected]>
To: Catalin Marinas <[email protected]>
To: Jonathan Cameron <[email protected]>
To: "Rafael J. Wysocki" <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
Sascha Bischoff (10):
irqchip/gic-v5: Reject SPIs not backed by an IRS irqchip/gic-v5: Only set IRS DPS when 1ofN routing is supported irqchip/gic-v5: Serialise IRS synchronisation requests irqchip/gic-v5: Serialise ITS invalidation commands irqchip/gic-v5: Use linear DT and ITT when L2 covers all IDs irqchip/gic-v5: Honour ACPI ITS noncoherent flag irqchip/gic-v5: Use firmware node name in ITS warning irqchip/gic-v5: Invalidate ITS device cache before freeing ITT irqchip/gic-v5: Clean the allocated linear device table size irqchip/gic-v5: Release ITS MMIO region on DT probe failure
drivers/irqchip/irq-gic-v5-irs.c | 22 +++++++++++++++------- drivers/irqchip/irq-gic-v5-its.c | 34 ++++++++++++++++++++++++++-------- drivers/irqchip/irq-gic-v5.c | 9 +++++++++ include/linux/irqchip/arm-gic-v5.h | 1 + 4 files changed, 51 insertions(+), 15 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261102-host_gicv5_fixes-1eeea29d2ea4
Best regards,
Signature · 1 line
Sascha Bischoff <[email protected]>
PATCH v2 1/10 irqchip/gic-v5: Reject SPIs not backed by an IRS
It is possible to build a multi-IRS GICv5 system where there are gaps in the global SPI range that are not backed by any IRS. In the current incarnation, this results in dereferencing a null pointer.
Reject cases where the firmware attempts to use those SPIs during IRQ allocation by catching the case where there is no chip_data associated with the irq (meaning that there is no IRS to back it). Spit out a warning about broken firmware when this is encountered as it shouldn't be using non-existent SPIs in the first place.
--- drivers/irqchip/irq-gic-v5.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/irqchip/irq-gic-v5.c +9 -0
@@ -727,6 +727,15 @@ static int gicv5_irq_spi_domain_alloc(struct irq_domain *domain, unsigned int vi irqd =irq_desc_get_irq_data (irq_to_desc (virq)); chip_data =gicv5_irs_lookup_by_spi_id (hwirq); +/* +* The global SPI range may contain IDs not covered by any IRS, i.e., it +* may have gaps, in which case there is no IRS to back the SPI. Catch +* broken firmware trying to use any of those SPIs. +*/ +if (!chip_data) { +pr_warn ("Firmware bug! Unimplemented SPI (0x%lx)!\n" , hwirq); +return -EINVAL ; + }irq_domain_set_info (domain, virq, hwirq, &gicv5_spi_irq_chip, chip_data, handle_fasteoi_irq,NULL ,NULL );
Signature · 1 line
2.34.1
Lorenzo Pieralisi
maintainerRe: [PATCH v2 01/10] irqchip/gic-v5: Reject SPIs not backed by an IRS
Quoted 10 lines · Sascha Bischoff
It is possible to build a multi-IRS GICv5 system where there are gaps in the global SPI range that are not backed by any IRS. In the current incarnation, this results in dereferencing a null pointer.
Reject cases where the firmware attempts to use those SPIs during IRQ allocation by catching the case where there is no
chip_dataassociated with the irq (meaning that there is no IRS to back it). Spit out a warning about broken firmware when this is encountered as it shouldn't be using non-existent SPIs in the first place.
Quoted 3 lines
Fixes 5cb1b6dab2def ("irqchip/gic-v5: Add GICv5 IRS/SPI support")Signed-off-by Sascha Bischoff <[email protected]>
https://docs.kernel.org/process/maintainer-tip.html
"Ordering of commit tags", if there is a v3.
Lorenzo
Quoted 28 lines
--- drivers/irqchip/irq-gic-v5.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/irqchip/irq-gic-v5.c +9
-0@@ -727,6 +727,15 @@ static int gicv5_irq_spi_domain_alloc(struct irq_domain *domain, unsigned int vi irqd =irq_desc_get_irq_data (irq_to_desc (virq)); chip_data =gicv5_irs_lookup_by_spi_id (hwirq); +/* +* The global SPI range may contain IDs not covered by any IRS, i.e., it +* may have gaps, in which case there is no IRS to back the SPI. Catch +* broken firmware trying to use any of those SPIs. +*/ +if (!chip_data) { +pr_warn ("Firmware bug! Unimplemented SPI (0x%lx)!\n" , hwirq); +return -EINVAL ; + }irq_domain_set_info (domain, virq, hwirq, &gicv5_spi_irq_chip, chip_data, handle_fasteoi_irq,NULL ,NULL );Signature · 2 lines
-- 2.34.1
Re: [PATCH v2 01/10] irqchip/gic-v5: Reject SPIs not backed by an IRS
Quoted 11 lines · Lorenzo Pieralisi
Quoted 10 lines · Sascha Bischoff
It is possible to build a multi-IRS GICv5 system where there are gaps in the global SPI range that are not backed by any IRS. In the current incarnation, this results in dereferencing a null pointer.
Reject cases where the firmware attempts to use those SPIs during IRQ allocation by catching the case where there is no
chip_dataassociated with the irq (meaning that there is no IRS to back it). Spit out a warning about broken firmware when this is encountered as it shouldn't be using non-existent SPIs in the first place.
Quoted 7 lines
Quoted 3 lines
Fixes 5cb1b6dab2def ("irqchip/gic-v5: Add GICv5 IRS/SPI support")Signed-off-by Sascha Bischoff <[email protected]>https://docs.kernel.org/process/maintainer-tip.html
"Ordering of commit tags", if there is a v3.
Have fixed this. I hadn't caught the fact that b4 (re)ordered tags differently by default! Thanks for catching it.
Quoted 2 lines
Lorenzo
Thanks,
Sascha
Quoted 29 lines
Quoted 29 lines
--- drivers/irqchip/irq-gic-v5.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/irqchip/irq-gic-v5.c +9
-0@@ -727,6 +727,15 @@ static int gicv5_irq_spi_domain_alloc(struct irq_domain *domain, unsigned int vi irqd =irq_desc_get_irq_data (irq_to_desc (virq)); chip_data =gicv5_irs_lookup_by_spi_id (hwirq); +/* +* The global SPI range may contain IDs not covered by any IRS, i.e., it +* may have gaps, in which case there is no IRS to back the SPI. Catch +* broken firmware trying to use any of those SPIs. +*/ +if (!chip_data) { +pr_warn ("Firmware bug! Unimplemented SPI (0x%lx)!\n" , hwirq); +return -EINVAL ; + }irq_domain_set_info (domain, virq, hwirq, &gicv5_spi_irq_chip, chip_data, handle_fasteoi_irq,NULL ,NULL );Signature · 2 lines
-- 2.34.1
PATCH v2 2/10 irqchip/gic-v5: Only set IRS DPS when 1ofN routing is supported
In reply to Sascha BischoffIRS_PE_CR0.DPS is RES0 when the IRS does not support 1ofN routing. Read the capability from IRS_IDR0 and skip programming DPS on systems without support for 1ofN routing, rather than blindly writing it.
--- drivers/irqchip/irq-gic-v5-irs.c | 14 +++++++++----- include/linux/irqchip/arm-gic-v5.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-)
drivers/irqchip/irq-gic-v5-irs.c +9 -5
@@ -541,12 +541,15 @@ int gicv5_irs_register_cpu(int cpuid)return -ENXIO ; } - cr0 =FIELD_PREP (GICV5_IRS_PE_CR0_DPS ,0x1 ); -irs_writel_relaxed (irs_data, cr0,GICV5_IRS_PE_CR0 ); +/* IRS_PE_CR0.DPS is RES0 when 1ofN routing is unsupported. */ +if (gicv5_global_data.one_of_n) { + cr0 =FIELD_PREP (GICV5_IRS_PE_CR0_DPS ,0x1 ); +irs_writel_relaxed (irs_data, cr0,GICV5_IRS_PE_CR0 ); - ret =gicv5_irs_wait_for_pe_cr0 (irs_data); -if (ret) -return ret; + ret =gicv5_irs_wait_for_pe_cr0 (irs_data); +if (ret) +return ret; + }pr_debug ("CPU %d enabled PE IAFFID 0x%x\n" , cpuid, iaffid);
@@ -725,6 +728,7 @@ static int __init gicv5_irs_init(struct gicv5_irs_chip_data *irs_data)if (list_empty (&irs_nodes)) { idr =irs_readl_relaxed (irs_data,GICV5_IRS_IDR0 ); gicv5_global_data.virt_capable = !!FIELD_GET (GICV5_IRS_IDR0_VIRT , idr); + gicv5_global_data.one_of_n = !!FIELD_GET (GICV5_IRS_IDR0_ONE_N , idr); idr =irs_readl_relaxed (irs_data,GICV5_IRS_IDR1 );irs_setup_pri_bits (idr);
include/linux/irqchip/arm-gic-v5.h +1 -0
@@ -532,6 +532,7 @@ struct gicv5_chip_data {u8 cpuif_id_bits;u8 irs_pri_bits;bool virt_capable; +bool one_of_n;struct {__le64 *l1ist_addr;u32 l2_size;
Signature · 1 line
2.34.1
PATCH v2 3/10 irqchip/gic-v5: Serialise IRS synchronisation requests
In reply to Sascha BischoffIRS_SYNCR writes are ignored while IRS_SYNC_STATUSR.IDLE is clear. Calls to gicv5_irs_syncr() for different IRQs can overlap, allowing the second request to be dropped. Its caller can then observe the first request completing and assume that its own events have been processed.
With GICv5 ITS KVM support, gicv5_irs_syncr() is also called while restoring the host ITTE in gicv5_its_set_vcpu_affinity(). The callback runs under the IRQ descriptor lock via irq_set_vcpu_affinity(), so it cannot sleep.
Serialise the request and completion poll with a raw spinlock, and use atomic polling because the synchronisation runs while holding the IRQ descriptor lock.
--- drivers/irqchip/irq-gic-v5-irs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/irqchip/irq-gic-v5-irs.c +6 -2
@@ -10,6 +10,7 @@#include <linux/log2.h> #include <linux/of.h> #include <linux/of_address.h> +#include <linux/spinlock.h> #include <linux/irqchip.h> #include <linux/irqchip/arm-gic-v5.h>
@@ -22,6 +23,8 @@#define LPI_ID_BITS_LINEAR 12 static DEFINE_PER_CPU_READ_MOSTLY(struct gicv5_irs_chip_data *, per_cpu_irs_data); +/* Synchronization requests must not overlap in an IRS Domain. */ +static DEFINE_RAW_SPINLOCK (irs_sync_lock);static LIST_HEAD (irs_nodes); static u32 irs_readl_relaxed(struct gicv5_irs_chip_data *irs_data,
@@ -507,10 +510,11 @@ void gicv5_irs_syncr(void)return ; syncr =FIELD_PREP (GICV5_IRS_SYNCR_SYNC ,1 ); +guard (raw_spinlock_irqsave)(&irs_sync_lock);irs_writel_relaxed (irs_data, syncr,GICV5_IRS_SYNCR ); -gicv5_wait_for_op (irs_data->irs_base,GICV5_IRS_SYNC_STATUSR , -GICV5_IRS_SYNC_STATUSR_IDLE ); +gicv5_wait_for_op_atomic (irs_data->irs_base,GICV5_IRS_SYNC_STATUSR , +GICV5_IRS_SYNC_STATUSR_IDLE ,NULL ); }int gicv5_irs_register_cpu (int cpuid)
Signature · 1 line
2.34.1
Re: [PATCH v2 03/10] irqchip/gic-v5: Serialise IRS synchronisation requests
[Remove stable from the CC email recipient list, leave it only in the log]
Quoted 2 lines · Sascha Bischoff
IRS_SYNCRwrites are ignored while IRS_SYNC_STATUSR.IDLE is clear. Calls togicv5_irs_syncr()for different IRQs can overlap, allowing
Nit: gicv5_irs_syncr() has no notion of specific IRQs, this is misleading.
Quoted 8 lines
the second request to be dropped. Its caller can then observe the first request completing and assume that its own events have been processed.
With GICv5 ITS KVM support,
gicv5_irs_syncr()is also called while restoring the host ITTE ingicv5_its_set_vcpu_affinity(). The callback runs under the IRQ descriptor lock viairq_set_vcpu_affinity(), so it cannot sleep.
Technically we are talking about a use case that does not exist yet.
I understand it is churn to fix it first and change it again later, I would just say that gicv5_irs_syncr() might need to be called in atomic context.
Quoted 34 lines
Serialise the request and completion poll with a raw spinlock, and use atomic polling because the synchronisation runs while holding the IRQ descriptor lock.
Fixes 57d72196dfc8 ("irqchip/gic-v5: Add GICv5 ITS support")Signed-off-by Sascha Bischoff <[email protected]>--- drivers/irqchip/irq-gic-v5-irs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/irqchip/irq-gic-v5-irs.c +3
-0@@ -10,6 +10,7 @@#include <linux/log2.h> #include <linux/of.h> #include <linux/of_address.h> +#include <linux/spinlock.h> #include <linux/irqchip.h> #include <linux/irqchip/arm-gic-v5.h> @@ -22,6 +23,8 @@#define LPI_ID_BITS_LINEAR 12 static DEFINE_PER_CPU_READ_MOSTLY(struct gicv5_irs_chip_data *, per_cpu_irs_data); +/* Synchronization requests must not overlap in an IRS Domain. */ +static DEFINE_RAW_SPINLOCK (irs_sync_lock);static LIST_HEAD (irs_nodes); static u32 irs_readl_relaxed(struct gicv5_irs_chip_data *irs_data,@@ -507,10 +510,11 @@ void gicv5_irs_syncr(void)return ;
drivers/irqchip/irq-gic-v5-irs.c void gicv5_irs_syncr(void) · line 518
Quoted 10 lines
drivers/irqchip/irq-gic-v5-irs.c +3
-2syncr =FIELD_PREP (GICV5_IRS_SYNCR_SYNC ,1 ); +guard (raw_spinlock_irqsave)(&irs_sync_lock);irs_writel_relaxed (irs_data, syncr,GICV5_IRS_SYNCR ); -gicv5_wait_for_op (irs_data->irs_base,GICV5_IRS_SYNC_STATUSR , -GICV5_IRS_SYNC_STATUSR_IDLE ); +gicv5_wait_for_op_atomic (irs_data->irs_base,GICV5_IRS_SYNC_STATUSR , +GICV5_IRS_SYNC_STATUSR_IDLE ,NULL ); }
Quoted 6 lines
drivers/irqchip/irq-gic-v5-irs.c +0
-0int gicv5_irs_register_cpu (int cpuid)Signature · 1 line
2.34.1
Re: [PATCH v2 03/10] irqchip/gic-v5: Serialise IRS synchronisation requests
Quoted 1 line · Lorenzo Pieralisi
[Remove stable from the CC email recipient list, leave it only in the log]
Noted, and thanks. Hadn't caught that had been added in from CC. Will omit henceforth!
Quoted 17 lines · Sascha Bischoff
Quoted 2 lines
IRS_SYNCRwrites are ignored while IRS_SYNC_STATUSR.IDLE is clear. Calls togicv5_irs_syncr()for different IRQs can overlap, allowingNit:
gicv5_irs_syncr()has no notion of specific IRQs, this is misleading.Quoted 8 lines
the second request to be dropped. Its caller can then observe the first request completing and assume that its own events have been processed.
With GICv5 ITS KVM support,
gicv5_irs_syncr()is also called while restoring the host ITTE ingicv5_its_set_vcpu_affinity(). The callback runs under the IRQ descriptor lock viairq_set_vcpu_affinity(), so it cannot sleep.
Quoted 5 lines
Technically we are talking about a use case that does not exist yet.
I understand it is churn to fix it first and change it again later, I would just say that
gicv5_irs_syncr()might need to be called in atomic context.
I've reworked this commit message to make it clearer.
Thanks,
Sascha
Quoted 54 lines
Quoted 35 lines
Serialise the request and completion poll with a raw spinlock, and use atomic polling because the synchronisation runs while holding the IRQ descriptor lock.
Fixes 57d72196dfc8 ("irqchip/gic-v5: Add GICv5 ITS support")Signed-off-by Sascha Bischoff <[email protected]>--- drivers/irqchip/irq-gic-v5-irs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/irqchip/irq-gic-v5-irs.c +3
-0@@ -10,6 +10,7 @@#include <linux/log2.h> #include <linux/of.h> #include <linux/of_address.h> +#include <linux/spinlock.h> #include <linux/irqchip.h> #include <linux/irqchip/arm-gic-v5.h> @@ -22,6 +23,8 @@#define LPI_ID_BITS_LINEAR 12 static DEFINE_PER_CPU_READ_MOSTLY(struct gicv5_irs_chip_data *, per_cpu_irs_data); +/* Synchronization requests must not overlap in an IRS Domain. */ +static DEFINE_RAW_SPINLOCK (irs_sync_lock);static LIST_HEAD (irs_nodes); static u32 irs_readl_relaxed(struct gicv5_irs_chip_data *irs_data,@@ -507,10 +510,11 @@ void gicv5_irs_syncr(void)return ;drivers/irqchip/irq-gic-v5-irs.c void gicv5_irs_syncr(void) · line 518
Quoted 10 lines
drivers/irqchip/irq-gic-v5-irs.c +3
-2syncr =FIELD_PREP (GICV5_IRS_SYNCR_SYNC ,1 ); +guard (raw_spinlock_irqsave)(&irs_sync_lock);irs_writel_relaxed (irs_data, syncr,GICV5_IRS_SYNCR ); -gicv5_wait_for_op (irs_data->irs_base,GICV5_IRS_SYNC_STATUSR , -GICV5_IRS_SYNC_STATUSR_IDLE ); +gicv5_wait_for_op_atomic (irs_data->irs_base,GICV5_IRS_SYNC_STATUSR , +GICV5_IRS_SYNC_STATUSR_IDLE ,NULL ); }Quoted 6 lines
drivers/irqchip/irq-gic-v5-irs.c +0
-0int gicv5_irs_register_cpu (int cpuid)Signature · 1 line
2.34.1
PATCH v2 4/10 irqchip/gic-v5: Serialise ITS invalidation commands
In reply to Sascha BischoffThe ITS uses the shared DIDR and EIDR registers to select the DeviceID and EventID whose translation is to be invalidated. Event invalidations for different IRQs can overlap, as can an event invalidation and a device invalidation. The per-IRQ descriptor lock does not serialise these commands, so writes can interleave and cause an invalidation to use the DeviceID or EventID of another IRQ being invalidated concurrently on a different CPU.
Serialise the command register writes and STATUSR.IDLE polls for both invalidation paths with a per-ITS raw spinlock. The KVM gicv5_its_set_vcpu_affinity() callback calls the event invalidation helper via irq_set_vcpu_affinity(), which holds the IRQ descriptor lock. This path cannot sleep, so use atomic polling.
--- drivers/irqchip/irq-gic-v5-its.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/irqchip/irq-gic-v5-its.c +9 -0
@@ -16,6 +16,7 @@#include <linux/of_address.h> #include <linux/of_irq.h> #include <linux/slab.h> +#include <linux/spinlock.h> #include <linux/irqchip.h> #include <linux/irqchip/arm-gic-v5.h>
@@ -28,6 +29,8 @@struct gicv5_its_chip_data {struct xarray its_devices;struct mutex dev_alloc_lock; +/* Event and device invalidation commands share DIDR. */ +raw_spinlock_t inv_lock;struct fwnode_handle *fwnode;struct gicv5_its_devtab_cfg devtab_cfgr;void __iomem *its_base;
@@ -129,6 +132,8 @@ static int gicv5_its_itt_cache_inv(struct gicv5_its_chip_data *its, u32 device_i eidr =FIELD_PREP (GICV5_ITS_EIDR_EVENTID , event_id); eventr =FIELD_PREP (GICV5_ITS_INV_EVENTR_I ,0x1 ); +guard (raw_spinlock_irqsave)(&its->inv_lock); +its_writeq_relaxed (its, didr,GICV5_ITS_DIDR );its_writel_relaxed (its, eidr,GICV5_ITS_EIDR );its_writel_relaxed (its, eventr,GICV5_ITS_INV_EVENTR );
@@ -371,6 +376,9 @@ static int gicv5_its_device_cache_inv(struct gicv5_its_chip_data *its,FIELD_PREP (GICV5_ITS_INV_DEVICER_EVENTID_BITS , its_dev->itt_cfg.event_id_bits) |FIELD_PREP (GICV5_ITS_INV_DEVICER_L1 ,0x0 ); + +guard (raw_spinlock_irqsave)(&its->inv_lock); +its_writeq_relaxed (its, didr,GICV5_ITS_DIDR );its_writel_relaxed (its, devicer,GICV5_ITS_INV_DEVICER );
@@ -1112,6 +1120,7 @@ static int __init gicv5_its_init_bases(void __iomem *its_base, struct fwnode_hanreturn -ENOMEM ;mutex_init (&its_node->dev_alloc_lock); +raw_spin_lock_init (&its_node->inv_lock);xa_init (&its_node->its_devices); its_node->fwnode = handle; its_node->its_base = its_base;
Signature · 1 line
2.34.1
Re: [PATCH v2 04/10] irqchip/gic-v5: Serialise ITS invalidation commands
Quoted 8 lines · Sascha Bischoff
The ITS uses the shared DIDR and EIDR registers to select the DeviceID and EventID whose translation is to be invalidated. Event invalidations for different IRQs can overlap, as can an event invalidation and a device invalidation. The per-IRQ descriptor lock does not serialise these commands, so writes can interleave and cause an invalidation to use the DeviceID or EventID of another IRQ being invalidated concurrently on a different CPU.
Quoted 5 lines
Serialise the command register writes and STATUSR.IDLE polls for both invalidation paths with a per-ITS raw spinlock. The KVM
gicv5_its_set_vcpu_affinity()callback calls the event invalidation helper viairq_set_vcpu_affinity(), which holds the IRQ descriptor lock. This path cannot sleep, so use atomic polling.
Same comment here as IRS sync. This one though looks like a host driver bug that can happen regardless of KVM, so I'd just fix it and remove/rephrase this paragraph.
Quoted 3 lines
Fixes 57d72196dfc8 ("irqchip/gic-v5: Add GICv5 ITS support")Reported-by Sashiko AI <[email protected]>
Again, this is linking to a report on a series that wasn't merged yet but probably it makes sense to leave it there for context.
Quoted 5 lines
Signed-off-by Sascha Bischoff <[email protected]>--- drivers/irqchip/irq-gic-v5-its.c | 9 +++++++++ 1 file changed, 9 insertions(+)
Quoted 52 lines
drivers/irqchip/irq-gic-v5-its.c +9
-0@@ -16,6 +16,7 @@#include <linux/of_address.h> #include <linux/of_irq.h> #include <linux/slab.h> +#include <linux/spinlock.h> #include <linux/irqchip.h> #include <linux/irqchip/arm-gic-v5.h> @@ -28,6 +29,8 @@struct gicv5_its_chip_data {struct xarray its_devices;struct mutex dev_alloc_lock; +/* Event and device invalidation commands share DIDR. */ +raw_spinlock_t inv_lock;struct fwnode_handle *fwnode;struct gicv5_its_devtab_cfg devtab_cfgr;void __iomem *its_base;@@ -129,6 +132,8 @@ static int gicv5_its_itt_cache_inv(struct gicv5_its_chip_data *its, u32 device_i eidr =FIELD_PREP (GICV5_ITS_EIDR_EVENTID , event_id); eventr =FIELD_PREP (GICV5_ITS_INV_EVENTR_I ,0x1 ); +guard (raw_spinlock_irqsave)(&its->inv_lock); +its_writeq_relaxed (its, didr,GICV5_ITS_DIDR );its_writel_relaxed (its, eidr,GICV5_ITS_EIDR );its_writel_relaxed (its, eventr,GICV5_ITS_INV_EVENTR );@@ -371,6 +376,9 @@ static int gicv5_its_device_cache_inv(struct gicv5_its_chip_data *its,FIELD_PREP (GICV5_ITS_INV_DEVICER_EVENTID_BITS , its_dev->itt_cfg.event_id_bits) |FIELD_PREP (GICV5_ITS_INV_DEVICER_L1 ,0x0 ); + +guard (raw_spinlock_irqsave)(&its->inv_lock); +its_writeq_relaxed (its, didr,GICV5_ITS_DIDR );its_writel_relaxed (its, devicer,GICV5_ITS_INV_DEVICER );@@ -1112,6 +1120,7 @@ static int __init gicv5_its_init_bases(void __iomem *its_base, struct fwnode_hanreturn -ENOMEM ;mutex_init (&its_node->dev_alloc_lock); +raw_spin_lock_init (&its_node->inv_lock);xa_init (&its_node->its_devices); its_node->fwnode = handle; its_node->its_base = its_base;Signature · 2 lines
-- 2.34.1
Re: [PATCH v2 04/10] irqchip/gic-v5: Serialise ITS invalidation commands
Quoted 15 lines · Lorenzo Pieralisi
Quoted 8 lines · Sascha Bischoff
The ITS uses the shared DIDR and EIDR registers to select the DeviceID and EventID whose translation is to be invalidated. Event invalidations for different IRQs can overlap, as can an event invalidation and a device invalidation. The per-IRQ descriptor lock does not serialise these commands, so writes can interleave and cause an invalidation to use the DeviceID or EventID of another IRQ being invalidated concurrently on a different CPU.
Quoted 5 lines
Serialise the command register writes and STATUSR.IDLE polls for both invalidation paths with a per-ITS raw spinlock. The KVM
gicv5_its_set_vcpu_affinity()callback calls the event invalidation helper viairq_set_vcpu_affinity(), which holds the IRQ descriptor lock. This path cannot sleep, so use atomic polling.
Quoted 3 lines
Same comment here as IRS sync. This one though looks like a host driver bug that can happen regardless of KVM, so I'd just fix it and remove/rephrase this paragraph.
Done, thanks!
Quoted 7 lines
Quoted 4 lines
Fixes 57d72196dfc8 ("irqchip/gic-v5: Add GICv5 ITS support")Reported-by Sashiko AI <[email protected]>Again, this is linking to a report on a series that wasn't merged yet but probably it makes sense to leave it there for context.
Yeah, I was just trying to make it clear where this was reported and how.
Thanks,
Sascha
Quoted 61 lines
Quoted 6 lines
Signed-off-by Sascha Bischoff <[email protected]>--- drivers/irqchip/irq-gic-v5-its.c | 9 +++++++++ 1 file changed, 9 insertions(+)Quoted 52 lines
drivers/irqchip/irq-gic-v5-its.c +9
-0@@ -16,6 +16,7 @@#include <linux/of_address.h> #include <linux/of_irq.h> #include <linux/slab.h> +#include <linux/spinlock.h> #include <linux/irqchip.h> #include <linux/irqchip/arm-gic-v5.h> @@ -28,6 +29,8 @@struct gicv5_its_chip_data {struct xarray its_devices;struct mutex dev_alloc_lock; +/* Event and device invalidation commands share DIDR. */ +raw_spinlock_t inv_lock;struct fwnode_handle *fwnode;struct gicv5_its_devtab_cfg devtab_cfgr;void __iomem *its_base;@@ -129,6 +132,8 @@ static int gicv5_its_itt_cache_inv(struct gicv5_its_chip_data *its, u32 device_i eidr =FIELD_PREP (GICV5_ITS_EIDR_EVENTID , event_id); eventr =FIELD_PREP (GICV5_ITS_INV_EVENTR_I ,0x1 ); +guard (raw_spinlock_irqsave)(&its->inv_lock); +its_writeq_relaxed (its, didr,GICV5_ITS_DIDR );its_writel_relaxed (its, eidr,GICV5_ITS_EIDR );its_writel_relaxed (its, eventr,GICV5_ITS_INV_EVENTR );@@ -371,6 +376,9 @@ static int gicv5_its_device_cache_inv(struct gicv5_its_chip_data *its,FIELD_PREP (GICV5_ITS_INV_DEVICER_EVENTID_BITS , its_dev->itt_cfg.event_id_bits) |FIELD_PREP (GICV5_ITS_INV_DEVICER_L1 ,0x0 ); + +guard (raw_spinlock_irqsave)(&its->inv_lock); +its_writeq_relaxed (its, didr,GICV5_ITS_DIDR );its_writel_relaxed (its, devicer,GICV5_ITS_INV_DEVICER );@@ -1112,6 +1120,7 @@ static int __init gicv5_its_init_bases(void __iomem *its_base, struct fwnode_hanreturn -ENOMEM ;mutex_init (&its_node->dev_alloc_lock); +raw_spin_lock_init (&its_node->inv_lock);xa_init (&its_node->its_devices); its_node->fwnode = handle; its_node->its_base = its_base;Signature · 2 lines
-- 2.34.1
PATCH v2 5/10 irqchip/gic-v5: Use linear DT and ITT when L2 covers all IDs
In reply to Sascha BischoffThe DT and ITT level selector incorrectly chooses a two-level table when the selected L2 table has exactly enough entries to cover the full ID space. There are no L1 index bits in this case. ITT allocation correctly rejects the layout and device registration fails; the DT path instead allocates an unnecessary one-entry L1 table.
Select a linear DT or ITT when the L2 width equals the ID width.
--- drivers/irqchip/irq-gic-v5-its.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v5-its.c +1 -1
@@ -337,7 +337,7 @@ static bool gicv5_its_l2sz_two_level(bool devtab, u32 its_idr1, u8 id_bits, u8 * l2_bits =gicv5_its_l2sz_to_l2_bits (l2_sz); -if (l2_bits > id_bits) +if (l2_bits >= id_bits)return false; *sz = l2_sz;
Signature · 1 line
2.34.1
PATCH v2 6/10 irqchip/gic-v5: Honour ACPI ITS noncoherent flag
In reply to Sascha BischoffThe ACPI ITS probe passes its noncoherent flag to gicv5_its_init_bases(), but the common initializer checks a DT property instead. For an ACPI ITS, this always selects coherent cache settings and skips the cache maintenance required for its tables.
Use the noncoherent argument, which both firmware paths already supply.
--- drivers/irqchip/irq-gic-v5-its.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v5-its.c +1 -1
@@ -1135,7 +1135,7 @@ static int __init gicv5_its_init_bases(void __iomem *its_base, struct fwnode_han goto out_free_node; } -if (of_property_read_bool (np,"dma-noncoherent" )) { +if (noncoherent) {/* * A non-coherent ITS implies that some cache levels cannot be * used coherently by the cores and GIC. Our only option is to mark
Signature · 1 line
2.34.1
PATCH v2 7/10 irqchip/gic-v5: Use firmware node name in ITS warning
In reply to Sascha BischoffThe common ITS initialiser can be called with an ACPI firmware node. If firmware leaves the ITS enabled, the warning dereferences the DT node pointer, which is NULL on that path.
Use the firmware node name for the warning and drop the DT-only pointer.
--- drivers/irqchip/irq-gic-v5-its.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/irqchip/irq-gic-v5-its.c +2 -2
@@ -1109,7 +1109,6 @@ static int gicv5_its_init_domain(struct gicv5_its_chip_data *its, struct irq_domstatic int __init gicv5_its_init_bases (void __iomem *its_base,struct fwnode_handle *handle,struct irq_domain *parent_domain,bool noncoherent) { -struct device_node *np =to_of_node (handle);struct gicv5_its_chip_data *its_node;u32 cr0, cr1;bool enabled;
@@ -1129,7 +1128,8 @@ static int __init gicv5_its_init_bases(void __iomem *its_base, struct fwnode_han cr0 =its_readl_relaxed (its_node,GICV5_ITS_CR0 ); enabled =FIELD_GET (GICV5_ITS_CR0_ITSEN , cr0); -if (WARN (enabled,"ITS %s enabled, disabling it before proceeding\n" , np->full_name)) { +if (WARN (enabled,"ITS %s enabled, disabling it before proceeding\n" , +fwnode_get_name (handle))) { ret =gicv5_its_disable (its_node);if (ret) goto out_free_node;
Signature · 1 line
2.34.1
PATCH v2 8/10 irqchip/gic-v5: Invalidate ITS device cache before freeing ITT
In reply to Sascha BischoffA cached device table entry can still reference the ITT after its memory is freed via kfree(), even if the DTE has been marked as invalid. Once the memory has been released, it could be reallocated, and it would be unfortunate for the hardware to interpret this as a valid ITT.
Invalidate the device cache and wait for completion before freeing the ITT during device teardown.
--- drivers/irqchip/irq-gic-v5-its.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v5-its.c +3 -1
@@ -556,6 +556,7 @@ static int gicv5_its_device_unregister(struct gicv5_its_chip_data *its, struct gicv5_its_dev *its_dev) {__le64 *dte; +int ret; dte =gicv5_its_devtab_get_dte_ref (its, its_dev->device_id, false);
@@ -568,9 +569,10 @@ static int gicv5_its_device_unregister(struct gicv5_its_chip_data *its,/* Zero everything - make it clear that this is an invalid entry */ its_write_table_entry (its, dte,0 ); + ret =gicv5_its_device_cache_inv (its, its_dev);gicv5_its_free_itt (its_dev); -return gicv5_its_device_cache_inv (its, its_dev); +return ret; }/*
Signature · 1 line
2.34.1
PATCH v2 9/10 irqchip/gic-v5: Clean the allocated linear device table size
In reply to Sascha BischoffWhen the linear device table exceeds the kmalloc limit, the driver caps the DeviceID width before allocation but keeps the original size for cache maintenance. On a noncoherent ITS, this cleans beyond the allocated table.
Recalculate the size after capping the DeviceID width.
--- drivers/irqchip/irq-gic-v5-its.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/irqchip/irq-gic-v5-its.c +3 -3
@@ -594,14 +594,14 @@ static int gicv5_its_alloc_devtab_linear(struct gicv5_its_chip_data *its,* kmalloc limits so that the system can chug along with a linear * device table. */ - sz =BIT_ULL (device_id_bits) *sizeof (*devtab); -if (sz >KMALLOC_MAX_SIZE ) { -u8 device_id_cap =ilog2 (KMALLOC_MAX_SIZE /sizeof (*devtab)); +if (BIT_ULL (device_id_bits) *sizeof (*devtab) >KMALLOC_MAX_SIZE ) { +u8 device_id_cap =ilog2 (KMALLOC_MAX_SIZE /sizeof (*devtab));pr_warn ("Limiting device ID bits from %u to %u\n" , device_id_bits, device_id_cap); device_id_bits = device_id_cap; } + sz =BIT_ULL (device_id_bits) *sizeof (*devtab); devtab =kcalloc (BIT (device_id_bits),sizeof (*devtab),GFP_KERNEL );if (!devtab)
Signature · 1 line
2.34.1
Re: [PATCH v2 09/10] irqchip/gic-v5: Clean the allocated linear device table size
Quoted 5 lines · Sascha Bischoff
When the linear device table exceeds the kmalloc limit, the driver caps the DeviceID width before allocation but keeps the original size for cache maintenance. On a noncoherent ITS, this cleans beyond the allocated table.
Quoted 7 lines
Recalculate the size after capping the DeviceID width.
Fixes 57d72196dfc85 ("irqchip/gic-v5: Add GICv5 ITS support")Signed-off-by Sascha Bischoff <[email protected]>--- drivers/irqchip/irq-gic-v5-its.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 26 lines
drivers/irqchip/irq-gic-v5-its.c +3
-3@@ -594,14 +594,14 @@ static int gicv5_its_alloc_devtab_linear(struct gicv5_its_chip_data *its,* kmalloc limits so that the system can chug along with a linear * device table. */ - sz =BIT_ULL (device_id_bits) *sizeof (*devtab); -if (sz >KMALLOC_MAX_SIZE ) { -u8 device_id_cap =ilog2 (KMALLOC_MAX_SIZE /sizeof (*devtab)); +if (BIT_ULL (device_id_bits) *sizeof (*devtab) >KMALLOC_MAX_SIZE ) { +u8 device_id_cap =ilog2 (KMALLOC_MAX_SIZE /sizeof (*devtab));pr_warn ("Limiting device ID bits from %u to %u\n" , device_id_bits, device_id_cap); device_id_bits = device_id_cap; } + sz =BIT_ULL (device_id_bits) *sizeof (*devtab); devtab =kcalloc (BIT (device_id_bits),sizeof (*devtab),GFP_KERNEL );if (!devtab)Signature · 2 lines
-- 2.34.1
PATCH v2 10/10 irqchip/gic-v5: Release ITS MMIO region on DT probe failure
In reply to Sascha Bischoffof_io_request_and_map() reserves the ITS configuration frame region. If ITS initialisation fails after mapping it, the error path only unmaps the registers and leaves the region reserved.
Keep the resource description and release the region on that path.
--- drivers/irqchip/irq-gic-v5-its.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/irqchip/irq-gic-v5-its.c +7 -0
@@ -1188,6 +1188,7 @@ static int __init gicv5_its_init_bases(void __iomem *its_base, struct fwnode_hanstatic int __init gicv5_its_init (struct device_node *node) {void __iomem *its_base; +struct resource res;int ret, idx; idx =of_property_match_string (node,"reg-names" ,"ns-config" );
@@ -1196,6 +1197,11 @@ static int __init gicv5_its_init(struct device_node *node)return -ENODEV ; } +/* Save the region to release if ITS setup fails after mapping it. */ + ret =of_address_to_resource (node, idx, &res); +if (ret) +return ret; + its_base =of_io_request_and_map (node, idx,of_node_full_name (node));if (IS_ERR (its_base)) {pr_err ("%pOF: unable to map GICv5 ITS_CONFIG_FRAME\n" , node);
@@ -1212,6 +1218,7 @@ static int __init gicv5_its_init(struct device_node *node) out_unmap:iounmap (its_base); +release_mem_region (res.start,resource_size (&res));return ret; }
Signature · 1 line
2.34.1
Hi Sascha,
I found a couple more issues in the GICv5 host driver while looking into pKVM support for GICv5. Rather than explain the fixes, I thought I'd send you patches for two of them instead. If you think they're useful, please include them in v3. They apply on top of this series. Boot tested on the GICv5 FVP with a two-level device table.
For the third one, the thing I spotted is that if the IDLE poll after an IRS_MAP_L2_ISTR write times out, gicv5_irs_iste_alloc() clears the level 1 entry and frees the level 2 IST, but nothing cancels the map. The IRS can still complete it and use the freed table. Keeping the table isn't enough either, since the next allocation in that range rewrites the level 1 entry while the map may still be running (R_SDVFP). vgic_v5_alloc_l2_vmt() and the ITT frees after a timed-out invalidate have the same shape. The question is, can an IRS miss the poll, or is a timeout here only ever a dead IRS?
Cheers,
/fuad
--- >8 ---
From: Fuad Tabba <[email protected]>
Subject: [PATCH] irqchip/gic-v5: Invalidate the level 1 DTE when registering a device
With a two-level device table, gicv5_its_device_register() makes a level 1 DTE valid when it allocates the level 2 table that it points to. However, gicv5_its_device_cache_inv() invalidates the ITS caches with ITS_INV_DEVICER.L1 clear, which doesn't invalidate the level 1 DTE. An update isn't guaranteed to be visible to the ITS until a cache invalidation that covers it completes (R_HQFDL in the GICv5 specification). An ITS that cached the level 1 DTE while it was invalid can keep dropping events for the DeviceIDs in its range.
Set ITS_INV_DEVICER.L1 on every device invalidation. It covers the level 2 DTE as well, and has no effect with a linear device table.
---
Notes:
Setting L1 on every invalidation turns each registration and teardown into a range invalidate, both rare paths, and keeps the function simple. Setting it only when registration allocates the level 2 table would miss a registration that fails after the allocation, which leaves the level 1 DTE valid.
drivers/irqchip/irq-gic-v5-its.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v5-its.c +2 -1
@@ -372,10 +372,11 @@ static int gicv5_its_device_cache_inv(struct gicv5_its_chip_data *its,u64 didr; didr =FIELD_PREP (GICV5_ITS_DIDR_DEVICEID , its_dev->device_id); +/* L1 also covers an L1 DTE that a registration may have just made valid. */ devicer =FIELD_PREP (GICV5_ITS_INV_DEVICER_I ,0x1 ) |FIELD_PREP (GICV5_ITS_INV_DEVICER_EVENTID_BITS , its_dev->itt_cfg.event_id_bits) | -FIELD_PREP (GICV5_ITS_INV_DEVICER_L1 ,0x0 ); +FIELD_PREP (GICV5_ITS_INV_DEVICER_L1 ,0x1 );guard (raw_spinlock_irqsave)(&its->inv_lock);
--- >8 ---
From: Fuad Tabba <[email protected]>
Subject: [PATCH] irqchip/gic-v5: Clean a level 2 device table before making it valid
gicv5_its_alloc_l2_devtab() allocates a zeroed level 2 device table and writes the level 1 DTE that points to it with VALID set. Unlike the other ITS tables, the new table isn't cleaned to the PoC first. On a non-coherent ITS, the zeroes can still sit in the CPU caches when the ITS reads the table, so it can take stale memory as a valid level 2 DTE for a DeviceID that nothing has registered.
Clean the table before the level 1 DTE is written.
--- drivers/irqchip/irq-gic-v5-its.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/irqchip/irq-gic-v5-its.c +2 -0
@@ -416,6 +416,8 @@ static int gicv5_its_alloc_l2_devtab(struct gicv5_its_chip_data *its,if (!l2devtab)return -ENOMEM ; +gicv5_its_dcache_clean (its, l2devtab,BIT (span) *sizeof (*l2devtab)); + its->devtab_cfgr.l2.l2ptrs[l1_index] = l2devtab; l1dte = FIELD_PREP(GICV5_DTL1E_SPAN, span) |
Lorenzo Pieralisi
maintainerQuoted 8 lines · Fuad Tabba
Hi Sascha,
I found a couple more issues in the GICv5 host driver while looking into pKVM support for GICv5. Rather than explain the fixes, I thought I'd send you patches for two of them instead. If you think they're useful, please include them in v3. They apply on top of this series. Boot tested on the GICv5 FVP with a two-level device table.
Quoted 9 lines
For the third one, the thing I spotted is that if the IDLE poll after an
IRS_MAP_L2_ISTRwrite times out,gicv5_irs_iste_alloc()clears the level 1 entry and frees the level 2 IST, but nothing cancels the map. The IRS can still complete it and use the freed table. Keeping the table isn't enough either, since the next allocation in that range rewrites the level 1 entry while the map may still be running (R_SDVFP).vgic_v5_alloc_l2_vmt()and the ITT frees after a timed-out invalidate have the same shape. The question is, can an IRS miss the poll, or is a timeout here only ever a dead IRS?
Thank you for your patches Fuad.
The latter, though freeing memory on timeout wasn't a good idea given that there is no way to cancel the respective, pending, mapping.
Quoted 22 lines
Cheers,
/fuad--- >8 ---
From: Fuad Tabba <[email protected]>
Subject: [PATCH] irqchip/gic-v5: Invalidate the level 1 DTE when registering a deviceWith a two-level device table,
gicv5_its_device_register()makes a level 1 DTE valid when it allocates the level 2 table that it points to. However,gicv5_its_device_cache_inv()invalidates the ITS caches with ITS_INV_DEVICER.L1 clear, which doesn't invalidate the level 1 DTE. An update isn't guaranteed to be visible to the ITS until a cache invalidation that covers it completes (R_HQFDLin the GICv5 specification). An ITS that cached the level 1 DTE while it was invalid can keep dropping events for the DeviceIDs in its range.Set ITS_INV_DEVICER.L1 on every device invalidation. It covers the level 2 DTE as well, and has no effect with a linear device table.
Fixes 57d72196dfc85 ("irqchip/gic-v5: Add GICv5 ITS support")Signed-off-by Fuad Tabba <[email protected]>
Quoted 8 lines
---
Notes:
Setting L1 on every invalidation turns each registration and teardown into a range invalidate, both rare paths, and keeps the function simple. Setting it only when registration allocates the level 2 table would miss a registration that fails after the allocation, which leaves the level 1 DTE valid.
I can't follow. I agree that we have to invalidate the L1 DTE on L2 allocation but that's a one-off, I don't understand what issues you are pointing out in the Notes above, if you can point out please the code paths it refers to that'd help.
Thanks,
Lorenzo
Quoted 54 lines
drivers/irqchip/irq-gic-v5-its.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/irqchip/irq-gic-v5-its.c +2
-2@@ -372,10 +372,11 @@ static int gicv5_its_device_cache_inv(struct gicv5_its_chip_data *its,u64 didr; didr =FIELD_PREP (GICV5_ITS_DIDR_DEVICEID , its_dev->device_id); +/* L1 also covers an L1 DTE that a registration may have just made valid. */ devicer =FIELD_PREP (GICV5_ITS_INV_DEVICER_I ,0x1 ) |FIELD_PREP (GICV5_ITS_INV_DEVICER_EVENTID_BITS , its_dev->itt_cfg.event_id_bits) | -FIELD_PREP (GICV5_ITS_INV_DEVICER_L1 ,0x0 ); +FIELD_PREP (GICV5_ITS_INV_DEVICER_L1 ,0x1 );guard (raw_spinlock_irqsave)(&its->inv_lock); --- >8 ---From: Fuad Tabba <[email protected]>
Subject: [PATCH] irqchip/gic-v5: Clean a level 2 device table before making it valid
gicv5_its_alloc_l2_devtab()allocates a zeroed level 2 device table and writes the level 1 DTE that points to it with VALID set. Unlike the other ITS tables, the new table isn't cleaned to the PoC first. On a non-coherent ITS, the zeroes can still sit in the CPU caches when the ITS reads the table, so it can take stale memory as a valid level 2 DTE for a DeviceID that nothing has registered.Clean the table before the level 1 DTE is written.
Fixes 57d72196dfc85 ("irqchip/gic-v5: Add GICv5 ITS support")Signed-off-by Fuad Tabba <[email protected]>--- drivers/irqchip/irq-gic-v5-its.c | 2 ++ 1 file changed, 2 insertions(+)drivers/irqchip/irq-gic-v5-its.c +2
-0@@ -416,6 +416,8 @@ static int gicv5_its_alloc_l2_devtab(struct gicv5_its_chip_data *its,if (!l2devtab)return -ENOMEM ; +gicv5_its_dcache_clean (its, l2devtab,BIT (span) *sizeof (*l2devtab)); + its->devtab_cfgr.l2.l2ptrs[l1_index] = l2devtab; l1dte = FIELD_PREP(GICV5_DTL1E_SPAN, span) |
Hi Lorenzo,
On Mon, 16 Nov 2026 12:14:50 +0000, Lorenzo Pieralisi <[email protected]> wrote:
[...]
Quoted 7 lines
Quoted 2 lines
invalidate have the same shape. The question is, can an IRS miss the poll, or is a timeout here only ever a dead IRS?
Thank you for your patches Fuad.
The latter, though freeing memory on timeout wasn't a good idea given that there is no way to cancel the respective, pending, mapping.
Thanks, that answers it. If you'd like a patch that doesn't free the memory on a timeout, let me know and I'll send one.
[...]
Quoted 11 lines
Quoted 6 lines
Notes:
Setting L1 on every invalidation turns each registration and teardown into a range invalidate, both rare paths, and keeps the function simple. Setting it only when registration allocates the level 2 table would miss a registration that fails after the allocation, which leaves the level 1 DTE valid.I can't follow. I agree that we have to invalidate the L1 DTE on L2 allocation but that's a one-off, I don't understand what issues you are pointing out in the Notes above, if you can point out please the code paths it refers to that'd help.
gicv5_its_device_register() can fail after gicv5_its_devtab_get_dte_ref() has made the L1 DTE valid, and before the gicv5_its_device_cache_inv() at the end. That happens if the EventID bits check fails, or the ITT allocation does. The L1 DTE is then already valid for the next device registered under it, so that registration doesn't allocate a level 2 table.
The patch Notes were about setting ITS_INV_DEVICER.L1 in that gicv5_its_device_cache_inv() call only when the registration allocated the table. In that case the failed registration never reaches that call and the next one reaches it with L1 clear, so this L1 DTE is never invalidated. Invalidating in gicv5_its_alloc_l2_devtab(), right after the L1 DTE write, is the one-off you describe. I'll rework the patch to do that instead.
Cheers,
/fuad
Lorenzo Pieralisi
maintainerQuoted 8 lines · Fuad Tabba
Hi Lorenzo,
On Mon, 16 Nov 2026 12:14:50 +0000, Lorenzo Pieralisi <[email protected]> wrote:
[...]Quoted 3 lines
Quoted 2 lines
invalidate have the same shape. The question is, can an IRS miss the poll, or is a timeout here only ever a dead IRS?
Quoted 7 lines
Quoted 4 lines
Thank you for your patches Fuad.
The latter, though freeing memory on timeout wasn't a good idea given that there is no way to cancel the respective, pending, mapping.
Thanks, that answers it. If you'd like a patch that doesn't free the memory on a timeout, let me know and I'll send one.
Thanks. Again, if that timeout expires I think we have more serious problems than the IST mapping but I do agree that freeing memory is not the answer; not urgent - please send a patch given that you spotted it, can obviously do it too.
Quoted 21 lines
[...]
Quoted 11 lines
Quoted 6 lines
Notes:
Setting L1 on every invalidation turns each registration and teardown into a range invalidate, both rare paths, and keeps the function simple. Setting it only when registration allocates the level 2 table would miss a registration that fails after the allocation, which leaves the level 1 DTE valid.I can't follow. I agree that we have to invalidate the L1 DTE on L2 allocation but that's a one-off, I don't understand what issues you are pointing out in the Notes above, if you can point out please the code paths it refers to that'd help.
gicv5_its_device_register()can fail aftergicv5_its_devtab_get_dte_ref()has made the L1 DTE valid, and before thegicv5_its_device_cache_inv()at the end. That happens if the EventID bits check fails, or the ITT allocation does. The L1 DTE is then already valid for the next device registered under it, so that registration doesn't allocate a level 2 table.
Quoted 7 lines
The patch Notes were about setting ITS_INV_DEVICER.L1 in that
gicv5_its_device_cache_inv()call only when the registration allocated the table. In that case the failed registration never reaches that call and the next one reaches it with L1 clear, so this L1 DTE is never invalidated. Invalidating ingicv5_its_alloc_l2_devtab(), right after the L1 DTE write, is the one-off you describe. I'll rework the patch to do that instead.
Yes, I think that's what we should do - invalidating in gicv5_its_alloc_l2_devtab() once for all and leave everything else as-is matches architecture guidelines.
Thanks again.
Lorenzo
Hi Fuad,
Quoted 10 lines · Lorenzo Pieralisi
Quoted 9 lines · Fuad Tabba
Hi Lorenzo,
On Mon, 16 Nov 2026 12:14:50 +0000, Lorenzo Pieralisi <[email protected]> wrote:
[...]Quoted 4 lines
Quoted 2 lines
invalidate have the same shape. The question is, can an IRS miss the poll, or is a timeout here only ever a dead IRS?
Thank you for your patches Fuad.
Seconded. Thanks a lot.
I'm more than happy to include "irqchip/gic-v5: Clean a level 2 device table before making it valid" in v3!
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
The latter, though freeing memory on timeout wasn't a good idea given that there is no way to cancel the respective, pending, mapping.
Thanks, that answers it. If you'd like a patch that doesn't free the memory on a timeout, let me know and I'll send one.
Thanks. Again, if that timeout expires I think we have more serious problems than the IST mapping but I do agree that freeing memory is not the answer; not urgent - please send a patch given that you spotted it, can obviously do it too.
I've got some patches addressing the ITT and IST mapping issues in the host driver, which I can include in v3 if you haven't already started working on these. I'll make sure to include the appropriate Reported-by tags, of course!
I'll post a fix for the VMT separately as it doesn't belong in this series.
Quoted 30 lines
Quoted 22 lines
[...]
Quoted 11 lines
Quoted 6 lines
Notes:
Setting L1 on every invalidation turns each registration and teardown into a range invalidate, both rare paths, and keeps the function simple. Setting it only when registration allocates the level 2 table would miss a registration that fails after the allocation, which leaves the level 1 DTE valid.I can't follow. I agree that we have to invalidate the L1 DTE on L2 allocation but that's a one-off, I don't understand what issues you are pointing out in the Notes above, if you can point out please the code paths it refers to that'd help.
gicv5_its_device_register()can fail aftergicv5_its_devtab_get_dte_ref()has made the L1 DTE valid, and before thegicv5_its_device_cache_inv()at the end. That happens if the EventID bits check fails, or the ITT allocation does. The L1 DTE is then already valid for the next device registered under it, so that registration doesn't allocate a level 2 table.Quoted 7 lines
The patch Notes were about setting ITS_INV_DEVICER.L1 in that
gicv5_its_device_cache_inv()call only when the registration allocated the table. In that case the failed registration never reaches that call and the next one reaches it with L1 clear, so this L1 DTE is never invalidated. Invalidating ingicv5_its_alloc_l2_devtab(), right after the L1 DTE write, is the one-off you describe. I'll rework the patch to do that instead.
Quoted 3 lines
Yes, I think that's what we should do - invalidating in
gicv5_its_alloc_l2_devtab()once for all and leave everything else as-is matches architecture guidelines.
Agreed. I've got a reworked fix for this too, which I can include in v3.
Quoted 4 lines
Thanks again.
Lorenzo
Thanks,
Sascha
Hi Sascha, Lorenzo,
On Wed, 18 Nov 2026 at 14:59, Sascha Bischoff <[email protected]> wrote:
[...]
Quoted 2 lines
I'm more than happy to include "irqchip/gic-v5: Clean a level 2 device table before making it valid" in v3!
Thanks.
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
The latter, though freeing memory on timeout wasn't a good idea given that there is no way to cancel the respective, pending, mapping.
Thanks, that answers it. If you'd like a patch that doesn't free the memory on a timeout, let me know and I'll send one.
Thanks. Again, if that timeout expires I think we have more serious problems than the IST mapping but I do agree that freeing memory is not the answer; not urgent - please send a patch given that you spotted it, can obviously do it too.
Quoted 6 lines
I've got some patches addressing the ITT and IST mapping issues in the host driver, which I can include in v3 if you haven't already started working on these. I'll make sure to include the appropriate Reported-by tags, of course!
I'll post a fix for the VMT separately as it doesn't belong in this series.
I haven't started on anything, so I'll leave this with you then.
Cheers,
/fuad
Quoted 8 lines · Fuad Tabba
Hi Sascha, Lorenzo,
On Wed, 18 Nov 2026 at 14:59, Sascha Bischoff <[email protected]> wrote:
[...]Quoted 2 lines
I'm more than happy to include "irqchip/gic-v5: Clean a level 2 device table before making it valid" in v3!
Thanks.
No, thank you!
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 7 lines
Quoted 4 lines
The latter, though freeing memory on timeout wasn't a good idea given that there is no way to cancel the respective, pending, mapping.
Thanks, that answers it. If you'd like a patch that doesn't free the memory on a timeout, let me know and I'll send one.
Thanks. Again, if that timeout expires I think we have more serious problems than the IST mapping but I do agree that freeing memory is not the answer; not urgent - please send a patch given that you spotted it, can obviously do it too.
Quoted 8 lines
Quoted 6 lines
I've got some patches addressing the ITT and IST mapping issues in the host driver, which I can include in v3 if you haven't already started working on these. I'll make sure to include the appropriate Reported-by tags, of course!
I'll post a fix for the VMT separately as it doesn't belong in this series.
I haven't started on anything, so I'll leave this with you then.
Perfect - I was trying to avoid the duplication of work :)
Quoted 3 lines
Cheers,
/fuad
Sascha