[PATCH v10 3/4] PCI: dwc: Add dw_pcie_mask_msi() to mask chained MSI without freeing domain
From: Krishna Chaitanya Chundru
Date: Thu Nov 26 2026 - 00:17:39 EST
dw_pcie_free_msi() detaches the chained MSI handler(s) and then removes
the MSI IRQ domain via irq_domain_remove(). That is correct for the
dw_pcie_host_deinit() teardown path, where PCI devices have already been
removed and no MSI mappings remain.
It is not safe to call from the shutdown()/reboot path. device_shutdown()
does not remove PCI devices or tear down their per-device child MSI
domains, so endpoint drivers that do not free their MSI vectors in a
shutdown callback leave live MSI descriptors parented to the domain.
Removing the domain there orphans those descriptors and leaves dangling
references to freed memory: during a subsequent kexec CPU teardown, IRQ
migration walks irq_data->parent_data and can dereference the freed
msi_irq_domain.
Add dw_pcie_mask_msi(), which clears the chained handler on the MSI
parent interrupt line(s) via irq_set_chained_handler_and_data(). That
masks the line(s) at the irqchip under desc->lock while leaving the IRQ
domain and the downstream MSI mappings intact. disable_irq() is not used
here: the parent lines are chained handlers, so the standard flow-handler
disabled-check never runs, and on irqchips without .irq_disable (e.g.
GIC) a lazy disable would leave the line unmasked and a late MSI could
still reach dw_handle_msi_irq() and touch unclocked DBI registers.
dw_pcie_free_msi() now reuses the helper, so it is exactly the shutdown
masking plus irq_domain_remove().
Signed-off-by: Krishna Chaitanya Chundru <krishna.chundru@xxxxxxxxxxxxxxxx>
---
drivers/pci/controller/dwc/pcie-designware-host.c | 17 ++++++++++++++++-
drivers/pci/controller/dwc/pcie-designware.h | 4 ++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 0837bb9e67e0..c81424e2f95c 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -227,7 +227,16 @@ int dw_pcie_allocate_msi_domains(struct dw_pcie_rp *pp)
}
EXPORT_SYMBOL_GPL(dw_pcie_allocate_msi_domains);
-void dw_pcie_free_msi(struct dw_pcie_rp *pp)
+/**
+ * dw_pcie_mask_msi - Detach and mask the chained MSI parent interrupt(s)
+ * @pp: DWC PCIe RP private data
+ *
+ * Detach the chained MSI handler(s), which masks the parent IRQ line(s),
+ * while leaving the MSI domain and downstream mappings intact (unlike
+ * dw_pcie_free_msi()). Safe for the shutdown() path, where PCI devices
+ * and their MSI descriptors are not removed.
+ */
+void dw_pcie_mask_msi(struct dw_pcie_rp *pp)
{
u32 ctrl;
@@ -235,6 +244,12 @@ void dw_pcie_free_msi(struct dw_pcie_rp *pp)
if (pp->msi_irq[ctrl] > 0)
irq_set_chained_handler_and_data(pp->msi_irq[ctrl], NULL, NULL);
}
+}
+EXPORT_SYMBOL_GPL(dw_pcie_mask_msi);
+
+void dw_pcie_free_msi(struct dw_pcie_rp *pp)
+{
+ dw_pcie_mask_msi(pp);
irq_domain_remove(pp->msi_irq_domain);
}
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index f774fc6d2a24..677e5423c5e4 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -908,6 +908,7 @@ void dw_handle_msi_irq(struct dw_pcie_rp *pp);
void dw_pcie_msi_init(struct dw_pcie_rp *pp);
int dw_pcie_msi_host_init(struct dw_pcie_rp *pp);
void dw_pcie_free_msi(struct dw_pcie_rp *pp);
+void dw_pcie_mask_msi(struct dw_pcie_rp *pp);
int dw_pcie_setup_rc(struct dw_pcie_rp *pp);
int dw_pcie_host_init(struct dw_pcie_rp *pp);
void dw_pcie_host_deinit(struct dw_pcie_rp *pp);
@@ -938,6 +939,9 @@ static inline int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)
static inline void dw_pcie_free_msi(struct dw_pcie_rp *pp)
{ }
+static inline void dw_pcie_mask_msi(struct dw_pcie_rp *pp)
+{ }
+
static inline int dw_pcie_setup_rc(struct dw_pcie_rp *pp)
{
return 0;
--
2.34.1