diff options
author | Long Li <longli@microsoft.com> | 2017-03-23 17:58:32 -0400 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2017-03-24 10:54:56 -0400 |
commit | 414428c5da1c71986727c2fa5cdf1ed071e398d7 (patch) | |
tree | 9d08139b53727f300a80b592bfae5e931634b6f8 | |
parent | d3a78d8bf759d8848339dcc367c4c1678b57a08b (diff) |
PCI: hv: Lock PCI bus on device eject
A PCI_EJECT message can arrive at the same time we are calling
pci_scan_child_bus() in the workqueue for the previous PCI_BUS_RELATIONS
message or in create_root_hv_pci_bus(). In this case we could potentially
modify the bus from multiple places.
Properly lock the bus access.
Thanks Dexuan Cui <decui@microsoft.com> for pointing out the race condition
in create_root_hv_pci_bus().
Reported-by: Xiaofeng Wang <xiaofwan@redhat.com>
Signed-off-by: Long Li <longli@microsoft.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: K. Y. Srinivasan <kys@microsoft.com>
-rw-r--r-- | drivers/pci/host/pci-hyperv.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 39fafda4deff..a1b3c1957d43 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c | |||
@@ -1209,9 +1209,11 @@ static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus) | |||
1209 | hbus->pci_bus->msi = &hbus->msi_chip; | 1209 | hbus->pci_bus->msi = &hbus->msi_chip; |
1210 | hbus->pci_bus->msi->dev = &hbus->hdev->device; | 1210 | hbus->pci_bus->msi->dev = &hbus->hdev->device; |
1211 | 1211 | ||
1212 | pci_lock_rescan_remove(); | ||
1212 | pci_scan_child_bus(hbus->pci_bus); | 1213 | pci_scan_child_bus(hbus->pci_bus); |
1213 | pci_bus_assign_resources(hbus->pci_bus); | 1214 | pci_bus_assign_resources(hbus->pci_bus); |
1214 | pci_bus_add_devices(hbus->pci_bus); | 1215 | pci_bus_add_devices(hbus->pci_bus); |
1216 | pci_unlock_rescan_remove(); | ||
1215 | hbus->state = hv_pcibus_installed; | 1217 | hbus->state = hv_pcibus_installed; |
1216 | return 0; | 1218 | return 0; |
1217 | } | 1219 | } |
@@ -1612,8 +1614,10 @@ static void hv_eject_device_work(struct work_struct *work) | |||
1612 | pdev = pci_get_domain_bus_and_slot(hpdev->hbus->sysdata.domain, 0, | 1614 | pdev = pci_get_domain_bus_and_slot(hpdev->hbus->sysdata.domain, 0, |
1613 | wslot); | 1615 | wslot); |
1614 | if (pdev) { | 1616 | if (pdev) { |
1617 | pci_lock_rescan_remove(); | ||
1615 | pci_stop_and_remove_bus_device(pdev); | 1618 | pci_stop_and_remove_bus_device(pdev); |
1616 | pci_dev_put(pdev); | 1619 | pci_dev_put(pdev); |
1620 | pci_unlock_rescan_remove(); | ||
1617 | } | 1621 | } |
1618 | 1622 | ||
1619 | spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags); | 1623 | spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags); |