Blame SOURCES/0006-pci-reserve-resources-for-pcie-pci-bridge-to-fix-reg.patch

aef0c9
From 4a31485efad9db7feed56f483e123f0b58c38b2f Mon Sep 17 00:00:00 2001
aef0c9
From: Igor Mammedov <imammedo@redhat.com>
aef0c9
Date: Mon, 29 Nov 2021 06:48:11 -0500
aef0c9
Subject: pci: reserve resources for pcie-pci-bridge to fix regressed hotplug
aef0c9
 on q35
aef0c9
aef0c9
RH-Bugzilla: 2001921
aef0c9
aef0c9
If QEMU is started with unpopulated pcie-pci-bridge with ACPI PCI
aef0c9
hotplug enabled (default since QEMU-6.1), hotplugging a PCI device
aef0c9
into one of the bridge slots fails due to lack of resources.
aef0c9
aef0c9
once linux guest is booted (test used Fedora 34), hotplug NIC from
aef0c9
QEMU monitor:
aef0c9
  (qemu) device_add rtl8139,bus=pcie-pci-bridge-0,addr=0x2
aef0c9
aef0c9
guest fails hotplug with:
aef0c9
  pci 0000:01:02.0: [10ec:8139] type 00 class 0x020000
aef0c9
  pci 0000:01:02.0: reg 0x10: [io  0x0000-0x00ff]
aef0c9
  pci 0000:01:02.0: reg 0x14: [mem 0x00000000-0x000000ff]
aef0c9
  pci 0000:01:02.0: reg 0x30: [mem 0x00000000-0x0003ffff pref]
aef0c9
  pci 0000:01:02.0: BAR 6: no space for [mem size 0x00040000 pref]
aef0c9
  pci 0000:01:02.0: BAR 6: failed to assign [mem size 0x00040000 pref]
aef0c9
  pci 0000:01:02.0: BAR 0: no space for [io  size 0x0100]
aef0c9
  pci 0000:01:02.0: BAR 0: failed to assign [io  size 0x0100]
aef0c9
  pci 0000:01:02.0: BAR 1: no space for [mem size 0x00000100]
aef0c9
  pci 0000:01:02.0: BAR 1: failed to assign [mem size 0x00000100]
aef0c9
  8139cp: 8139cp: 10/100 PCI Ethernet driver v1.3 (Mar 22, 2004)
aef0c9
  PCI Interrupt Link [GSIG] enabled at IRQ 22
aef0c9
  8139cp 0000:01:02.0: no MMIO resource
aef0c9
  8139cp: probe of 0000:01:02.0 failed with error -5
aef0c9
aef0c9
Reason for this is that commit [1] didn't take into account
aef0c9
pcie-pci-bridge, marking bridge as non hotpluggable instead of
aef0c9
handling it as possibly SHPC capable bridge.
aef0c9
Fix issue by checking if pcie-pci-bridge is SHPC capable and
aef0c9
if it is mark it as hotpluggable.
aef0c9
aef0c9
Fixes regression in QEMU-6.1 and later, since it was switched
aef0c9
to ACPI based PCI hotplug on Q35 by default at that time.
aef0c9
aef0c9
[1]
aef0c9
Fixes: 3aa31d7d637 ("hw/pci: reserve IO and mem for pci express downstream ports with no devices attached")
aef0c9
Signed-off-by: Igor Mammedov imammedo@redhat.com
aef0c9
CC: mapfelba@redhat.com
aef0c9
CC: kraxel@redhat.com
aef0c9
CC: mst@redhat.com
aef0c9
CC: lvivier@redhat.com
aef0c9
CC: jusual@redhat.com
aef0c9
Tested-by: Laurent Vivier <lvivier@redhat.com>
aef0c9
Acked-by: Michael S. Tsirkin <mst@redhat.com>
aef0c9
Message-Id: <20211129114812.231849-2-imammedo@redhat.com>
aef0c9
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
aef0c9
---
aef0c9
 src/fw/pciinit.c | 5 +++++
aef0c9
 1 file changed, 5 insertions(+)
aef0c9
aef0c9
diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
aef0c9
index 3c99d51..badf13d 100644
aef0c9
--- a/src/fw/pciinit.c
aef0c9
+++ b/src/fw/pciinit.c
aef0c9
@@ -808,6 +808,10 @@ static hotplug_type_t pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap)
aef0c9
                                           pcie_cap + PCI_EXP_FLAGS);
aef0c9
         u8 port_type = ((pcie_flags & PCI_EXP_FLAGS_TYPE) >>
aef0c9
                        (__builtin_ffs(PCI_EXP_FLAGS_TYPE) - 1));
aef0c9
+
aef0c9
+        if (port_type == PCI_EXP_TYPE_PCI_BRIDGE)
aef0c9
+            goto check_shpc;
aef0c9
+
aef0c9
         u8 downstream_port = (port_type == PCI_EXP_TYPE_DOWNSTREAM) ||
aef0c9
                              (port_type == PCI_EXP_TYPE_ROOT_PORT);
aef0c9
         /*
aef0c9
@@ -825,6 +829,7 @@ static hotplug_type_t pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap)
aef0c9
             HOTPLUG_PCIE : HOTPLUG_NO_SUPPORTED;
aef0c9
     }
aef0c9
 
aef0c9
+check_shpc:
aef0c9
     shpc_cap = pci_find_capability(bus->bus_dev->bdf, PCI_CAP_ID_SHPC, 0);
aef0c9
     return !!shpc_cap ? HOTPLUG_SHPC : HOTPLUG_NO_SUPPORTED;
aef0c9
 }
aef0c9
-- 
aef0c9
2.27.0
aef0c9