[PATCH 2/4] PCI: hv: Delete the device earlier from hbus->children for hot-remove

Tim Gardner tim.gardner at canonical.com
Tue Mar 7 17:30:46 UTC 2017

From: Dexuan Cui <decui at microsoft.com>

BugLink: http://bugs.launchpad.net/bugs/1670518

After we send a PCI_EJECTION_COMPLETE message to the host, the host will
immediately send us a PCI_BUS_RELATIONS message with
relations->device_count == 0, so pci_devices_present_work(), running on
another thread, can find the being-ejected device, mark the
hpdev->reported_missing to true, and run list_move_tail()/list_del() for
the device -- this races hv_eject_device_work() -> list_del().

Move the list_del() in hv_eject_device_work() to an earlier place, i.e.,
before we send PCI_EJECTION_COMPLETE, so later the
pci_devices_present_work() can't see the device.

Signed-off-by: Dexuan Cui <decui at microsoft.com>
Signed-off-by: Bjorn Helgaas <bhelgaas at google.com>
Reviewed-by: Jake Oshins <jakeo at microsoft.com>
Acked-by: K. Y. Srinivasan <kys at microsoft.com>
CC: Haiyang Zhang <haiyangz at microsoft.com>
CC: Vitaly Kuznetsov <vkuznets at redhat.com>
(cherry picked from commit e74d2ebdda33b3bdd1826b5b92e9aa45bdf92bb3)
Signed-off-by: Tim Gardner <tim.gardner at canonical.com>
 drivers/pci/host/pci-hyperv.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
index c968330..87ecdf0 100644
--- a/drivers/pci/host/pci-hyperv.c
+++ b/drivers/pci/host/pci-hyperv.c
@@ -1582,6 +1582,10 @@ static void hv_eject_device_work(struct work_struct *work)
+	spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags);
+	list_del(&hpdev->list_entry);
+	spin_unlock_irqrestore(&hpdev->hbus->device_list_lock, flags);
 	memset(&ctxt, 0, sizeof(ctxt));
 	ejct_pkt = (struct pci_eject_response *)&ctxt.pkt.message;
 	ejct_pkt->message_type.type = PCI_EJECTION_COMPLETE;
@@ -1590,10 +1594,6 @@ static void hv_eject_device_work(struct work_struct *work)
 			 sizeof(*ejct_pkt), (unsigned long)&ctxt.pkt,
-	spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags);
-	list_del(&hpdev->list_entry);
-	spin_unlock_irqrestore(&hpdev->hbus->device_list_lock, flags);
 	put_pcichild(hpdev, hv_pcidev_ref_childlist);
 	put_pcichild(hpdev, hv_pcidev_ref_pnp);

More information about the kernel-team mailing list