yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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