Skip to content

Commit 4668619

Browse files
madscientist159maddy-kerneldev
authored andcommitted
PCI: pnv_php: Clean up allocated IRQs on unplug
When the root of a nested PCIe bridge configuration is unplugged, the pnv_php driver leaked the allocated IRQ resources for the child bridges' hotplug event notifications, resulting in a panic. Fix this by walking all child buses and deallocating all its IRQ resources before calling pci_hp_remove_devices(). Also modify the lifetime of the workqueue at struct pnv_php_slot::wq so that it is only destroyed in pnv_php_free_slot(), instead of pnv_php_disable_irq(). This is required since pnv_php_disable_irq() will now be called by workers triggered by hot unplug interrupts, so the workqueue needs to stay allocated. The abridged kernel panic that occurs without this patch is as follows: WARNING: CPU: 0 PID: 687 at kernel/irq/msi.c:292 msi_device_data_release+0x6c/0x9c CPU: 0 UID: 0 PID: 687 Comm: bash Not tainted 6.14.0-rc5+ #2 Call Trace: msi_device_data_release+0x34/0x9c (unreliable) release_nodes+0x64/0x13c devres_release_all+0xc0/0x140 device_del+0x2d4/0x46c pci_destroy_dev+0x5c/0x194 pci_hp_remove_devices+0x90/0x128 pci_hp_remove_devices+0x44/0x128 pnv_php_disable_slot+0x54/0xd4 power_write_file+0xf8/0x18c pci_slot_attr_store+0x40/0x5c sysfs_kf_write+0x64/0x78 kernfs_fop_write_iter+0x1b0/0x290 vfs_write+0x3bc/0x50c ksys_write+0x84/0x140 system_call_exception+0x124/0x230 system_call_vectored_common+0x15c/0x2ec Signed-off-by: Shawn Anastasio <[email protected]> Signed-off-by: Timothy Pearson <[email protected]> [bhelgaas: tidy comments] Signed-off-by: Bjorn Helgaas <[email protected]> Signed-off-by: Madhavan Srinivasan <[email protected]> Link: https://patch.msgid.link/2013845045.1359852.1752615367790.JavaMail.zimbra@raptorengineeringinc.com
1 parent da30705 commit 4668619

File tree

1 file changed

+77
-19
lines changed

1 file changed

+77
-19
lines changed

drivers/pci/hotplug/pnv_php.c

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* PCI Hotplug Driver for PowerPC PowerNV platform.
44
*
55
* Copyright Gavin Shan, IBM Corporation 2016.
6+
* Copyright (C) 2025 Raptor Engineering, LLC
67
*/
78

89
#include <linux/bitfield.h>
@@ -36,8 +37,10 @@ static void pnv_php_register(struct device_node *dn);
3637
static void pnv_php_unregister_one(struct device_node *dn);
3738
static void pnv_php_unregister(struct device_node *dn);
3839

40+
static void pnv_php_enable_irq(struct pnv_php_slot *php_slot);
41+
3942
static void pnv_php_disable_irq(struct pnv_php_slot *php_slot,
40-
bool disable_device)
43+
bool disable_device, bool disable_msi)
4144
{
4245
struct pci_dev *pdev = php_slot->pdev;
4346
u16 ctrl;
@@ -53,19 +56,15 @@ static void pnv_php_disable_irq(struct pnv_php_slot *php_slot,
5356
php_slot->irq = 0;
5457
}
5558

56-
if (php_slot->wq) {
57-
destroy_workqueue(php_slot->wq);
58-
php_slot->wq = NULL;
59-
}
60-
61-
if (disable_device) {
59+
if (disable_device || disable_msi) {
6260
if (pdev->msix_enabled)
6361
pci_disable_msix(pdev);
6462
else if (pdev->msi_enabled)
6563
pci_disable_msi(pdev);
64+
}
6665

66+
if (disable_device)
6767
pci_disable_device(pdev);
68-
}
6968
}
7069

7170
static void pnv_php_free_slot(struct kref *kref)
@@ -74,7 +73,8 @@ static void pnv_php_free_slot(struct kref *kref)
7473
struct pnv_php_slot, kref);
7574

7675
WARN_ON(!list_empty(&php_slot->children));
77-
pnv_php_disable_irq(php_slot, false);
76+
pnv_php_disable_irq(php_slot, false, false);
77+
destroy_workqueue(php_slot->wq);
7878
kfree(php_slot->name);
7979
kfree(php_slot);
8080
}
@@ -561,8 +561,58 @@ static int pnv_php_reset_slot(struct hotplug_slot *slot, bool probe)
561561
static int pnv_php_enable_slot(struct hotplug_slot *slot)
562562
{
563563
struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);
564+
u32 prop32;
565+
int ret;
566+
567+
ret = pnv_php_enable(php_slot, true);
568+
if (ret)
569+
return ret;
570+
571+
/* (Re-)enable interrupt if the slot supports surprise hotplug */
572+
ret = of_property_read_u32(php_slot->dn, "ibm,slot-surprise-pluggable",
573+
&prop32);
574+
if (!ret && prop32)
575+
pnv_php_enable_irq(php_slot);
564576

565-
return pnv_php_enable(php_slot, true);
577+
return 0;
578+
}
579+
580+
/*
581+
* Disable any hotplug interrupts for all slots on the provided bus, as well as
582+
* all downstream slots in preparation for a hot unplug.
583+
*/
584+
static int pnv_php_disable_all_irqs(struct pci_bus *bus)
585+
{
586+
struct pci_bus *child_bus;
587+
struct pci_slot *slot;
588+
589+
/* First go down child buses */
590+
list_for_each_entry(child_bus, &bus->children, node)
591+
pnv_php_disable_all_irqs(child_bus);
592+
593+
/* Disable IRQs for all pnv_php slots on this bus */
594+
list_for_each_entry(slot, &bus->slots, list) {
595+
struct pnv_php_slot *php_slot = to_pnv_php_slot(slot->hotplug);
596+
597+
pnv_php_disable_irq(php_slot, false, true);
598+
}
599+
600+
return 0;
601+
}
602+
603+
/*
604+
* Disable any hotplug interrupts for all downstream slots on the provided
605+
* bus in preparation for a hot unplug.
606+
*/
607+
static int pnv_php_disable_all_downstream_irqs(struct pci_bus *bus)
608+
{
609+
struct pci_bus *child_bus;
610+
611+
/* Go down child buses, recursively deactivating their IRQs */
612+
list_for_each_entry(child_bus, &bus->children, node)
613+
pnv_php_disable_all_irqs(child_bus);
614+
615+
return 0;
566616
}
567617

568618
static int pnv_php_disable_slot(struct hotplug_slot *slot)
@@ -579,6 +629,13 @@ static int pnv_php_disable_slot(struct hotplug_slot *slot)
579629
php_slot->state != PNV_PHP_STATE_REGISTERED)
580630
return 0;
581631

632+
/*
633+
* Free all IRQ resources from all child slots before remove.
634+
* Note that we do not disable the root slot IRQ here as that
635+
* would also deactivate the slot hot (re)plug interrupt!
636+
*/
637+
pnv_php_disable_all_downstream_irqs(php_slot->bus);
638+
582639
/* Remove all devices behind the slot */
583640
pci_lock_rescan_remove();
584641
pci_hp_remove_devices(php_slot->bus);
@@ -647,6 +704,15 @@ static struct pnv_php_slot *pnv_php_alloc_slot(struct device_node *dn)
647704
return NULL;
648705
}
649706

707+
/* Allocate workqueue for this slot's interrupt handling */
708+
php_slot->wq = alloc_workqueue("pciehp-%s", 0, 0, php_slot->name);
709+
if (!php_slot->wq) {
710+
SLOT_WARN(php_slot, "Cannot alloc workqueue\n");
711+
kfree(php_slot->name);
712+
kfree(php_slot);
713+
return NULL;
714+
}
715+
650716
if (dn->child && PCI_DN(dn->child))
651717
php_slot->slot_no = PCI_SLOT(PCI_DN(dn->child)->devfn);
652718
else
@@ -843,14 +909,6 @@ static void pnv_php_init_irq(struct pnv_php_slot *php_slot, int irq)
843909
u16 sts, ctrl;
844910
int ret;
845911

846-
/* Allocate workqueue */
847-
php_slot->wq = alloc_workqueue("pciehp-%s", 0, 0, php_slot->name);
848-
if (!php_slot->wq) {
849-
SLOT_WARN(php_slot, "Cannot alloc workqueue\n");
850-
pnv_php_disable_irq(php_slot, true);
851-
return;
852-
}
853-
854912
/* Check PDC (Presence Detection Change) is broken or not */
855913
ret = of_property_read_u32(php_slot->dn, "ibm,slot-broken-pdc",
856914
&broken_pdc);
@@ -869,7 +927,7 @@ static void pnv_php_init_irq(struct pnv_php_slot *php_slot, int irq)
869927
ret = request_irq(irq, pnv_php_interrupt, IRQF_SHARED,
870928
php_slot->name, php_slot);
871929
if (ret) {
872-
pnv_php_disable_irq(php_slot, true);
930+
pnv_php_disable_irq(php_slot, true, true);
873931
SLOT_WARN(php_slot, "Error %d enabling IRQ %d\n", ret, irq);
874932
return;
875933
}

0 commit comments

Comments
 (0)