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

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