Skip to contentSkip to conversation

hw/pci-host: Allow extended config space access for Designware PCIe host

PATCH In review Jason Chien 4 participants 10 messages Aug 9, 2023 – Aug 12, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/pci-host: Allow extended config space access for Designware PCIe host

In pcie_bus_realize(), a root bus is realized as a PCIe bus and a non-root bus is realized as a PCIe bus if its parent bus is a PCIe bus. However, the child bus "dw-pcie" is realized before the parent bus "pcie" which is the root PCIe bus. Thus, the extended configuration space is not accessible on "dw-pcie". The issue can be resolved by adding the PCI_BUS_EXTENDED_CONFIG_SPACE flag to "pcie" before "dw-pcie" is realized.

---
 hw/pci-host/designware.c | 1 +
 1 file changed, 1 insertion(+)
hw/pci-host/designware.c +1 -0
index 9e183caa48..388d252ee2 100644
@@ -694,6 +694,7 @@ static void designware_pcie_host_realize(DeviceState *dev, Error **errp)
                                      &s->pci.io,
                                      0, 4,
                                      TYPE_PCIE_BUS);
+    pci->bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
 
     memory_region_init(&s->pci.address_space_root,
                        OBJECT(s),
Signature · 1 line
2.17.1
#1 lore raw
Quoted 8 lines · Jason Chien

In pcie_bus_realize(), a root bus is realized as a PCIe bus and a non-root bus is realized as a PCIe bus if its parent bus is a PCIe bus. However, the child bus "dw-pcie" is realized before the parent bus "pcie" which is the root PCIe bus. Thus, the extended configuration space is not accessible on "dw-pcie". The issue can be resolved by adding the PCI_BUS_EXTENDED_CONFIG_SPACE flag to "pcie" before "dw-pcie" is realized.

I think we should fix the order of initialization rather than hack around it.

Quoted 18 lines
---
 hw/pci-host/designware.c | 1 +
 1 file changed, 1 insertion(+)
hw/pci-host/designware.c +1 -0
index 9e183caa48..388d252ee2 100644
@@ -694,6 +694,7 @@ static void designware_pcie_host_realize(DeviceState *dev, Error **errp)
                                      &s->pci.io,
                                      0, 4,
                                      TYPE_PCIE_BUS);
+    pci->bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
 
     memory_region_init(&s->pci.address_space_root,
                        OBJECT(s),
Signature · 1 line
2.17.1
#2 lore raw

As far as I know, the order issue is caused by nested device realization. In this case, realizing TYPE_DESIGNWARE_PCIE_HOST will also realize TYPE_DESIGNWARE_PCIE_ROOT(see designware_pcie_host_realize()). device_set_realized() is the function that realizing a device must go through, and this function first realizes the device by dc->realize() and then realizes the device's child bus by qbus_realize(). Whether there is any child bus of the device may depend on dc->realize(). The realization flow will be like a recursive call to device_set_realized(). More precisely, the flow in this case is: qdev_realize() --> ... --> FIRST device_set_realized() --> FIRST dc->realize() --> ...
--> designware_pcie_host_realize() --> qdev_realize() --> ... --> SECOND device_set_realized() --> SECOND dc->realize() --> ...
--> designware_pcie_root_realize() --> ...--> back to the SECOND device_set_realized() --> SECOND qbus_realize() the CHILD bus "dw-pcie" --> ... --> back to the FIRST device_set_realized() --> FIRST qbus_realize() the PARENT bus "pcie".

I also found this patch
<https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg02162.html> that solves the same bus issue.

Do you have any suggestions on the order of realization? Thanks!

Quoted 37 lines · Michael S. Tsirkin
Quoted 1 line · Jason Chien

In pcie_bus_realize(), a root bus is realized as a PCIe bus and a

non-root

Quoted 3 lines

bus is realized as a PCIe bus if its parent bus is a PCIe bus. However, the child bus "dw-pcie" is realized before the parent bus "pcie" which is the root PCIe bus. Thus, the extended configuration space is not

accessible

Quoted 2 lines

on "dw-pcie". The issue can be resolved by adding the PCI_BUS_EXTENDED_CONFIG_SPACE flag to "pcie" before "dw-pcie" is

realized.

Quoted 2 lines

I think we should fix the order of initialization rather than hack around it.

hw/pci-host/designware.c static void designware_pcie_host_realize(DeviceState

Quoted 9 lines
---
 hw/pci-host/designware.c | 1 +
 1 file changed, 1 insertion(+)
hw/pci-host/designware.c +0 -0
index 9e183caa48..388d252ee2 100644
@@ -694,6 +694,7 @@ static void designware_pcie_host_realize(DeviceState

*dev, Error **errp)

Quoted 9 lines
hw/pci-host/designware.c +1 -1
                                      &s->pci.io,
                                      0, 4,
                                      TYPE_PCIE_BUS);
+    pci->bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
 
     memory_region_init(&s->pci.address_space_root,
                        OBJECT(s),
--

2.17.1

#3 lore raw
Quoted 16 lines · Jason Chien

As far as I know, the order issue is caused by nested device realization. In this case, realizing TYPE_DESIGNWARE_PCIE_HOST will also
realize TYPE_DESIGNWARE_PCIE_ROOT(see designware_pcie_host_realize()). device_set_realized() is the function that realizing a device must go through, and this function first realizes the device by dc->realize() and then realizes the device's child bus by qbus_realize(). Whether there is any child bus of the device may depend on dc->realize(). The realization flow will be like a recursive call to device_set_realized(). More precisely, the flow in this case
is: qdev_realize() --> ... --> FIRST device_set_realized() --> FIRST dc-> realize() --> ... --> designware_pcie_host_realize() --> qdev_realize() --> ... --> SECOND device_set_realized() --> SECOND dc->realize() --> ... --> designware_pcie_root_realize() --> ...--> back to the SECOND device_set_realized() --> SECOND qbus_realize() the CHILD bus "dw-pcie" --> ... --> back to the FIRST device_set_realized() --> FIRST qbus_realize() the PARENT bus "pcie".

Quoted 1 line

I also found this patch that solves the same bus issue.

Which patch?

Quoted 1 line

Do you have any suggestions on the order of realization? Thanks!

I see. It's not easy to fix. Worth thinking about but I guess your patch is ok for now.

Quoted 39 lines · Michael S. Tsirkin
    On Wed, Aug 09, 2023 at 10:22:50AM +0000, Jason Chien wrote:
    > In pcie_bus_realize(), a root bus is realized as a PCIe bus and a
    non-root
    > bus is realized as a PCIe bus if its parent bus is a PCIe bus. However,
    > the child bus "dw-pcie" is realized before the parent bus "pcie" which is
    > the root PCIe bus. Thus, the extended configuration space is not
    accessible
    > on "dw-pcie". The issue can be resolved by adding the
    > PCI_BUS_EXTENDED_CONFIG_SPACE flag to "pcie" before "dw-pcie" is
    realized.
    >
    > Signed-off-by: Jason Chien <[email protected]>

    I think we should fix the order of initialization rather than
    hack around it.

    > ---
    >  hw/pci-host/designware.c | 1 +
    >  1 file changed, 1 insertion(+)
    >
    > diff --git a/hw/pci-host/designware.c b/hw/pci-host/designware.c
    > index 9e183caa48..388d252ee2 100644
    > --- a/hw/pci-host/designware.c
    > +++ b/hw/pci-host/designware.c
    > @@ -694,6 +694,7 @@ static void designware_pcie_host_realize(DeviceState
    *dev, Error **errp)
    >                                       &s->pci.io,
    >                                       0, 4,
    >                                       TYPE_PCIE_BUS);
    > +    pci->bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
    > 
    >      memory_region_init(&s->pci.address_space_root,
    >                         OBJECT(s),
    > --
    > 2.17.1
#4 lore raw

the patch
<https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg02162.html> link:
https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg02162.html

Quoted 80 lines · Michael S. Tsirkin
Quoted 1 line · Jason Chien

As far as I know, the order issue is caused by nested device

realization. In

Quoted 3 lines

this case, realizing TYPE_DESIGNWARE_PCIE_HOST will also realize TYPE_DESIGNWARE_PCIE_ROOT(see designware_pcie_host_realize()). device_set_realized() is the function that realizing a device must go

through,

Quoted 1 line

and this function first realizes the device by dc->realize() and then

realizes

Quoted 1 line

the device's child bus by qbus_realize(). Whether there is any child bus

of the

Quoted 2 lines

device may depend on dc->realize(). The realization flow will be like a recursive call to device_set_realized(). More precisely, the flow in

this case

Quoted 2 lines

is: qdev_realize() --> ... --> FIRST device_set_realized() --> FIRST dc-> realize() --> ... --> designware_pcie_host_realize() --> qdev_realize()

--> ...

Quoted 3 lines

--> SECOND device_set_realized() --> SECOND dc->realize() --> ... -->
designware_pcie_root_realize() --> ...--> back to the SECOND
device_set_realized() --> SECOND qbus_realize() the CHILD bus "dw-pcie"

--> ...

Quoted 1 line

--> back to the FIRST device_set_realized() --> FIRST qbus_realize() the

PARENT

Quoted 3 lines

bus "pcie".

I also found this patch that solves the same bus issue.

Which patch?

Quoted 1 line

Do you have any suggestions on the order of realization? Thanks!

I see. It's not easy to fix. Worth thinking about but I guess your patch is ok for now.

Quoted 1 line

On Thu, Aug 10, 2023 at 5:24 AM Michael S. Tsirkin <[email protected]>

Quoted 5 lines · wrote:

On Wed, Aug 09, 2023 at 10:22:50AM +0000, Jason Chien wrote:
> In pcie_bus_realize(), a root bus is realized as a PCIe bus and a non-root
> bus is realized as a PCIe bus if its parent bus is a PCIe bus.

However,

Quoted 1 line
Quoted 1 line

the child bus "dw-pcie" is realized before the parent bus "pcie"

which is

Quoted 12 lines
Quoted 1 line

the root PCIe bus. Thus, the extended configuration space is not

    accessible
    > on "dw-pcie". The issue can be resolved by adding the
    > PCI_BUS_EXTENDED_CONFIG_SPACE flag to "pcie" before "dw-pcie" is
    realized.
    >
    > Signed-off-by: Jason Chien <[email protected]>

    I think we should fix the order of initialization rather than
    hack around it.

    > ---
Quoted 8 lines
    >  hw/pci-host/designware.c | 1 +
    >  1 file changed, 1 insertion(+)
    >
    > diff --git a/hw/pci-host/designware.c b/hw/pci-host/designware.c
    > index 9e183caa48..388d252ee2 100644
    > --- a/hw/pci-host/designware.c
    > +++ b/hw/pci-host/designware.c
    > @@ -694,6 +694,7 @@ static void

designware_pcie_host_realize(DeviceState

Quoted 12 lines
    *dev, Error **errp)
    >                                       &s->pci.io,
    >                                       0, 4,
    >                                       TYPE_PCIE_BUS);
    > +    pci->bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
    >
    >      memory_region_init(&s->pci.address_space_root,
    >                         OBJECT(s),
    > --
    > 2.17.1
Acked-by on v1 1/1
#5 lore raw
In reply to Jason Chien
Quoted 8 lines · Jason Chien

In pcie_bus_realize(), a root bus is realized as a PCIe bus and a non-root bus is realized as a PCIe bus if its parent bus is a PCIe bus. However, the child bus "dw-pcie" is realized before the parent bus "pcie" which is the root PCIe bus. Thus, the extended configuration space is not accessible on "dw-pcie". The issue can be resolved by adding the PCI_BUS_EXTENDED_CONFIG_SPACE flag to "pcie" before "dw-pcie" is realized.

I'm not planning another pull before release, hopefully another maintainer can pick it up? Peter?

Quoted 18 lines
---
 hw/pci-host/designware.c | 1 +
 1 file changed, 1 insertion(+)
hw/pci-host/designware.c +1 -0
index 9e183caa48..388d252ee2 100644
@@ -694,6 +694,7 @@ static void designware_pcie_host_realize(DeviceState *dev, Error **errp)
                                      &s->pci.io,
                                      0, 4,
                                      TYPE_PCIE_BUS);
+    pci->bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
 
     memory_region_init(&s->pci.address_space_root,
                        OBJECT(s),
Signature · 1 line
2.17.1
#6 lore raw
Quoted 9 lines · Michael S. Tsirkin
Quoted 7 lines · Jason Chien

In pcie_bus_realize(), a root bus is realized as a PCIe bus and a non-root bus is realized as a PCIe bus if its parent bus is a PCIe bus. However, the child bus "dw-pcie" is realized before the parent bus "pcie" which is the root PCIe bus. Thus, the extended configuration space is not accessible on "dw-pcie". The issue can be resolved by adding the PCI_BUS_EXTENDED_CONFIG_SPACE flag to "pcie" before "dw-pcie" is realized.

Quoted 7 lines
Quoted 1 line

I'm not planning another pull before release, hopefully another maintainer can pick it up? Peter?

At the moment I don't have anything intended for 8.1 either, so whoever of us does it it would be a 1-patch pullreq...

-- PMM

#7 lore raw
Quoted 14 lines · Peter Maydell
Quoted 12 lines · Michael S. Tsirkin
Quoted 8 lines · Jason Chien

In pcie_bus_realize(), a root bus is realized as a PCIe bus and a non-root bus is realized as a PCIe bus if its parent bus is a PCIe bus. However, the child bus "dw-pcie" is realized before the parent bus "pcie" which is the root PCIe bus. Thus, the extended configuration space is not accessible on "dw-pcie". The issue can be resolved by adding the PCI_BUS_EXTENDED_CONFIG_SPACE flag to "pcie" before "dw-pcie" is realized.

Quoted 7 lines
Quoted 4 lines

I'm not planning another pull before release, hopefully another maintainer can pick it up? Peter?

At the moment I don't have anything intended for 8.1 either, so whoever of us does it it would be a 1-patch pullreq...

Also, at this stage in the release cycle it's always worth
asking: is this a regression, or was this bug also in 8.0?

thanks
-- PMM

#8 lore raw

This bug was also in 8.0.

Jason

Quoted 35 lines · Peter Maydell
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin
Quoted 1 line · Jason Chien

In pcie_bus_realize(), a root bus is realized as a PCIe bus and a

non-root

Quoted 1 line
Quoted 1 line
Quoted 1 line

bus is realized as a PCIe bus if its parent bus is a PCIe bus.

However,

Quoted 1 line
Quoted 1 line
Quoted 1 line

the child bus "dw-pcie" is realized before the parent bus "pcie"

which is

Quoted 1 line
Quoted 1 line
Quoted 1 line

the root PCIe bus. Thus, the extended configuration space is not

accessible

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

on "dw-pcie". The issue can be resolved by adding the PCI_BUS_EXTENDED_CONFIG_SPACE flag to "pcie" before "dw-pcie" is

realized.

Quoted 11 lines
Quoted 8 lines
Quoted 2 lines

I'm not planning another pull before release, hopefully another maintainer can pick it up? Peter?

At the moment I don't have anything intended for 8.1 either, so whoever of us does it it would be a 1-patch pullreq...

Also, at this stage in the release cycle it's always worth
asking: is this a regression, or was this bug also in 8.0?

thanks
-- PMM

Reviewed-by on v1 1/1
#9 lore raw
In reply to Jason Chien
Quoted 30 lines · Jason Chien

In pcie_bus_realize(), a root bus is realized as a PCIe bus and a non-root bus is realized as a PCIe bus if its parent bus is a PCIe bus. However, the child bus "dw-pcie" is realized before the parent bus "pcie" which is the root PCIe bus. Thus, the extended configuration space is not accessible on "dw-pcie". The issue can be resolved by adding the PCI_BUS_EXTENDED_CONFIG_SPACE flag to "pcie" before "dw-pcie" is realized.

---
 hw/pci-host/designware.c | 1 +
 1 file changed, 1 insertion(+)
hw/pci-host/designware.c +1 -0
index 9e183caa48..388d252ee2 100644
@@ -694,6 +694,7 @@ static void designware_pcie_host_realize(DeviceState
 *dev, Error **errp)
                                      &s->pci.io,
                                      0, 4,
                                      TYPE_PCIE_BUS);
+    pci->bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
 
     memory_region_init(&s->pci.address_space_root,
                        OBJECT(s),

--
2.17.1