Use PCI bus lock to protect concurrent PCI device hotplug operations. Signed-off-by: Jiang Liu <jiang.liu@xxxxxxxxxx> Cc: Yinghai Lu <yinghai@xxxxxxxxxx> Cc: Yijing Wang <wangyijing@xxxxxxxxxx> Cc: linux-pci@xxxxxxxxxxxxxxx Cc: linux-kernel@xxxxxxxxxxxxxxx --- drivers/pci/hotplug/pciehp_pci.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c index aac7a40..ddc29ae 100644 --- a/drivers/pci/hotplug/pciehp_pci.c +++ b/drivers/pci/hotplug/pciehp_pci.c @@ -51,8 +51,14 @@ int pciehp_configure_device(struct slot *p_slot) return -EINVAL; } + if (pci_bus_lock(parent, PCI_BUS_STATE_STOPPING - 1, true) < 0) { + ctrl_err(ctrl, "Parent bus has been removed\n"); + return -EBUSY; + } + num = pci_scan_slot(parent, PCI_DEVFN(0, 0)); if (num == 0) { + pci_bus_unlock(parent, true); ctrl_err(ctrl, "No new device found\n"); return -ENODEV; } @@ -72,6 +78,7 @@ int pciehp_configure_device(struct slot *p_slot) } pci_bus_add_devices(parent); + pci_bus_unlock(parent, true); return 0; } @@ -88,6 +95,12 @@ int pciehp_unconfigure_device(struct slot *p_slot) ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:00\n", __func__, pci_domain_nr(parent), parent->number); + + if (pci_bus_lock(parent, PCI_BUS_STATE_REMOVED - 1, true) < 0) { + ctrl_dbg(ctrl, "Parent bus has been removed\n"); + return 0; + } + ret = pciehp_get_adapter_status(p_slot, &presence); if (ret) presence = 0; @@ -119,5 +132,7 @@ int pciehp_unconfigure_device(struct slot *p_slot) pci_dev_put(dev); } + pci_bus_unlock(parent, true); + return rc; } -- 1.8.1.2 -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html