@@ -505,6 +505,7 @@ static int pcifront_scan_root(struct pcifront_device *pdev,
/* Create SysFS and notify udev of the devices. Aka: "going live" */
pci_bus_add_devices(b);
+ pci_bus_unlock(b, true);
return err;
@@ -538,6 +539,11 @@ static int pcifront_rescan_root(struct pcifront_device *pdev,
/* If the bus is unknown, create it. */
return pcifront_scan_root(pdev, domain, bus);
+ if (pci_bus_lock(b, PCI_BUS_STATE_STOPPING - 1, true) < 0) {
+ err = -EBUSY;
+ goto out;
+ }
+
err = pcifront_scan_bus(pdev, domain, bus, b);
/* Claim resources before going "live" with our devices */
@@ -545,6 +551,9 @@ static int pcifront_rescan_root(struct pcifront_device *pdev,
/* Create SysFS and notify udev of the devices. Aka: "going live" */
pci_bus_add_devices(b);
+ pci_bus_unlock(b, true);
+
+out:
pci_bus_put(b);
return err;
@@ -559,8 +568,11 @@ static void pcifront_free_roots(struct pcifront_device *pdev)
for_each_pci_root_bus(bus) {
sd = bus->sysdata;
- if (sd->pdev == pdev) {
+ if (sd->pdev != pdev)
+ continue;
+ if (pci_bus_lock(bus, PCI_BUS_STATE_REMOVED - 1, true) == 0) {
pci_stop_root_bus(bus);
+ /* it also unlocks PCI buses */
pci_remove_root_bus(bus);
}
}
@@ -1042,7 +1054,7 @@ static int pcifront_detach_devices(struct pcifront_device *pdev)
domain, bus, slot, func);
continue;
}
- pci_stop_and_remove_bus_device(pci_dev);
+ pci_stop_and_remove_device(pci_dev);
pci_dev_put(pci_dev);
dev_dbg(&pdev->xdev->dev,
Use PCI bus lock to protect concurrent PCI device hotplug operations. Signed-off-by: Jiang Liu <jiang.liu@huawei.com> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Jeremy Fitzhardinge <jeremy@goop.org> Cc: xen-devel@lists.xensource.com Cc: virtualization@lists.linux-foundation.org Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/pci/xen-pcifront.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)