thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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