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

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