Skip to contentSkip to conversation

spapr/pci: Fix primary bus number for PCI bridges

PATCH Applied David Hildenbrand 3 participants 5 messages Jan 23, 2019 – Jan 27, 2019

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spapr/pci: Fix primary bus number for PCI bridges

While looking at the s390x implementation, looks like spapr has a similar BUG when building the topology.

The primary bus number corresponds always to the bus number of the bus the bridge is attached to.

Right now, if we have two bridges attached to the same bus (e.g. root bus) this is however not the case. The first bridge will have primary bus 0, the second bridge primary bus 1, which is wrong. Fix the assignment.

While at it, drop setting the PCI_SUBORDINATE_BUS temporarily to 0xff. Setting it temporarily to that value (as discussed e.g. in [1]), is only relevant for a running system that probes the buses. The value is effectively unused for us just doing a DFS.

[1] http://www.science.unitn.it/~fiorella/guidelinux/tlk/node76.html

Note: Is hotplug of bridges supported? I can't find where the topology is fixed up when hotplugging a PCI bridge. (e.g. bus numbers assigned and PCI_SUBORDINATE_BUS of path to the root updated). But maybe we are excluding bridges or this is not necessary for some reason.

---
 hw/ppc/spapr_pci.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
hw/ppc/spapr_pci.c +1 -4
index b74f2632ec..5cdc98513d 100644
@@ -2030,8 +2030,6 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
                                            void *opaque)
 {
     unsigned int *bus_no = opaque;
-    unsigned int primary = *bus_no;
-    unsigned int subordinate = 0xff;
     PCIBus *sec_bus = NULL;
 
     if ((pci_default_read_config(pdev, PCI_HEADER_TYPE, 1) !=
@@ -2040,7 +2038,7 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
     }
 
     (*bus_no)++;
-    pci_default_write_config(pdev, PCI_PRIMARY_BUS, primary, 1);
+    pci_default_write_config(pdev, PCI_PRIMARY_BUS, pci_dev_bus_num(pdev), 1);
     pci_default_write_config(pdev, PCI_SECONDARY_BUS, *bus_no, 1);
     pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, *bus_no, 1);
 
@@ -2049,7 +2047,6 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
         return;
     }
 
-    pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, subordinate, 1);
     pci_for_each_device(sec_bus, pci_bus_num(sec_bus),
                         spapr_phb_pci_enumerate_bridge, bus_no);
     pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, *bus_no, 1);
Signature · 1 line
2.17.2
#1 lore raw
Quoted 15 lines · David Hildenbrand

While looking at the s390x implementation, looks like spapr has a similar BUG when building the topology.

The primary bus number corresponds always to the bus number of the bus the bridge is attached to.

Right now, if we have two bridges attached to the same bus (e.g. root bus) this is however not the case. The first bridge will have primary bus 0, the second bridge primary bus 1, which is wrong. Fix the assignment.

While at it, drop setting the PCI_SUBORDINATE_BUS temporarily to 0xff. Setting it temporarily to that value (as discussed e.g. in [1]), is only relevant for a running system that probes the buses. The value is effectively unused for us just doing a DFS.

Quoted 6 lines

[1] http://www.science.unitn.it/~fiorella/guidelinux/tlk/node76.html

Note: Is hotplug of bridges supported? I can't find where the topology is fixed up when hotplugging a PCI bridge. (e.g. bus numbers assigned and PCI_SUBORDINATE_BUS of path to the root updated). But maybe we are excluding bridges or this is not necessary for some reason.

This note can be dropped. I learned that this is under guest control. (which has to reserve bus numbers and rebuild the topology)

Quoted 37 lines
---
 hw/ppc/spapr_pci.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
hw/ppc/spapr_pci.c +1 -4
index b74f2632ec..5cdc98513d 100644
@@ -2030,8 +2030,6 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
                                            void *opaque)
 {
     unsigned int *bus_no = opaque;
-    unsigned int primary = *bus_no;
-    unsigned int subordinate = 0xff;
     PCIBus *sec_bus = NULL;
 
     if ((pci_default_read_config(pdev, PCI_HEADER_TYPE, 1) !=
@@ -2040,7 +2038,7 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
     }
 
     (*bus_no)++;
-    pci_default_write_config(pdev, PCI_PRIMARY_BUS, primary, 1);
+    pci_default_write_config(pdev, PCI_PRIMARY_BUS, pci_dev_bus_num(pdev), 1);
     pci_default_write_config(pdev, PCI_SECONDARY_BUS, *bus_no, 1);
     pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, *bus_no, 1);
 
@@ -2049,7 +2047,6 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
         return;
     }
 
-    pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, subordinate, 1);
     pci_for_each_device(sec_bus, pci_bus_num(sec_bus),
                         spapr_phb_pci_enumerate_bridge, bus_no);
     pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, *bus_no, 1);
Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by on v1 1/1
#2 lore raw
In reply to David Hildenbrand
Quoted 6 lines · David Hildenbrand

While looking at the s390x implementation, looks like spapr has a similar BUG when building the topology.

The primary bus number corresponds always to the bus number of the bus the bridge is attached to.

Quoted 8 lines

Right now, if we have two bridges attached to the same bus (e.g. root bus) this is however not the case. The first bridge will have primary bus 0, the second bridge primary bus 1, which is wrong. Fix the assignment.

While at it, drop setting the PCI_SUBORDINATE_BUS temporarily to 0xff. Setting it temporarily to that value (as discussed e.g. in [1]), is only relevant for a running system that probes the buses. The value is effectively unused for us just doing a DFS.

What is DFS?

Quoted 9 lines

[1] http://www.science.unitn.it/~fiorella/guidelinux/tlk/node76.html

Note: Is hotplug of bridges supported? I can't find where the topology is fixed up when hotplugging a PCI bridge. (e.g. bus numbers assigned and PCI_SUBORDINATE_BUS of path to the root updated). But maybe we are excluding bridges or this is not necessary for some reason.

Quoted 35 lines
---
 hw/ppc/spapr_pci.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
hw/ppc/spapr_pci.c +1 -4
index b74f2632ec..5cdc98513d 100644
@@ -2030,8 +2030,6 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
                                            void *opaque)
 {
     unsigned int *bus_no = opaque;
-    unsigned int primary = *bus_no;
-    unsigned int subordinate = 0xff;
     PCIBus *sec_bus = NULL;
 
     if ((pci_default_read_config(pdev, PCI_HEADER_TYPE, 1) !=
@@ -2040,7 +2038,7 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
     }
 
     (*bus_no)++;
-    pci_default_write_config(pdev, PCI_PRIMARY_BUS, primary, 1);
+    pci_default_write_config(pdev, PCI_PRIMARY_BUS, pci_dev_bus_num(pdev), 1);
     pci_default_write_config(pdev, PCI_SECONDARY_BUS, *bus_no, 1);
     pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, *bus_no, 1);
 
@@ -2049,7 +2047,6 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
         return;
     }
 
-    pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, subordinate, 1);
     pci_for_each_device(sec_bus, pci_bus_num(sec_bus),
                         spapr_phb_pci_enumerate_bridge, bus_no);
     pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, *bus_no, 1);
Signature · 1 line
Alexey
#3 lore raw
Quoted 13 lines · Alexey Kardashevskiy
Quoted 10 lines · David Hildenbrand

While looking at the s390x implementation, looks like spapr has a similar BUG when building the topology.

The primary bus number corresponds always to the bus number of the bus the bridge is attached to.

Right now, if we have two bridges attached to the same bus (e.g. root bus) this is however not the case. The first bridge will have primary bus 0, the second bridge primary bus 1, which is wrong. Fix the assignment.

Quoted 6 lines
Quoted 4 lines

While at it, drop setting the PCI_SUBORDINATE_BUS temporarily to 0xff. Setting it temporarily to that value (as discussed e.g. in [1]), is only relevant for a running system that probes the buses. The value is effectively unused for us just doing a DFS.

What is DFS?

Depth-first search :)

Quoted 9 lines
Quoted 9 lines

[1] http://www.science.unitn.it/~fiorella/guidelinux/tlk/node76.html

Note: Is hotplug of bridges supported? I can't find where the topology is fixed up when hotplugging a PCI bridge. (e.g. bus numbers assigned and PCI_SUBORDINATE_BUS of path to the root updated). But maybe we are excluding bridges or this is not necessary for some reason.

Quoted 6 lines
Quoted 1 line

Thanks!

Signature · 3 lines
Thanks,

David / dhildenb
Applied
#4 lore raw
In reply to Alexey Kardashevskiy
Quoted 28 lines · Alexey Kardashevskiy
Quoted 6 lines · David Hildenbrand

While looking at the s390x implementation, looks like spapr has a similar BUG when building the topology.

The primary bus number corresponds always to the bus number of the bus the bridge is attached to.

Quoted 8 lines

Right now, if we have two bridges attached to the same bus (e.g. root bus) this is however not the case. The first bridge will have primary bus 0, the second bridge primary bus 1, which is wrong. Fix the assignment.

While at it, drop setting the PCI_SUBORDINATE_BUS temporarily to 0xff. Setting it temporarily to that value (as discussed e.g. in [1]), is only relevant for a running system that probes the buses. The value is effectively unused for us just doing a DFS.

What is DFS?

Quoted 8 lines

[1] http://www.science.unitn.it/~fiorella/guidelinux/tlk/node76.html

Note: Is hotplug of bridges supported? I can't find where the topology is fixed up when hotplugging a PCI bridge. (e.g. bus numbers assigned and PCI_SUBORDINATE_BUS of path to the root updated). But maybe we are excluding bridges or this is not necessary for some reason.

Quoted 4 lines
Quoted 1 line

Applied, thanks.

Quoted 38 lines
Quoted 37 lines

---
 hw/ppc/spapr_pci.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
hw/ppc/spapr_pci.c +1 -4
index b74f2632ec..5cdc98513d 100644
@@ -2030,8 +2030,6 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
                                            void *opaque)
 {
     unsigned int *bus_no = opaque;
-    unsigned int primary = *bus_no;
-    unsigned int subordinate = 0xff;
     PCIBus *sec_bus = NULL;
 
     if ((pci_default_read_config(pdev, PCI_HEADER_TYPE, 1) !=
@@ -2040,7 +2038,7 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
     }
 
     (*bus_no)++;
-    pci_default_write_config(pdev, PCI_PRIMARY_BUS, primary, 1);
+    pci_default_write_config(pdev, PCI_PRIMARY_BUS, pci_dev_bus_num(pdev), 1);
     pci_default_write_config(pdev, PCI_SECONDARY_BUS, *bus_no, 1);
     pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, *bus_no, 1);
 
@@ -2049,7 +2047,6 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
         return;
     }
 
-    pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, subordinate, 1);
     pci_for_each_device(sec_bus, pci_bus_num(sec_bus),
                         spapr_phb_pci_enumerate_bridge, bus_no);
     pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, *bus_no, 1);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson