linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] PCI: mvebu: Dispose INTx IRQs before to removing INTx domain
@ 2024-07-11 13:25 Marek Behún
  2024-07-11 14:03 ` Andrew Lunn
  2024-07-12 20:41 ` Bjorn Helgaas
  0 siblings, 2 replies; 6+ messages in thread
From: Marek Behún @ 2024-07-11 13:25 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Andrew Lunn, Gregory Clement
  Cc: Thomas Petazzoni, Rob Herring, linux-pci, linux-arm-kernel,
	Manivannan Sadhasivam, Marek Behún

From: Pali Rohár <pali@kernel.org>

The documentation for the irq_domain_remove() function says that all
mappings within the IRQ domain must be disposed before the domain is
removed.

Currently, the INTx IRQs are not disposed in pci-mvebu driver .remove()
method, which causes the kernel to crash when unloading the driver and
then reading /sys/kernel/debug/irq/irqs/<num> or /proc/interrupts.

Unmapping of the IRQs at this point of the .remove() method is safe,
since the PCIe bus is already unregistered, and all its devices are
unbound from their drivers and removed. If there was indeed any
remaining use of PCIe resources, then it would mean that PCIe hotplug
code is broken, and we have bigger problems.

Fixes: ec075262648f ("PCI: mvebu: Implement support for legacy INTx interrupts")
Reported-by: Hajo Noerenberg <hajo-linux-bugzilla@noerenberg.de>
Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Marek Behún <kabel@kernel.org>
[ Marek: refactored a little, added more explanation to commit message ]
Signed-off-by: Marek Behún <kabel@kernel.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
Changes since v1:
- added explanation into commit message about why this is safe to do,
  as suggested by Andy. The explanation originally comes from Pali:
    https://lore.kernel.org/linux-arm-kernel/20220809133911.hqi7eyskcq2sojia@pali/
---
 drivers/pci/controller/pci-mvebu.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
index 29fe09c99e7d..91a02b23aeb1 100644
--- a/drivers/pci/controller/pci-mvebu.c
+++ b/drivers/pci/controller/pci-mvebu.c
@@ -1683,8 +1683,15 @@ static void mvebu_pcie_remove(struct platform_device *pdev)
 			irq_set_chained_handler_and_data(irq, NULL, NULL);
 
 		/* Remove IRQ domains. */
-		if (port->intx_irq_domain)
+		if (port->intx_irq_domain) {
+			for (int j = 0; j < PCI_NUM_INTX; j++) {
+				int virq = irq_find_mapping(port->intx_irq_domain, j);
+
+				if (virq > 0)
+					irq_dispose_mapping(virq);
+			}
 			irq_domain_remove(port->intx_irq_domain);
+		}
 
 		/* Free config space for emulated root bridge. */
 		pci_bridge_emul_cleanup(&port->bridge);
-- 
2.44.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-07-13 19:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-11 13:25 [PATCH v2] PCI: mvebu: Dispose INTx IRQs before to removing INTx domain Marek Behún
2024-07-11 14:03 ` Andrew Lunn
2024-07-12 20:41 ` Bjorn Helgaas
2024-07-13 10:33   ` Thomas Gleixner
2024-07-13 19:32     ` Bjorn Helgaas
2024-07-13 19:56       ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).