[SeaBIOS] [PATCH v3 1/2] pci: reserve resources for pcie-pci-bridge to fix regressed hotplug on q35

Igor Mammedov posted 2 patches 2 years, 9 months ago
[SeaBIOS] [PATCH v3 1/2] pci: reserve resources for pcie-pci-bridge to fix regressed hotplug on q35
Posted by Igor Mammedov 2 years, 9 months ago
If QEMU is started with unpopulated pcie-pci-bridge with ACPI PCI
hotplug enabled (default since QEMU-6.1), hotplugging a PCI device
into one of the bridge slots fails due to lack of resources.

once linux guest is booted (test used Fedora 34), hotplug NIC from
QEMU monitor:
  (qemu) device_add rtl8139,bus=pcie-pci-bridge-0,addr=0x2

guest fails hotplug with:
  pci 0000:01:02.0: [10ec:8139] type 00 class 0x020000
  pci 0000:01:02.0: reg 0x10: [io  0x0000-0x00ff]
  pci 0000:01:02.0: reg 0x14: [mem 0x00000000-0x000000ff]
  pci 0000:01:02.0: reg 0x30: [mem 0x00000000-0x0003ffff pref]
  pci 0000:01:02.0: BAR 6: no space for [mem size 0x00040000 pref]
  pci 0000:01:02.0: BAR 6: failed to assign [mem size 0x00040000 pref]
  pci 0000:01:02.0: BAR 0: no space for [io  size 0x0100]
  pci 0000:01:02.0: BAR 0: failed to assign [io  size 0x0100]
  pci 0000:01:02.0: BAR 1: no space for [mem size 0x00000100]
  pci 0000:01:02.0: BAR 1: failed to assign [mem size 0x00000100]
  8139cp: 8139cp: 10/100 PCI Ethernet driver v1.3 (Mar 22, 2004)
  PCI Interrupt Link [GSIG] enabled at IRQ 22
  8139cp 0000:01:02.0: no MMIO resource
  8139cp: probe of 0000:01:02.0 failed with error -5

Reason for this is that commit [1] didn't take into account
pcie-pci-bridge, marking bridge as non hotpluggable instead of
handling it as possibly SHPC capable bridge.
Fix issue by checking if pcie-pci-bridge is SHPC capable and
if it is mark it as hotpluggable.

Fixes regression in QEMU-6.1 and later, since it was switched
to ACPI based PCI hotplug on Q35 by default at that time.

RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2001732
[1]
Fixes: 3aa31d7d637 ("hw/pci: reserve IO and mem for pci express downstream ports with no devices attached")
Signed-off-by: Igor Mammedov imammedo@redhat.com
CC: mapfelba@redhat.com
CC: kraxel@redhat.com
CC: mst@redhat.com
CC: lvivier@redhat.com
CC: jusual@redhat.com
---
 src/fw/pciinit.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
index d25931bb..7342d8d8 100644
--- a/src/fw/pciinit.c
+++ b/src/fw/pciinit.c
@@ -802,6 +802,10 @@ static int pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap)
                                           pcie_cap + PCI_EXP_FLAGS);
         u8 port_type = ((pcie_flags & PCI_EXP_FLAGS_TYPE) >>
                        (__builtin_ffs(PCI_EXP_FLAGS_TYPE) - 1));
+
+        if (port_type == PCI_EXP_TYPE_PCI_BRIDGE)
+            goto check_shpc;
+
         u8 downstream_port = (port_type == PCI_EXP_TYPE_DOWNSTREAM) ||
                              (port_type == PCI_EXP_TYPE_ROOT_PORT);
         /*
@@ -818,6 +822,7 @@ static int pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap)
         return downstream_port && slot_implemented;
     }
 
+check_shpc:
     shpc_cap = pci_find_capability(bus->bus_dev->bdf, PCI_CAP_ID_SHPC, 0);
     return !!shpc_cap;
 }
-- 
2.27.0

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org
[SeaBIOS] Re: [PATCH v3 1/2] pci: reserve resources for pcie-pci-bridge to fix regressed hotplug on q35
Posted by Laurent Vivier 2 years, 9 months ago
On 29/11/2021 12:48, Igor Mammedov wrote:
> If QEMU is started with unpopulated pcie-pci-bridge with ACPI PCI
> hotplug enabled (default since QEMU-6.1), hotplugging a PCI device
> into one of the bridge slots fails due to lack of resources.
> 
> once linux guest is booted (test used Fedora 34), hotplug NIC from
> QEMU monitor:
>    (qemu) device_add rtl8139,bus=pcie-pci-bridge-0,addr=0x2
> 
> guest fails hotplug with:
>    pci 0000:01:02.0: [10ec:8139] type 00 class 0x020000
>    pci 0000:01:02.0: reg 0x10: [io  0x0000-0x00ff]
>    pci 0000:01:02.0: reg 0x14: [mem 0x00000000-0x000000ff]
>    pci 0000:01:02.0: reg 0x30: [mem 0x00000000-0x0003ffff pref]
>    pci 0000:01:02.0: BAR 6: no space for [mem size 0x00040000 pref]
>    pci 0000:01:02.0: BAR 6: failed to assign [mem size 0x00040000 pref]
>    pci 0000:01:02.0: BAR 0: no space for [io  size 0x0100]
>    pci 0000:01:02.0: BAR 0: failed to assign [io  size 0x0100]
>    pci 0000:01:02.0: BAR 1: no space for [mem size 0x00000100]
>    pci 0000:01:02.0: BAR 1: failed to assign [mem size 0x00000100]
>    8139cp: 8139cp: 10/100 PCI Ethernet driver v1.3 (Mar 22, 2004)
>    PCI Interrupt Link [GSIG] enabled at IRQ 22
>    8139cp 0000:01:02.0: no MMIO resource
>    8139cp: probe of 0000:01:02.0 failed with error -5
> 
> Reason for this is that commit [1] didn't take into account
> pcie-pci-bridge, marking bridge as non hotpluggable instead of
> handling it as possibly SHPC capable bridge.
> Fix issue by checking if pcie-pci-bridge is SHPC capable and
> if it is mark it as hotpluggable.
> 
> Fixes regression in QEMU-6.1 and later, since it was switched
> to ACPI based PCI hotplug on Q35 by default at that time.
> 
> RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2001732
> [1]
> Fixes: 3aa31d7d637 ("hw/pci: reserve IO and mem for pci express downstream ports with no devices attached")
> Signed-off-by: Igor Mammedov imammedo@redhat.com
> CC: mapfelba@redhat.com
> CC: kraxel@redhat.com
> CC: mst@redhat.com
> CC: lvivier@redhat.com
> CC: jusual@redhat.com
> ---
>   src/fw/pciinit.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
> index d25931bb..7342d8d8 100644
> --- a/src/fw/pciinit.c
> +++ b/src/fw/pciinit.c
> @@ -802,6 +802,10 @@ static int pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap)
>                                             pcie_cap + PCI_EXP_FLAGS);
>           u8 port_type = ((pcie_flags & PCI_EXP_FLAGS_TYPE) >>
>                          (__builtin_ffs(PCI_EXP_FLAGS_TYPE) - 1));
> +
> +        if (port_type == PCI_EXP_TYPE_PCI_BRIDGE)
> +            goto check_shpc;
> +
>           u8 downstream_port = (port_type == PCI_EXP_TYPE_DOWNSTREAM) ||
>                                (port_type == PCI_EXP_TYPE_ROOT_PORT);
>           /*
> @@ -818,6 +822,7 @@ static int pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap)
>           return downstream_port && slot_implemented;
>       }
>   
> +check_shpc:
>       shpc_cap = pci_find_capability(bus->bus_dev->bdf, PCI_CAP_ID_SHPC, 0);
>       return !!shpc_cap;
>   }
> 

Tested-by: Laurent Vivier <lvivier@redhat.com>

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org
[SeaBIOS] Re: [PATCH v3 1/2] pci: reserve resources for pcie-pci-bridge to fix regressed hotplug on q35
Posted by Michael S. Tsirkin 2 years, 9 months ago
On Mon, Nov 29, 2021 at 06:48:11AM -0500, Igor Mammedov wrote:
> If QEMU is started with unpopulated pcie-pci-bridge with ACPI PCI
> hotplug enabled (default since QEMU-6.1), hotplugging a PCI device
> into one of the bridge slots fails due to lack of resources.
> 
> once linux guest is booted (test used Fedora 34), hotplug NIC from
> QEMU monitor:
>   (qemu) device_add rtl8139,bus=pcie-pci-bridge-0,addr=0x2
> 
> guest fails hotplug with:
>   pci 0000:01:02.0: [10ec:8139] type 00 class 0x020000
>   pci 0000:01:02.0: reg 0x10: [io  0x0000-0x00ff]
>   pci 0000:01:02.0: reg 0x14: [mem 0x00000000-0x000000ff]
>   pci 0000:01:02.0: reg 0x30: [mem 0x00000000-0x0003ffff pref]
>   pci 0000:01:02.0: BAR 6: no space for [mem size 0x00040000 pref]
>   pci 0000:01:02.0: BAR 6: failed to assign [mem size 0x00040000 pref]
>   pci 0000:01:02.0: BAR 0: no space for [io  size 0x0100]
>   pci 0000:01:02.0: BAR 0: failed to assign [io  size 0x0100]
>   pci 0000:01:02.0: BAR 1: no space for [mem size 0x00000100]
>   pci 0000:01:02.0: BAR 1: failed to assign [mem size 0x00000100]
>   8139cp: 8139cp: 10/100 PCI Ethernet driver v1.3 (Mar 22, 2004)
>   PCI Interrupt Link [GSIG] enabled at IRQ 22
>   8139cp 0000:01:02.0: no MMIO resource
>   8139cp: probe of 0000:01:02.0 failed with error -5
> 
> Reason for this is that commit [1] didn't take into account
> pcie-pci-bridge, marking bridge as non hotpluggable instead of
> handling it as possibly SHPC capable bridge.
> Fix issue by checking if pcie-pci-bridge is SHPC capable and
> if it is mark it as hotpluggable.
> 
> Fixes regression in QEMU-6.1 and later, since it was switched
> to ACPI based PCI hotplug on Q35 by default at that time.
> 
> RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2001732
> [1]
> Fixes: 3aa31d7d637 ("hw/pci: reserve IO and mem for pci express downstream ports with no devices attached")
> Signed-off-by: Igor Mammedov imammedo@redhat.com
> CC: mapfelba@redhat.com
> CC: kraxel@redhat.com
> CC: mst@redhat.com
> CC: lvivier@redhat.com
> CC: jusual@redhat.com

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
>  src/fw/pciinit.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
> index d25931bb..7342d8d8 100644
> --- a/src/fw/pciinit.c
> +++ b/src/fw/pciinit.c
> @@ -802,6 +802,10 @@ static int pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap)
>                                            pcie_cap + PCI_EXP_FLAGS);
>          u8 port_type = ((pcie_flags & PCI_EXP_FLAGS_TYPE) >>
>                         (__builtin_ffs(PCI_EXP_FLAGS_TYPE) - 1));
> +
> +        if (port_type == PCI_EXP_TYPE_PCI_BRIDGE)
> +            goto check_shpc;
> +
>          u8 downstream_port = (port_type == PCI_EXP_TYPE_DOWNSTREAM) ||
>                               (port_type == PCI_EXP_TYPE_ROOT_PORT);
>          /*
> @@ -818,6 +822,7 @@ static int pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap)
>          return downstream_port && slot_implemented;
>      }
>  
> +check_shpc:
>      shpc_cap = pci_find_capability(bus->bus_dev->bdf, PCI_CAP_ID_SHPC, 0);
>      return !!shpc_cap;
>  }
> -- 
> 2.27.0

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org