yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-s390x-pci-Move-some-hotplug-checks-to-the-pre_plug-h.patch

b38b0f
From 2bbc164594e03b4ab2b436433c7757990801ef49 Mon Sep 17 00:00:00 2001
b38b0f
From: Cornelia Huck <cohuck@redhat.com>
b38b0f
Date: Wed, 17 Apr 2019 13:57:32 +0100
b38b0f
Subject: [PATCH 15/24] s390x/pci: Move some hotplug checks to the pre_plug
b38b0f
 handler
b38b0f
b38b0f
RH-Author: Cornelia Huck <cohuck@redhat.com>
b38b0f
Message-id: <20190417135741.25297-16-cohuck@redhat.com>
b38b0f
Patchwork-id: 85797
b38b0f
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH v2 15/24] s390x/pci: Move some hotplug checks to the pre_plug handler
b38b0f
Bugzilla: 1699070
b38b0f
RH-Acked-by: David Hildenbrand <david@redhat.com>
b38b0f
RH-Acked-by: Thomas Huth <thuth@redhat.com>
b38b0f
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
b38b0f
b38b0f
From: David Hildenbrand <david@redhat.com>
b38b0f
b38b0f
Let's move most of the checks to the new pre_plug handler. As a PCI
b38b0f
bridge is just a PCI device, we can simplify the code.
b38b0f
b38b0f
Notes: We cannot yet move the MSIX check or device ID creation +
b38b0f
zPCI device creation to the pre_plug handler as both parts are not
b38b0f
fixed before actual device realization (and therefore after pre_plug and
b38b0f
before plug). Once that part is factored out, we can move these parts to
b38b0f
the pre_plug handler, too and therefore remove all possible errors from
b38b0f
the plug handler.
b38b0f
b38b0f
Reviewed-by: Collin Walling <walling@linux.ibm.com>
b38b0f
Signed-off-by: David Hildenbrand <david@redhat.com>
b38b0f
Message-Id: <20190114103110.10909-3-david@redhat.com>
b38b0f
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
b38b0f
(cherry picked from commit 6069bcdeaceebb91f43bc4762e3f63eee48cd390)
b38b0f
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
b38b0f
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
b38b0f
---
b38b0f
 hw/s390x/s390-pci-bus.c | 41 +++++++++++++++++++++++++----------------
b38b0f
 1 file changed, 25 insertions(+), 16 deletions(-)
b38b0f
b38b0f
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
b38b0f
index f1b3334..e3f576a 100644
b38b0f
--- a/hw/s390x/s390-pci-bus.c
b38b0f
+++ b/hw/s390x/s390-pci-bus.c
b38b0f
@@ -822,11 +822,31 @@ static bool s390_pci_alloc_idx(S390pciState *s, S390PCIBusDevice *pbdev)
b38b0f
     }
b38b0f
 
b38b0f
     pbdev->idx = idx;
b38b0f
-    s->next_idx = (idx + 1) & FH_MASK_INDEX;
b38b0f
-
b38b0f
     return true;
b38b0f
 }
b38b0f
 
b38b0f
+static void s390_pcihost_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
b38b0f
+                                   Error **errp)
b38b0f
+{
b38b0f
+    S390pciState *s = S390_PCI_HOST_BRIDGE(hotplug_dev);
b38b0f
+
b38b0f
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
b38b0f
+        PCIDevice *pdev = PCI_DEVICE(dev);
b38b0f
+
b38b0f
+        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
b38b0f
+            error_setg(errp, "multifunction not supported in s390");
b38b0f
+            return;
b38b0f
+        }
b38b0f
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
b38b0f
+        S390PCIBusDevice *pbdev = S390_PCI_DEVICE(dev);
b38b0f
+
b38b0f
+        if (!s390_pci_alloc_idx(s, pbdev)) {
b38b0f
+            error_setg(errp, "no slot for plugging zpci device");
b38b0f
+            return;
b38b0f
+        }
b38b0f
+    }
b38b0f
+}
b38b0f
+
b38b0f
 static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
b38b0f
                               Error **errp)
b38b0f
 {
b38b0f
@@ -839,11 +859,6 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
b38b0f
         PCIBridge *pb = PCI_BRIDGE(dev);
b38b0f
         PCIDevice *pdev = PCI_DEVICE(dev);
b38b0f
 
b38b0f
-        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
b38b0f
-            error_setg(errp, "multifunction not supported in s390");
b38b0f
-            return;
b38b0f
-        }
b38b0f
-
b38b0f
         pci_bridge_map_irq(pb, dev->id, s390_pci_map_irq);
b38b0f
         pci_setup_iommu(&pb->sec_bus, s390_pci_dma_iommu, s);
b38b0f
 
b38b0f
@@ -863,11 +878,6 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
b38b0f
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
b38b0f
         pdev = PCI_DEVICE(dev);
b38b0f
 
b38b0f
-        if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
b38b0f
-            error_setg(errp, "multifunction not supported in s390");
b38b0f
-            return;
b38b0f
-        }
b38b0f
-
b38b0f
         if (!dev->id) {
b38b0f
             /* In the case the PCI device does not define an id */
b38b0f
             /* we generate one based on the PCI address         */
b38b0f
@@ -909,10 +919,8 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
b38b0f
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
b38b0f
         pbdev = S390_PCI_DEVICE(dev);
b38b0f
 
b38b0f
-        if (!s390_pci_alloc_idx(s, pbdev)) {
b38b0f
-            error_setg(errp, "no slot for plugging zpci device");
b38b0f
-            return;
b38b0f
-        }
b38b0f
+        /* the allocated idx is actually getting used */
b38b0f
+        s->next_idx = (pbdev->idx + 1) & FH_MASK_INDEX;
b38b0f
         pbdev->fh = pbdev->idx;
b38b0f
         QTAILQ_INSERT_TAIL(&s->zpci_devs, pbdev, link);
b38b0f
         g_hash_table_insert(s->zpci_table, &pbdev->idx, pbdev);
b38b0f
@@ -1052,6 +1060,7 @@ static void s390_pcihost_class_init(ObjectClass *klass, void *data)
b38b0f
 
b38b0f
     dc->reset = s390_pcihost_reset;
b38b0f
     dc->realize = s390_pcihost_realize;
b38b0f
+    hc->pre_plug = s390_pcihost_pre_plug;
b38b0f
     hc->plug = s390_pcihost_plug;
b38b0f
     hc->unplug = s390_pcihost_unplug;
b38b0f
     msi_nonbroken = true;
b38b0f
-- 
b38b0f
1.8.3.1
b38b0f