diff mbox series

spapr_pci: Fix DRC owner in spapr_dt_pci_bus()

Message ID 156084737348.512412.3552825999605902691.stgit@bahia.lan (mailing list archive)
State New, archived
Headers show
Series spapr_pci: Fix DRC owner in spapr_dt_pci_bus() | expand

Commit Message

Greg Kurz June 18, 2019, 8:42 a.m. UTC
spapr_dt_drc() scans the aliases of all DRConnector objects and filters
the ones that it will use to generate OF properties according to their
owner and type.

Passing bus->parent_dev _works_ if bus belongs to a PCI bridge, but it is
NULL if it is the PHB's root bus. This causes all allocated PCI DRCs to
be associated to all PHBs (visible in their "ibm,drc-types" properties).
As a consequence, hot unplugging a PHB results in PCI devices from the
other PHBs to be unplugged as well, and likely confuses the guest.

Use the same logic as in add_drcs() to ensure the correct owner is passed
to spapr_dt_drc().

Fixes: 14e714900f6b "spapr: Allow hot plug/unplug of PCI bridges and devices under PCI bridges"
Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/ppc/spapr_pci.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

David Gibson June 18, 2019, 8:46 a.m. UTC | #1
On Tue, Jun 18, 2019 at 10:42:53AM +0200, Greg Kurz wrote:
> spapr_dt_drc() scans the aliases of all DRConnector objects and filters
> the ones that it will use to generate OF properties according to their
> owner and type.
> 
> Passing bus->parent_dev _works_ if bus belongs to a PCI bridge, but it is
> NULL if it is the PHB's root bus. This causes all allocated PCI DRCs to
> be associated to all PHBs (visible in their "ibm,drc-types" properties).
> As a consequence, hot unplugging a PHB results in PCI devices from the
> other PHBs to be unplugged as well, and likely confuses the guest.
> 
> Use the same logic as in add_drcs() to ensure the correct owner is passed
> to spapr_dt_drc().
> 
> Fixes: 14e714900f6b "spapr: Allow hot plug/unplug of PCI bridges and devices under PCI bridges"
> Signed-off-by: Greg Kurz <groug@kaod.org>

Applied, thanks.
> ---
>  hw/ppc/spapr_pci.c |    9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index fbeb1c90ee6c..2dca1e57f36c 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -1343,6 +1343,7 @@ static void spapr_dt_pci_device_cb(PCIBus *bus, PCIDevice *pdev,
>  static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus,
>                                 void *fdt, int offset)
>  {
> +    Object *owner;
>      PciWalkFdt cbinfo = {
>          .fdt = fdt,
>          .offset = offset,
> @@ -1363,7 +1364,13 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus,
>          return cbinfo.err;
>      }
>  
> -    ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev),
> +    if (pci_bus_is_root(bus)) {
> +        owner = OBJECT(sphb);
> +    } else {
> +        owner = OBJECT(pci_bridge_get_device(bus));
> +    }
> +
> +    ret = spapr_dt_drc(fdt, offset, owner,
>                         SPAPR_DR_CONNECTOR_TYPE_PCI);
>      if (ret) {
>          return ret;
>
diff mbox series

Patch

diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index fbeb1c90ee6c..2dca1e57f36c 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -1343,6 +1343,7 @@  static void spapr_dt_pci_device_cb(PCIBus *bus, PCIDevice *pdev,
 static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus,
                                void *fdt, int offset)
 {
+    Object *owner;
     PciWalkFdt cbinfo = {
         .fdt = fdt,
         .offset = offset,
@@ -1363,7 +1364,13 @@  static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus,
         return cbinfo.err;
     }
 
-    ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev),
+    if (pci_bus_is_root(bus)) {
+        owner = OBJECT(sphb);
+    } else {
+        owner = OBJECT(pci_bridge_get_device(bus));
+    }
+
+    ret = spapr_dt_drc(fdt, offset, owner,
                        SPAPR_DR_CONNECTOR_TYPE_PCI);
     if (ret) {
         return ret;