Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2019-05-17 06:38:43 +0200
committerJiri Slaby <jslaby@suse.cz>2019-05-17 06:38:54 +0200
commit1937f557e5411be22757216c21e88971d0031be9 (patch)
treeb35906fc382a559d19f9ef6979aef662a303b178
parent9d7b3e84ec255355e43c5f914b4fae7cf7e672cd (diff)
PCI: hv: Add pci_destroy_slot() in pci_devices_present_work(),
if necessary (bnc#1012628).
-rw-r--r--patches.kernel.org/5.1.3-042-PCI-hv-Add-pci_destroy_slot-in-pci_devices_pres.patch97
-rw-r--r--series.conf1
2 files changed, 98 insertions, 0 deletions
diff --git a/patches.kernel.org/5.1.3-042-PCI-hv-Add-pci_destroy_slot-in-pci_devices_pres.patch b/patches.kernel.org/5.1.3-042-PCI-hv-Add-pci_destroy_slot-in-pci_devices_pres.patch
new file mode 100644
index 0000000000..4a32eecff1
--- /dev/null
+++ b/patches.kernel.org/5.1.3-042-PCI-hv-Add-pci_destroy_slot-in-pci_devices_pres.patch
@@ -0,0 +1,97 @@
+From: Dexuan Cui <decui@microsoft.com>
+Date: Mon, 4 Mar 2019 21:34:49 +0000
+Subject: [PATCH] PCI: hv: Add pci_destroy_slot() in
+ pci_devices_present_work(), if necessary
+References: bnc#1012628
+Patch-mainline: 5.1.3
+Git-commit: 340d455699400f2c2c0f9b3f703ade3085cdb501
+
+commit 340d455699400f2c2c0f9b3f703ade3085cdb501 upstream.
+
+When we hot-remove a device, usually the host sends us a PCI_EJECT message,
+and a PCI_BUS_RELATIONS message with bus_rel->device_count == 0.
+
+When we execute the quick hot-add/hot-remove test, the host may not send
+us the PCI_EJECT message if the guest has not fully finished the
+initialization by sending the PCI_RESOURCES_ASSIGNED* message to the
+host, so it's potentially unsafe to only depend on the
+pci_destroy_slot() in hv_eject_device_work() because the code path
+
+create_root_hv_pci_bus()
+ -> hv_pci_assign_slots()
+
+is not called in this case. Note: in this case, the host still sends the
+guest a PCI_BUS_RELATIONS message with bus_rel->device_count == 0.
+
+In the quick hot-add/hot-remove test, we can have such a race before
+the code path
+
+pci_devices_present_work()
+ -> new_pcichild_device()
+
+adds the new device into the hbus->children list, we may have already
+received the PCI_EJECT message, and since the tasklet handler
+
+hv_pci_onchannelcallback()
+
+may fail to find the "hpdev" by calling
+
+get_pcichild_wslot(hbus, dev_message->wslot.slot)
+
+hv_pci_eject_device() is not called; Later, by continuing execution
+
+create_root_hv_pci_bus()
+ -> hv_pci_assign_slots()
+
+creates the slot and the PCI_BUS_RELATIONS message with
+bus_rel->device_count == 0 removes the device from hbus->children, and
+we end up being unable to remove the slot in
+
+hv_pci_remove()
+ -> hv_pci_remove_slots()
+
+Remove the slot in pci_devices_present_work() when the device
+is removed to address this race.
+
+pci_devices_present_work() and hv_eject_device_work() run in the
+singled-threaded hbus->wq, so there is not a double-remove issue for the
+slot.
+
+We cannot offload hv_pci_eject_device() from hv_pci_onchannelcallback()
+to the workqueue, because we need the hv_pci_onchannelcallback()
+synchronously call hv_pci_eject_device() to poll the channel
+ringbuffer to work around the "hangs in hv_compose_msi_msg()" issue
+fixed in commit de0aa7b2f97d ("PCI: hv: Fix 2 hang issues in
+hv_compose_msi_msg()")
+
+Fixes: a15f2c08c708 ("PCI: hv: support reporting serial number as slot information")
+Signed-off-by: Dexuan Cui <decui@microsoft.com>
+[lorenzo.pieralisi@arm.com: rewritten commit log]
+Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
+Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
+Reviewed-by: Michael Kelley <mikelley@microsoft.com>
+Cc: stable@vger.kernel.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Signed-off-by: Jiri Slaby <jslaby@suse.cz>
+---
+ drivers/pci/controller/pci-hyperv.c | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
+index b489412e3502..82acd6155adf 100644
+--- a/drivers/pci/controller/pci-hyperv.c
++++ b/drivers/pci/controller/pci-hyperv.c
+@@ -1776,6 +1776,10 @@ static void pci_devices_present_work(struct work_struct *work)
+ hpdev = list_first_entry(&removed, struct hv_pci_dev,
+ list_entry);
+ list_del(&hpdev->list_entry);
++
++ if (hpdev->pci_slot)
++ pci_destroy_slot(hpdev->pci_slot);
++
+ put_pcichild(hpdev);
+ }
+
+--
+2.21.0
+
diff --git a/series.conf b/series.conf
index 613da8bfee..50ca13fbe5 100644
--- a/series.conf
+++ b/series.conf
@@ -127,6 +127,7 @@
patches.kernel.org/5.1.3-039-virtio_ring-Fix-potential-mem-leak-in-virtqueue.patch
patches.kernel.org/5.1.3-040-PCI-hv-Fix-a-memory-leak-in-hv_eject_device_wor.patch
patches.kernel.org/5.1.3-041-PCI-hv-Add-hv_pci_remove_slots-when-we-unload-t.patch
+ patches.kernel.org/5.1.3-042-PCI-hv-Add-pci_destroy_slot-in-pci_devices_pres.patch
########################################################
# Build fixes that apply to the vanilla kernel too.