Skip to content

Commit 76888d1

Browse files
dcuigregkh
authored andcommitted
PCI: hv: Add hv_pci_remove_slots() when we unload the driver
commit 15becc2 upstream. When we unload the pci-hyperv host controller driver, the host does not send us a PCI_EJECT message. In this case we also need to make sure the sysfs PCI slot directory is removed, otherwise a command on a slot file eg: "cat /sys/bus/pci/slots/2/address" will trigger a "BUG: unable to handle kernel paging request" and, if we unload/reload the driver several times we would end up with stale slot entries in PCI slot directories in /sys/bus/pci/slots/ root@localhost:~# ls -rtl /sys/bus/pci/slots/ total 0 drwxr-xr-x 2 root root 0 Feb 7 10:49 2 drwxr-xr-x 2 root root 0 Feb 7 10:49 2-1 drwxr-xr-x 2 root root 0 Feb 7 10:51 2-2 Add the missing code to remove the PCI slot and fix the current behaviour. Fixes: a15f2c0 ("PCI: hv: support reporting serial number as slot information") Signed-off-by: Dexuan Cui <decui@microsoft.com> [lorenzo.pieralisi@arm.com: reformatted the log] Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Reviewed-by: Stephen Hemminger <sthemmin@microsoft.com> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a47e005 commit 76888d1

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

drivers/pci/controller/pci-hyperv.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,21 @@ static void hv_pci_assign_slots(struct hv_pcibus_device *hbus)
14911491
}
14921492
}
14931493

1494+
/*
1495+
* Remove entries in sysfs pci slot directory.
1496+
*/
1497+
static void hv_pci_remove_slots(struct hv_pcibus_device *hbus)
1498+
{
1499+
struct hv_pci_dev *hpdev;
1500+
1501+
list_for_each_entry(hpdev, &hbus->children, list_entry) {
1502+
if (!hpdev->pci_slot)
1503+
continue;
1504+
pci_destroy_slot(hpdev->pci_slot);
1505+
hpdev->pci_slot = NULL;
1506+
}
1507+
}
1508+
14941509
/**
14951510
* create_root_hv_pci_bus() - Expose a new root PCI bus
14961511
* @hbus: Root PCI bus, as understood by this driver
@@ -2685,6 +2700,7 @@ static int hv_pci_remove(struct hv_device *hdev)
26852700
pci_lock_rescan_remove();
26862701
pci_stop_root_bus(hbus->pci_bus);
26872702
pci_remove_root_bus(hbus->pci_bus);
2703+
hv_pci_remove_slots(hbus);
26882704
pci_unlock_rescan_remove();
26892705
hbus->state = hv_pcibus_removed;
26902706
}

0 commit comments

Comments
 (0)