Blame SOURCES/kvm-s390x-pci-Fix-primary-bus-number-for-PCI-bridges.patch

Pablo Greco e6a3ae
From 160715e23b00c660f0dfee3f1bdc021f9693d222 Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: Cornelia Huck <cohuck@redhat.com>
Pablo Greco e6a3ae
Date: Wed, 17 Apr 2019 13:57:36 +0100
Pablo Greco e6a3ae
Subject: [PATCH 19/24] s390x/pci: Fix primary bus number for PCI bridges
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: Cornelia Huck <cohuck@redhat.com>
Pablo Greco e6a3ae
Message-id: <20190417135741.25297-20-cohuck@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 85800
Pablo Greco e6a3ae
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH v2 19/24] s390x/pci: Fix primary bus number for PCI bridges
Pablo Greco e6a3ae
Bugzilla: 1699070
Pablo Greco e6a3ae
RH-Acked-by: David Hildenbrand <david@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Thomas Huth <thuth@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
From: David Hildenbrand <david@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
The primary bus number corresponds always to the bus number of the
Pablo Greco e6a3ae
bus the bridge is attached to.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Right now, if we have two bridges attached to the same bus (e.g. root
Pablo Greco e6a3ae
bus) this is however not the case. The first bridge will have primary
Pablo Greco e6a3ae
bus 0, the second bridge primary bus 1, which is wrong. Fix the assignment.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
While at it, drop setting the PCI_SUBORDINATE_BUS temporarily to 0xff.
Pablo Greco e6a3ae
Setting it temporarily to that value (as discussed e.g. in [1]), is
Pablo Greco e6a3ae
only relevant for a running system that probes the buses. The value is
Pablo Greco e6a3ae
effectively unused for us just doing a DFS.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Also add a comment why we have to reassign during every reset (which I
Pablo Greco e6a3ae
found to be surprising.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Please note that hotplugging of bridges is in general still broken, will
Pablo Greco e6a3ae
be fixed next.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
[1] http://www.science.unitn.it/~fiorella/guidelinux/tlk/node76.html
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Reviewed-by: Thomas Huth <thuth@redhat.com>
Pablo Greco e6a3ae
Signed-off-by: David Hildenbrand <david@redhat.com>
Pablo Greco e6a3ae
Message-Id: <20190130155733.32742-2-david@redhat.com>
Pablo Greco e6a3ae
Reviewed-by: Collin Walling <walling@linux.ibm.com>
Pablo Greco e6a3ae
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
Pablo Greco e6a3ae
(cherry picked from commit d30a7507edf1ca23d33dbf00b25f5e49a7808492)
Pablo Greco e6a3ae
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
Pablo Greco e6a3ae
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
 hw/s390x/s390-pci-bus.c | 13 ++++++++-----
Pablo Greco e6a3ae
 1 file changed, 8 insertions(+), 5 deletions(-)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
Pablo Greco e6a3ae
index 07a286a..309ad79 100644
Pablo Greco e6a3ae
--- a/hw/s390x/s390-pci-bus.c
Pablo Greco e6a3ae
+++ b/hw/s390x/s390-pci-bus.c
Pablo Greco e6a3ae
@@ -900,7 +900,8 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
Pablo Greco e6a3ae
         qbus_set_hotplug_handler(bus, DEVICE(s), errp);
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
         if (dev->hotplugged) {
Pablo Greco e6a3ae
-            pci_default_write_config(pdev, PCI_PRIMARY_BUS, s->bus_no, 1);
Pablo Greco e6a3ae
+            pci_default_write_config(pdev, PCI_PRIMARY_BUS,
Pablo Greco e6a3ae
+                                     pci_dev_bus_num(pdev), 1);
Pablo Greco e6a3ae
             s->bus_no += 1;
Pablo Greco e6a3ae
             pci_default_write_config(pdev, PCI_SECONDARY_BUS, s->bus_no, 1);
Pablo Greco e6a3ae
             do {
Pablo Greco e6a3ae
@@ -1053,8 +1054,6 @@ static void s390_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
Pablo Greco e6a3ae
                                       void *opaque)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
     S390pciState *s = opaque;
Pablo Greco e6a3ae
-    unsigned int primary = s->bus_no;
Pablo Greco e6a3ae
-    unsigned int subordinate = 0xff;
Pablo Greco e6a3ae
     PCIBus *sec_bus = NULL;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     if ((pci_default_read_config(pdev, PCI_HEADER_TYPE, 1) !=
Pablo Greco e6a3ae
@@ -1063,7 +1062,7 @@ static void s390_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     (s->bus_no)++;
Pablo Greco e6a3ae
-    pci_default_write_config(pdev, PCI_PRIMARY_BUS, primary, 1);
Pablo Greco e6a3ae
+    pci_default_write_config(pdev, PCI_PRIMARY_BUS, pci_dev_bus_num(pdev), 1);
Pablo Greco e6a3ae
     pci_default_write_config(pdev, PCI_SECONDARY_BUS, s->bus_no, 1);
Pablo Greco e6a3ae
     pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, s->bus_no, 1);
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
@@ -1072,7 +1071,7 @@ static void s390_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
Pablo Greco e6a3ae
         return;
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
-    pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, subordinate, 1);
Pablo Greco e6a3ae
+    /* Assign numbers to all child bridges. The last is the highest number. */
Pablo Greco e6a3ae
     pci_for_each_device(sec_bus, pci_bus_num(sec_bus),
Pablo Greco e6a3ae
                         s390_pci_enumerate_bridge, s);
Pablo Greco e6a3ae
     pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, s->bus_no, 1);
Pablo Greco e6a3ae
@@ -1083,6 +1082,10 @@ static void s390_pcihost_reset(DeviceState *dev)
Pablo Greco e6a3ae
     S390pciState *s = S390_PCI_HOST_BRIDGE(dev);
Pablo Greco e6a3ae
     PCIBus *bus = s->parent_obj.bus;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
+    /*
Pablo Greco e6a3ae
+     * When resetting a PCI bridge, the assigned numbers are set to 0. So
Pablo Greco e6a3ae
+     * on every system reset, we also have to reassign numbers.
Pablo Greco e6a3ae
+     */
Pablo Greco e6a3ae
     s->bus_no = 0;
Pablo Greco e6a3ae
     pci_for_each_device(bus, pci_bus_num(bus), s390_pci_enumerate_bridge, s);
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae