]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
PCI: hv: Do not wait forever on a device that has disappeared
authorDexuan Cui <decui@microsoft.com>
Wed, 23 May 2018 21:12:01 +0000 (21:12 +0000)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 5 Sep 2018 08:30:45 +0000 (10:30 +0200)
BugLink: http://bugs.launchpad.net/bugs/1789666
commit c3635da2a336441253c33298b87b3042db100725 upstream.

Before the guest finishes the device initialization, the device can be
removed anytime by the host, and after that the host won't respond to
the guest's request, so the guest should be prepared to handle this
case.

Add a polling mechanism to detect device presence.

Signed-off-by: Dexuan Cui <decui@microsoft.com>
[lorenzo.pieralisi@arm.com: edited commit log]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/pci/host/pci-hyperv.c

index 573f1b64adf4a9ec77e7c992420498e496295441..c2de1ea95ef492788b0aa8939650f5e3a6c2c2c9 100644 (file)
@@ -567,6 +567,26 @@ static void put_pcichild(struct hv_pci_dev *hv_pcidev,
 static void get_hvpcibus(struct hv_pcibus_device *hv_pcibus);
 static void put_hvpcibus(struct hv_pcibus_device *hv_pcibus);
 
+/*
+ * There is no good way to get notified from vmbus_onoffer_rescind(),
+ * so let's use polling here, since this is not a hot path.
+ */
+static int wait_for_response(struct hv_device *hdev,
+                            struct completion *comp)
+{
+       while (true) {
+               if (hdev->channel->rescind) {
+                       dev_warn_once(&hdev->device, "The device is gone.\n");
+                       return -ENODEV;
+               }
+
+               if (wait_for_completion_timeout(comp, HZ / 10))
+                       break;
+       }
+
+       return 0;
+}
+
 /**
  * devfn_to_wslot() - Convert from Linux PCI slot to Windows
  * @devfn:     The Linux representation of PCI slot
@@ -1579,7 +1599,8 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus,
        if (ret)
                goto error;
 
-       wait_for_completion(&comp_pkt.host_event);
+       if (wait_for_response(hbus->hdev, &comp_pkt.host_event))
+               goto error;
 
        hpdev->desc = *desc;
        refcount_set(&hpdev->refs, 1);
@@ -2082,15 +2103,16 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev)
                                sizeof(struct pci_version_request),
                                (unsigned long)pkt, VM_PKT_DATA_INBAND,
                                VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+               if (!ret)
+                       ret = wait_for_response(hdev, &comp_pkt.host_event);
+
                if (ret) {
                        dev_err(&hdev->device,
-                               "PCI Pass-through VSP failed sending version reqquest: %#x",
+                               "PCI Pass-through VSP failed to request version: %d",
                                ret);
                        goto exit;
                }
 
-               wait_for_completion(&comp_pkt.host_event);
-
                if (comp_pkt.completion_status >= 0) {
                        pci_protocol_version = pci_protocol_versions[i];
                        dev_info(&hdev->device,
@@ -2299,11 +2321,12 @@ static int hv_pci_enter_d0(struct hv_device *hdev)
        ret = vmbus_sendpacket(hdev->channel, d0_entry, sizeof(*d0_entry),
                               (unsigned long)pkt, VM_PKT_DATA_INBAND,
                               VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+       if (!ret)
+               ret = wait_for_response(hdev, &comp_pkt.host_event);
+
        if (ret)
                goto exit;
 
-       wait_for_completion(&comp_pkt.host_event);
-
        if (comp_pkt.completion_status < 0) {
                dev_err(&hdev->device,
                        "PCI Pass-through VSP failed D0 Entry with status %x\n",
@@ -2343,11 +2366,10 @@ static int hv_pci_query_relations(struct hv_device *hdev)
 
        ret = vmbus_sendpacket(hdev->channel, &message, sizeof(message),
                               0, VM_PKT_DATA_INBAND, 0);
-       if (ret)
-               return ret;
+       if (!ret)
+               ret = wait_for_response(hdev, &comp);
 
-       wait_for_completion(&comp);
-       return 0;
+       return ret;
 }
 
 /**
@@ -2417,11 +2439,11 @@ static int hv_send_resources_allocated(struct hv_device *hdev)
                                size_res, (unsigned long)pkt,
                                VM_PKT_DATA_INBAND,
                                VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+               if (!ret)
+                       ret = wait_for_response(hdev, &comp_pkt.host_event);
                if (ret)
                        break;
 
-               wait_for_completion(&comp_pkt.host_event);
-
                if (comp_pkt.completion_status < 0) {
                        ret = -EPROTO;
                        dev_err(&hdev->device,