Skip to contentSkip to conversation

hw/pcie-root-port: Fix hotplug for PCI devices requiring IO

PATCH Superseded Marcel Apfelbaum 2 participants 2 messages Jul 22, 2021 – Jul 26, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/pcie-root-port: Fix hotplug for PCI devices requiring IO

Q35 has now ACPI hotplug enabled by default for PCI(e) devices. As opposed to native PCIe hotplug, some guests will not assign IO range to pcie-root-ports not supporting native hotplug, resulting into a regression.

Fix it by setting the "reserve-io" hint capability of the pcie-root-ports so the firmware will allocate the IO range instead.

---
 hw/pci-bridge/gen_pcie_root_port.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/pci-bridge/gen_pcie_root_port.c +5 -0
index ec9907917e..20099a8ae3 100644
@@ -28,6 +28,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(GenPCIERootPort, GEN_PCIE_ROOT_PORT)
         (GEN_PCIE_ROOT_PORT_AER_OFFSET + PCI_ERR_SIZEOF)
 
 #define GEN_PCIE_ROOT_PORT_MSIX_NR_VECTOR       1
+#define GEN_PCIE_ROOT_DEFAULT_IO_RANGE          4096
 
 struct GenPCIERootPort {
     /*< private >*/
@@ -75,6 +76,7 @@ static bool gen_rp_test_migrate_msix(void *opaque, int version_id)
 static void gen_rp_realize(DeviceState *dev, Error **errp)
 {
     PCIDevice *d = PCI_DEVICE(dev);
+    PCIESlot *s = PCIE_SLOT(d);
     GenPCIERootPort *grp = GEN_PCIE_ROOT_PORT(d);
     PCIERootPortClass *rpc = PCIE_ROOT_PORT_GET_CLASS(d);
     Error *local_err = NULL;
@@ -85,6 +87,9 @@ static void gen_rp_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    if (grp->res_reserve.io == -1 && s->hotplug && !s->native_hotplug) {
+        grp->res_reserve.io = GEN_PCIE_ROOT_DEFAULT_IO_RANGE;
+    }
     int rc = pci_bridge_qemu_reserve_cap_init(d, 0,
                                               grp->res_reserve, errp);
 
Signature · 1 line
2.31.1
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · On Thu, 22 Jul 2021 12:00:09 +0300 Marcel Apfelbaum…

Q35 has now ACPI hotplug enabled by default for PCI(e) devices. As opposed to native PCIe hotplug, some guests will not assign

could be 'some guests' be more specific, preferably with a way to reproduce issue.

Quoted 7 lines

IO range to pcie-root-ports not supporting native hotplug, resulting into a regression.

Fix it by setting the "reserve-io" hint capability of the pcie-root-ports so the firmware will allocate the IO range instead.

other than commit message nit, looks fine to me

Quoted 34 lines
---
 hw/pci-bridge/gen_pcie_root_port.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/pci-bridge/gen_pcie_root_port.c +5 -0
index ec9907917e..20099a8ae3 100644
@@ -28,6 +28,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(GenPCIERootPort, GEN_PCIE_ROOT_PORT)
         (GEN_PCIE_ROOT_PORT_AER_OFFSET + PCI_ERR_SIZEOF)
 
 #define GEN_PCIE_ROOT_PORT_MSIX_NR_VECTOR       1
+#define GEN_PCIE_ROOT_DEFAULT_IO_RANGE          4096
 
 struct GenPCIERootPort {
     /*< private >*/
@@ -75,6 +76,7 @@ static bool gen_rp_test_migrate_msix(void *opaque, int version_id)
 static void gen_rp_realize(DeviceState *dev, Error **errp)
 {
     PCIDevice *d = PCI_DEVICE(dev);
+    PCIESlot *s = PCIE_SLOT(d);
     GenPCIERootPort *grp = GEN_PCIE_ROOT_PORT(d);
     PCIERootPortClass *rpc = PCIE_ROOT_PORT_GET_CLASS(d);
     Error *local_err = NULL;
@@ -85,6 +87,9 @@ static void gen_rp_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    if (grp->res_reserve.io == -1 && s->hotplug && !s->native_hotplug) {
+        grp->res_reserve.io = GEN_PCIE_ROOT_DEFAULT_IO_RANGE;
+    }
     int rc = pci_bridge_qemu_reserve_cap_init(d, 0,
                                               grp->res_reserve, errp);