iommu_get_irqdomain() lazily creates a single irq domain and caches it in the global iommu_irqdomain, shared by all IOMMUs. Both failure branches of __iommu_setup_intcapxt() call irq_domain_remove() on it, which frees the domain, but the global pointer is never cleared and keeps handing out the freed domain. The failure does not prevent reuse: register_syscore() runs in the IOMMU_ENABLED init state, one state before amd_iommu_enable_interrupts() runs in IOMMU_PCI_INIT, and the error paths never unregister it. On resume, amd_iommu_resume() re-runs amd_iommu_enable_interrupts(); for an IOMMU whose setup failed, int_enabled was never set, so __iommu_setup_intcapxt() runs again, gets the freed domain from iommu_get_irqdomain() and passes it to irq_domain_alloc_irqs(). The shared domain also makes a single failure affect the healthy IOMMUs: if IOMMU#0 set up fine and IOMMU#1's setup fails, the remove frees a domain that still has IOMMU#0's irqs mapped, tripping the WARN_ON(!radix_tree_empty) in irq_domain_remove(). Keep the domain alive on failure; a later attempt (including the resume path) reuses the cached domain. The request_threaded_irq() failure branch still backs out the allocated irq via irq_domain_free_irqs(). Found by static analysis. Fixes: d1adcfbb520c ("iommu/amd: Fix IOMMU interrupt generation in X2APIC mode") Cc: stable@vger.kernel.org Signed-off-by: Chengyu Liu --- drivers/iommu/amd/init.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 8a410d4aa3..78b11b04dd 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -2522,6 +2522,13 @@ static int __iommu_setup_intcapxt(struct amd_iommu *iommu, const char *devname, int irq, ret; int node = dev_to_node(&iommu->dev->dev); + /* + * The IRQ domain is a cached singleton shared by all IOMMUs; a + * setup failure must not remove it, otherwise the global + * iommu_irqdomain is left dangling (and a shared domain could be + * freed while still mapped by another IOMMU). Leave it in place + * so a later retry (e.g. resume) can use it. + */ domain = iommu_get_irqdomain(); if (!domain) return -ENXIO; @@ -2532,16 +2539,13 @@ static int __iommu_setup_intcapxt(struct amd_iommu *iommu, const char *devname, info.hwirq = hwirq; irq = irq_domain_alloc_irqs(domain, 1, node, &info); - if (irq < 0) { - irq_domain_remove(domain); + if (irq < 0) return irq; - } ret = request_threaded_irq(irq, NULL, thread_fn, IRQF_ONESHOT, devname, iommu); if (ret) { irq_domain_free_irqs(irq, 1); - irq_domain_remove(domain); return ret; } -- 2.25.1