[RFC PATCH v2, part3 08/11] PCI, xen-pcifront: use PCI bus lock to protect PCI device hotplug

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use PCI bus lock to protect concurrent PCI device hotplug operations.

Signed-off-by: Jiang Liu <jiang.liu@xxxxxxxxxx>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
Cc: Jeremy Fitzhardinge <jeremy@xxxxxxxx>
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Cc: virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
Cc: linux-pci@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
 drivers/pci/xen-pcifront.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index 6aa2c0f..2b213b3 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -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,
-- 
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




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux