Blame SOURCES/kvm-hw-pci-pcie-Forbid-hot-plug-if-it-s-disabled-on-the-.patch

ddf19c
From fe8a9f211fba3588d60507b3d2f48c41d8ee3c79 Mon Sep 17 00:00:00 2001
ddf19c
From: Julia Suvorova <jusual@redhat.com>
ddf19c
Date: Mon, 4 May 2020 21:25:04 +0100
ddf19c
Subject: [PATCH 1/9] hw/pci/pcie: Forbid hot-plug if it's disabled on the slot
ddf19c
ddf19c
RH-Author: Julia Suvorova <jusual@redhat.com>
ddf19c
Message-id: <20200504212505.15977-2-jusual@redhat.com>
ddf19c
Patchwork-id: 96257
ddf19c
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 1/2] hw/pci/pcie: Forbid hot-plug if it's disabled on the slot
ddf19c
Bugzilla: 1820531
ddf19c
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
ddf19c
RH-Acked-by: Peter Xu <peterx@redhat.com>
ddf19c
ddf19c
Raise an error when trying to hot-plug/unplug a device through QMP to a device
ddf19c
with disabled hot-plug capability. This makes the device behaviour more
ddf19c
consistent and provides an explanation of the failure in the case of
ddf19c
asynchronous unplug.
ddf19c
ddf19c
Signed-off-by: Julia Suvorova <jusual@redhat.com>
ddf19c
Message-Id: <20200427182440.92433-2-jusual@redhat.com>
ddf19c
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
Reviewed-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
ddf19c
(cherry picked from commit 0501e1aa1d32a6e02dd06a79bba97fbe9d557cb5)
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 hw/pci/pcie.c | 19 +++++++++++++++++++
ddf19c
 1 file changed, 19 insertions(+)
ddf19c
ddf19c
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
ddf19c
index 0eb3a2a..6b48d04 100644
ddf19c
--- a/hw/pci/pcie.c
ddf19c
+++ b/hw/pci/pcie.c
ddf19c
@@ -415,6 +415,7 @@ void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
ddf19c
 {
ddf19c
     PCIDevice *hotplug_pdev = PCI_DEVICE(hotplug_dev);
ddf19c
     uint8_t *exp_cap = hotplug_pdev->config + hotplug_pdev->exp.exp_cap;
ddf19c
+    uint32_t sltcap = pci_get_word(exp_cap + PCI_EXP_SLTCAP);
ddf19c
     PCIDevice *pci_dev = PCI_DEVICE(dev);
ddf19c
 
ddf19c
     /* Don't send event when device is enabled during qemu machine creation:
ddf19c
@@ -430,6 +431,13 @@ void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
ddf19c
         return;
ddf19c
     }
ddf19c
 
ddf19c
+    /* Check if hot-plug is disabled on the slot */
ddf19c
+    if ((sltcap & PCI_EXP_SLTCAP_HPC) == 0) {
ddf19c
+        error_setg(errp, "Hot-plug failed: unsupported by the port device '%s'",
ddf19c
+                         DEVICE(hotplug_pdev)->id);
ddf19c
+        return;
ddf19c
+    }
ddf19c
+
ddf19c
     /* To enable multifunction hot-plug, we just ensure the function
ddf19c
      * 0 added last. When function 0 is added, we set the sltsta and
ddf19c
      * inform OS via event notification.
ddf19c
@@ -470,6 +478,17 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev,
ddf19c
     Error *local_err = NULL;
ddf19c
     PCIDevice *pci_dev = PCI_DEVICE(dev);
ddf19c
     PCIBus *bus = pci_get_bus(pci_dev);
ddf19c
+    PCIDevice *hotplug_pdev = PCI_DEVICE(hotplug_dev);
ddf19c
+    uint8_t *exp_cap = hotplug_pdev->config + hotplug_pdev->exp.exp_cap;
ddf19c
+    uint32_t sltcap = pci_get_word(exp_cap + PCI_EXP_SLTCAP);
ddf19c
+
ddf19c
+    /* Check if hot-unplug is disabled on the slot */
ddf19c
+    if ((sltcap & PCI_EXP_SLTCAP_HPC) == 0) {
ddf19c
+        error_setg(errp, "Hot-unplug failed: "
ddf19c
+                         "unsupported by the port device '%s'",
ddf19c
+                         DEVICE(hotplug_pdev)->id);
ddf19c
+        return;
ddf19c
+    }
ddf19c
 
ddf19c
     pcie_cap_slot_plug_common(PCI_DEVICE(hotplug_dev), dev, &local_err);
ddf19c
     if (local_err) {
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c