Blame SOURCES/kvm-hw-pci-pcie-Move-hot-plug-capability-check-to-pre_pl.patch

902636
From 035f8aaabf2c31cd6206bff6da23a12fee69d1b7 Mon Sep 17 00:00:00 2001
902636
From: Julia Suvorova <jusual@redhat.com>
902636
Date: Tue, 16 Jun 2020 12:25:36 -0400
902636
Subject: [PATCH 1/3] hw/pci/pcie: Move hot plug capability check to pre_plug
902636
 callback
902636
902636
RH-Author: Julia Suvorova <jusual@redhat.com>
902636
Message-id: <20200616122536.1027685-1-jusual@redhat.com>
902636
Patchwork-id: 97548
902636
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 1/1] hw/pci/pcie: Move hot plug capability check to pre_plug callback
902636
Bugzilla: 1820531
902636
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
902636
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
902636
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
902636
902636
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1820531
902636
BRANCH: rhel-av-8.2.1
902636
UPSTREAM: merged
902636
BREW: 29422092
902636
902636
Check for hot plug capability earlier to avoid removing devices attached
902636
during the initialization process.
902636
902636
Run qemu with an unattached drive:
902636
  -drive file=$FILE,if=none,id=drive0 \
902636
  -device pcie-root-port,id=rp0,slot=3,bus=pcie.0,hotplug=off
902636
Hotplug a block device:
902636
  device_add virtio-blk-pci,id=blk0,drive=drive0,bus=rp0
902636
If hotplug fails on plug_cb, drive0 will be deleted.
902636
902636
Fixes: 0501e1aa1d32a6 ("hw/pci/pcie: Forbid hot-plug if it's disabled on the slot")
902636
902636
Acked-by: Igor Mammedov <imammedo@redhat.com>
902636
Signed-off-by: Julia Suvorova <jusual@redhat.com>
902636
Message-Id: <20200604125947.881210-1-jusual@redhat.com>
902636
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
902636
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
902636
(cherry picked from commit 0dabc0f6544f2c0310546f6d6cf3b68979580a9c)
902636
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
902636
---
902636
 hw/pci/pcie.c | 19 +++++++++++--------
902636
 1 file changed, 11 insertions(+), 8 deletions(-)
902636
902636
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
902636
index abc99b6eff..1386dd228c 100644
902636
--- a/hw/pci/pcie.c
902636
+++ b/hw/pci/pcie.c
902636
@@ -407,6 +407,17 @@ static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev,
902636
 void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
902636
                                Error **errp)
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
+
902636
+    /* Check if hot-plug is disabled on the slot */
902636
+    if (dev->hotplugged && (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
     pcie_cap_slot_plug_common(PCI_DEVICE(hotplug_dev), dev, errp);
902636
 }
902636
 
902636
@@ -415,7 +426,6 @@ 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
@@ -431,13 +441,6 @@ 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
-- 
902636
2.27.0
902636