Skip to contentSkip to conversation

hw/pci, hw/arm/virt: fixed PCI BAR placement

PATCH In review Tushar Dave 2 participants 16 messages Sep 16 – Oct 30 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover hw/pci, hw/arm/virt: fixed PCI BAR placement

This patch series introduces a mechanism to specify Guest Physical Addresses (GPAs) for PCI BARs, allowing explicit placement of guest MMIO BAR addresses to match host physical addresses for assigned devices.

On some platforms, P2P DMA between devices in the same IOMMU group is required for the desired data path and performance. The PCI fabric ACS is configured to permit direct P2P without routing traffic through the host bridge.

To support this multi-device IOMMU group P2P scenario in virtualization, the VM may need to preserve the host PCI BAR addresses in the guest.

A new fixed-bar-N property on a PCI endpoint device specifies the required guest address for BAR N (N = 0 through 5):

    -device some-device,fixed-bar-0=<addr>[,fixed-bar-1=<addr>]...

Once any fixed-bar-N property is set on a device, every memory BAR on that device must have a fixed address. Under a PCIe root port, fixed BAR placement is all-or-nothing within that root port's subtree. If one endpoint below the root port has a fixed BAR, every other endpoint with a memory BAR below that same root port must also have all of its memory BARs fixed.

QEMU validates the configuration during device realization. Each address must be aligned to its BAR size, fall within the appropriate PCIe MMIO aperture, and not overlap any other fixed BAR. QEMU aborts on any validation failure. QEMU performs neither PCI enumeration nor BAR allocation; the validated configuration is exported to firmware through the "etc/fixed-bars" fw_cfg blob, which carries each PCI function's vendor/device identification, firmware device path, and, for fixed devices, the configured address, size, and type of each BAR.

The fixed-bar-N property and its validation are generic and apply to any PCI device. This series wires up the fw_cfg export on the virt machine only; other machine types would need their own equivalent wiring to expose the same mechanism to firmware.

On the firmware side, the existing IncompatiblePciDeviceSupportDxe driver is extended to consume this blob. Before PCI enumeration, it reserves the fixed BAR address ranges in the GCD memory space map. During device discovery, its CheckDevice() implementation checks for a fixed-bars entry first, falling back to the existing 64-bit-MMIO preference descriptor otherwise, returning ACPI address descriptors with _MIF|_MAF set for fixed BARs.

PciBusDxe preserves and programs these fixed addresses when programming each BAR, and sizes and programs each ancestor bridge's resource window to cover the union of its fixed descendants' address ranges. This allows fixed BARs behind one or more PCI bridges to be correctly routed.

Fixed BAR placement requires firmware to preserve QEMU's PCI configuration across reset. This is requested through the PCI boot configuration preservation mechanism using ACPI _DSM function 5. Fixed BAR configuration is rejected when ACPI is disabled.

Example 1: VFIO passthrough device with fixed BARs and the PCIe MMIO aperture adjusted to accommodate the fixed addresses.

    -machine virt,...,highmem-mmio-base=4T,highmem-mmio-size=4T
    -device pcie-root-port,id=pcie.port1,bus=pcie.1,chassis=1,io-reserve=0
    -device x3130-upstream,id=upstream1,bus=pcie.port1
    -device xio3130-downstream,id=downstream1_1,bus=upstream1,chassis=1,slot=2
    -device vfio-pci-nohotplug,host=0018:06:00.0,bus=downstream1_1,id=dev0,\
            fixed-bar-0=0x48000000000,fixed-bar-2=0x50000000000,fixed-bar-4=0x58000000000

Example 2: VFIO and emulated devices under the same root port with fixed BARs and the PCIe MMIO aperture adjusted using highmem-mmio-base.

    -machine virt,...,highmem-mmio-base=64T,highmem-mmio-size=64T
    -device pxb-pcie,id=pcie.1,bus_nr=1,bus=pcie.0
    -device pcie-root-port,id=pcie.port1,bus=pcie.1,chassis=1,io-reserve=0
    -device x3130-upstream,id=upstream1,bus=pcie.port1
    -device xio3130-downstream,id=downstream1_1,bus=upstream1,chassis=1,slot=1
    -device vfio-pci-nohotplug,host=0018:06:00.0,bus=downstream1_1,rombar=0,id=dev0,iommufd=iommufd0,\
            fixed-bar-0=0x6b4000000000,fixed-bar-2=0x6b8000000000,fixed-bar-4=0x6c0000000000
    -device xio3130-downstream,id=downstream1_2,bus=upstream1,chassis=1,slot=2
    -device vfio-pci,host=0012:03:00.1,bus=downstream1_2,id=nic1,iommufd=iommufd0,fixed-bar-0=0x6c8000000000
    -device xio3130-downstream,id=downstream1_3,bus=upstream1,chassis=1,slot=3
    -device e1000,netdev=net0,bus=downstream1_3,id=nic_emu,fixed-bar-0=0x20000000

Limitations:

* I/O BARs and the expansion ROM BAR are not covered by fixed-bar-N.
* This has only been tested on the AArch64 virt machine.
* SR-IOV VF BARs are not covered.

Testing:

The series was tested on the AArch64 virt machine across a range of PCIe
topologies: emulated devices, VFIO passthrough devices, PCIe switches, single and multiple fixed-BAR endpoints under a shared root port, and fixed BARs behind nested bridges.

Changes since RFC v2:

* Replace pci-bars/fixed-bar with per-BAR fixed-bar-N properties; drop the root-port fixed-bar=on property. Fixed-BAR handling is inferred from devices in the root-port subtree.
* Drop the separate post-enumeration bridge-window reprogramming pass; PciBusDxe's own CalculateResourceAperture()/ProgramPpbApperture() now size and program bridge windows for fixed BARs directly, as part of normal resource calculation and programming.
* Include the firmware device path in the fw_cfg blob.
* Integrate fixed-BAR handling into the existing IncompatiblePciDeviceSupportDxe driver instead of a separate QemuFixedBarsDxe driver.

RFC v2:
https://lore.kernel.org/qemu-devel/[email protected]/

RFC v1:
https://lore.kernel.org/qemu-devel/[email protected]/

A git branch with this series applied is available at:
https://github.com/tdavenvidia/upstream-qemu/tree/Upstream-fixed-bar-Sep-15-V1

The related EDK2 change is available at:
https://github.com/tdavenvidia/edk2/tree/Upstream-fixed-bar-Sep-15-V1

Tushar Dave (5):
hw/pci: introduce PCI fixed BAR properties
pci: add validation for fixed BAR configuration
pci: add fixed BAR fw_cfg blob export hw/arm/virt: export fixed BAR metadata via fw_cfg hw/arm/virt: add highmem-mmio-base property

 hw/arm/virt.c                   |  78 +++++++-
 hw/pci/meson.build              |   2 +
 hw/pci/pci-fixed-bar-blob.c     | 305 ++++++++++++++++++++++++++++++
 hw/pci/pci-fixed-bar-validate.c | 326 ++++++++++++++++++++++++++++++++
 hw/pci/pci-fixed-bar-validate.h |  21 ++
 hw/pci/pci-fixed-bar.h          |  63 ++++++
 hw/pci/pci.c                    |  43 +++++
 include/hw/pci/pci_device.h     |   7 +
 8 files changed, 844 insertions(+), 1 deletion(-)
 create mode 100644 hw/pci/pci-fixed-bar-blob.c
 create mode 100644 hw/pci/pci-fixed-bar-validate.c
 create mode 100644 hw/pci/pci-fixed-bar-validate.h
 create mode 100644 hw/pci/pci-fixed-bar.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/5 hw/pci: introduce PCI fixed BAR properties

Add fixed-bar-N properties to PCIDevice to allow the guest address of an individual PCI BAR to be explicitly specified. The properties are available for PCI BARs 0 through 5 and accept QEMU size values, for example fixed-bar-0=0x40000000 or fixed-bar-0=64G.

e.g.
-device some-device,fixed-bar-0=<addr>[,fixed-bar-1=<addr>]...

During realize, validate that each specified BAR exists and is a memory BAR, and reject fixed BAR configuration for hot-plugged devices.

---
 hw/pci/pci.c                | 43 +++++++++++++++++++++++++++++++++++++
 include/hw/pci/pci_device.h |  7 ++++++
 2 files changed, 50 insertions(+)
hw/pci/pci.c +43 -0
index 0efb4eb4bb..775fef1beb 100644
@@ -89,6 +89,12 @@ static const Property pci_props[] = {
     DEFINE_PROP_STRING("romfile", PCIDevice, romfile),
     DEFINE_PROP_UINT32("romsize", PCIDevice, romsize, UINT32_MAX),
     DEFINE_PROP_INT32("rombar",  PCIDevice, rom_bar, -1),
+    DEFINE_PROP_SIZE("fixed-bar-0", PCIDevice, fixed_bar_addr[0], PCI_BAR_UNMAPPED),
+    DEFINE_PROP_SIZE("fixed-bar-1", PCIDevice, fixed_bar_addr[1], PCI_BAR_UNMAPPED),
+    DEFINE_PROP_SIZE("fixed-bar-2", PCIDevice, fixed_bar_addr[2], PCI_BAR_UNMAPPED),
+    DEFINE_PROP_SIZE("fixed-bar-3", PCIDevice, fixed_bar_addr[3], PCI_BAR_UNMAPPED),
+    DEFINE_PROP_SIZE("fixed-bar-4", PCIDevice, fixed_bar_addr[4], PCI_BAR_UNMAPPED),
+    DEFINE_PROP_SIZE("fixed-bar-5", PCIDevice, fixed_bar_addr[5], PCI_BAR_UNMAPPED),
     DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present,
                     QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false),
     DEFINE_PROP_BIT("x-pcie-lnksta-dllla", PCIDevice, cap_present,
@@ -228,6 +234,36 @@ static void pci_bus_unrealize(BusState *qbus)
     vmstate_unregister(NULL, &vmstate_pcibus, bus);
 }
 
+static void pci_check_fixed_bars(PCIDevice *pci_dev, Error **errp)
+{
+    PCIIORegion *r;
+    int i;
+
+    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+        if (pci_dev->fixed_bar_addr[i] == PCI_BAR_UNMAPPED) {
+            continue;
+        }
+
+        if (DEVICE(pci_dev)->hotplugged) {
+            error_setg(errp, "fixed-bar-%d is not supported on "
+                       "hot-plugged devices", i);
+            return;
+        }
+
+        r = &pci_dev->io_regions[i];
+        if (!r->size) {
+            error_setg(errp, "fixed-bar-%d: bar%d does not exist on %s",
+                       i, i, pci_dev->name);
+            return;
+        }
+        if (r->type & PCI_BASE_ADDRESS_SPACE_IO) {
+            error_setg(errp, "fixed-bar-%d: bar%d on %s is an I/O BAR, "
+                       "not a memory BAR", i, i, pci_dev->name);
+            return;
+        }
+    }
+}
+
 static int pcibus_num(PCIBus *bus)
 {
     if (pci_bus_is_root(bus)) {
@@ -2393,6 +2429,13 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp)
         is_default_rom = true;
     }
 
+    pci_check_fixed_bars(pci_dev, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        pci_qdev_unrealize(DEVICE(pci_dev));
+        return;
+    }
+
     pci_add_option_rom(pci_dev, is_default_rom, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
include/hw/pci/pci_device.h +7 -0
index 5cac6e1688..fc5f50a1c4 100644
@@ -187,6 +187,13 @@ struct PCIDevice {
     uint32_t max_bounce_buffer_size;
 
     char *sriov_pf;
+
+    /*
+     * fixed_bar_addr[N] holds the guest address configured via the
+     * fixed-bar-N property for memory BAR N. PCI_BAR_UNMAPPED means
+     * the BAR's address is not fixed.
+     */
+    uint64_t  fixed_bar_addr[PCI_NUM_REGIONS - 1];
 };
 
 static inline int pci_intx(PCIDevice *pci_dev)
Signature · 1 line
2.34.1
#2 lore raw

RE: [PATCH 1/5] hw/pci: introduce PCI fixed BAR properties

Quoted 45 lines

-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 16 September 2026 19:56
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 1/5] hw/pci: introduce PCI fixed BAR properties

Add fixed-bar-N properties to PCIDevice to allow the guest address of an individual PCI BAR to be explicitly specified. The properties are available for PCI BARs 0 through 5 and accept QEMU size values, for example fixed-bar-0=0x40000000 or fixed-bar-0=64G.

e.g.
-device some-device,fixed-bar-0=<addr>[,fixed-bar-1=<addr>]...

During realize, validate that each specified BAR exists and is a memory BAR, and reject fixed BAR configuration for hot-plugged devices.

---
 hw/pci/pci.c                | 43 +++++++++++++++++++++++++++++++++++++
 include/hw/pci/pci_device.h |  7 ++++++
 2 files changed, 50 insertions(+)
hw/pci/pci.c +4 -0
index 0efb4eb4bb..775fef1beb 100644
@@ -89,6 +89,12 @@ static const Property pci_props[] = {
     DEFINE_PROP_STRING("romfile", PCIDevice, romfile),
     DEFINE_PROP_UINT32("romsize", PCIDevice, romsize, UINT32_MAX),
     DEFINE_PROP_INT32("rombar",  PCIDevice, rom_bar, -1),
+    DEFINE_PROP_SIZE("fixed-bar-0", PCIDevice, fixed_bar_addr[0],
 PCI_BAR_UNMAPPED),
+    DEFINE_PROP_SIZE("fixed-bar-1", PCIDevice, fixed_bar_addr[1],
 PCI_BAR_UNMAPPED),
+    DEFINE_PROP_SIZE("fixed-bar-2", PCIDevice, fixed_bar_addr[2],
 PCI_BAR_UNMAPPED),
+    DEFINE_PROP_SIZE("fixed-bar-3", PCIDevice, fixed_bar_addr[3],
Quoted 5 lines

PCI_BAR_UNMAPPED),
+ DEFINE_PROP_SIZE("fixed-bar-4", PCIDevice, fixed_bar_addr[4],
PCI_BAR_UNMAPPED),
+ DEFINE_PROP_SIZE("fixed-bar-5", PCIDevice, fixed_bar_addr[5],
PCI_BAR_UNMAPPED),

These properties are exposed on all PCI devices, but only virt wires up the validation and fw_cfg export in this series. On other machines, a valid request would be accepted without placing the BAR, right?

I think it is better we add a mechanism(MachineClass flag ?) and check that.

Thanks,
Shameer

Quoted 75 lines

DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present,
QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false),
DEFINE_PROP_BIT("x-pcie-lnksta-dllla", PCIDevice, cap_present,

hw/pci/pci.c +37 -0
@@ -228,6 +234,36 @@ static void pci_bus_unrealize(BusState *qbus)
     vmstate_unregister(NULL, &vmstate_pcibus, bus);
 }
 
+static void pci_check_fixed_bars(PCIDevice *pci_dev, Error **errp)
+{
+    PCIIORegion *r;
+    int i;
+
+    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+        if (pci_dev->fixed_bar_addr[i] == PCI_BAR_UNMAPPED) {
+            continue;
+        }
+
+        if (DEVICE(pci_dev)->hotplugged) {
+            error_setg(errp, "fixed-bar-%d is not supported on "
+                       "hot-plugged devices", i);
+            return;
+        }
+
+        r = &pci_dev->io_regions[i];
+        if (!r->size) {
+            error_setg(errp, "fixed-bar-%d: bar%d does not exist on %s",
+                       i, i, pci_dev->name);
+            return;
+        }
+        if (r->type & PCI_BASE_ADDRESS_SPACE_IO) {
+            error_setg(errp, "fixed-bar-%d: bar%d on %s is an I/O BAR, "
+                       "not a memory BAR", i, i, pci_dev->name);
+            return;
+        }
+    }
+}
+
 static int pcibus_num(PCIBus *bus)
 {
     if (pci_bus_is_root(bus)) {
@@ -2393,6 +2429,13 @@ static void pci_qdev_realize(DeviceState *qdev,
 Error **errp)
         is_default_rom = true;
     }
 
+    pci_check_fixed_bars(pci_dev, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        pci_qdev_unrealize(DEVICE(pci_dev));
+        return;
+    }
+
     pci_add_option_rom(pci_dev, is_default_rom, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
include/hw/pci/pci_device.h +7 -1
index 5cac6e1688..fc5f50a1c4 100644
@@ -187,6 +187,13 @@ struct PCIDevice {
     uint32_t max_bounce_buffer_size;
 
     char *sriov_pf;
+
+    /*
+     * fixed_bar_addr[N] holds the guest address configured via the
+     * fixed-bar-N property for memory BAR N. PCI_BAR_UNMAPPED means
+     * the BAR's address is not fixed.
+     */
+    uint64_t  fixed_bar_addr[PCI_NUM_REGIONS - 1];
 };
 
 static inline int pci_intx(PCIDevice *pci_dev)
--

2.34.1

#3 lore raw

Re: [PATCH 1/5] hw/pci: introduce PCI fixed BAR properties

Quoted 42 lines · Shameer Kolothum Thodi
Quoted 42 lines

-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 16 September 2026 19:56
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 1/5] hw/pci: introduce PCI fixed BAR properties

Add fixed-bar-N properties to PCIDevice to allow the guest address of an individual PCI BAR to be explicitly specified. The properties are available for PCI BARs 0 through 5 and accept QEMU size values, for example fixed-bar-0=0x40000000 or fixed-bar-0=64G.

e.g.
-device some-device,fixed-bar-0=<addr>[,fixed-bar-1=<addr>]...

During realize, validate that each specified BAR exists and is a memory BAR, and reject fixed BAR configuration for hot-plugged devices.

---
 hw/pci/pci.c                | 43 +++++++++++++++++++++++++++++++++++++
 include/hw/pci/pci_device.h |  7 ++++++
 2 files changed, 50 insertions(+)
hw/pci/pci.c +2 -0
index 0efb4eb4bb..775fef1beb 100644
@@ -89,6 +89,12 @@ static const Property pci_props[] = {
     DEFINE_PROP_STRING("romfile", PCIDevice, romfile),
     DEFINE_PROP_UINT32("romsize", PCIDevice, romsize, UINT32_MAX),
     DEFINE_PROP_INT32("rombar",  PCIDevice, rom_bar, -1),
+    DEFINE_PROP_SIZE("fixed-bar-0", PCIDevice, fixed_bar_addr[0],
 PCI_BAR_UNMAPPED),
+    DEFINE_PROP_SIZE("fixed-bar-1", PCIDevice, fixed_bar_addr[1],
 PCI_BAR_UNMAPPED),
Quoted 9 lines
Quoted 8 lines
hw/pci/pci.c +2 -0
+    DEFINE_PROP_SIZE("fixed-bar-2", PCIDevice, fixed_bar_addr[2],
 PCI_BAR_UNMAPPED),
+    DEFINE_PROP_SIZE("fixed-bar-3", PCIDevice, fixed_bar_addr[3],

PCI_BAR_UNMAPPED),
+ DEFINE_PROP_SIZE("fixed-bar-4", PCIDevice, fixed_bar_addr[4],
PCI_BAR_UNMAPPED),
+ DEFINE_PROP_SIZE("fixed-bar-5", PCIDevice, fixed_bar_addr[5],
PCI_BAR_UNMAPPED),

Thank you for the review.

Quoted 3 lines

These properties are exposed on all PCI devices, but only virt wires up the validation and fw_cfg export in this series. On other machines, a valid request would be accepted without placing the BAR, right?

Yes.

Quoted 3 lines

I think it is better we add a mechanism(MachineClass flag ?) and check that.

Sure, I will add a MachineClass flag 'bool pci_fixed_bar_supported'

-Tushar

Quoted 80 lines

Thanks,
Shameer

Quoted 75 lines

DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present,
QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false),
DEFINE_PROP_BIT("x-pcie-lnksta-dllla", PCIDevice, cap_present,

hw/pci/pci.c +37 -0
@@ -228,6 +234,36 @@ static void pci_bus_unrealize(BusState *qbus)
     vmstate_unregister(NULL, &vmstate_pcibus, bus);
 }
 
+static void pci_check_fixed_bars(PCIDevice *pci_dev, Error **errp)
+{
+    PCIIORegion *r;
+    int i;
+
+    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+        if (pci_dev->fixed_bar_addr[i] == PCI_BAR_UNMAPPED) {
+            continue;
+        }
+
+        if (DEVICE(pci_dev)->hotplugged) {
+            error_setg(errp, "fixed-bar-%d is not supported on "
+                       "hot-plugged devices", i);
+            return;
+        }
+
+        r = &pci_dev->io_regions[i];
+        if (!r->size) {
+            error_setg(errp, "fixed-bar-%d: bar%d does not exist on %s",
+                       i, i, pci_dev->name);
+            return;
+        }
+        if (r->type & PCI_BASE_ADDRESS_SPACE_IO) {
+            error_setg(errp, "fixed-bar-%d: bar%d on %s is an I/O BAR, "
+                       "not a memory BAR", i, i, pci_dev->name);
+            return;
+        }
+    }
+}
+
 static int pcibus_num(PCIBus *bus)
 {
     if (pci_bus_is_root(bus)) {
@@ -2393,6 +2429,13 @@ static void pci_qdev_realize(DeviceState *qdev,
 Error **errp)
         is_default_rom = true;
     }
 
+    pci_check_fixed_bars(pci_dev, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        pci_qdev_unrealize(DEVICE(pci_dev));
+        return;
+    }
+
     pci_add_option_rom(pci_dev, is_default_rom, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
include/hw/pci/pci_device.h +7 -1
index 5cac6e1688..fc5f50a1c4 100644
@@ -187,6 +187,13 @@ struct PCIDevice {
     uint32_t max_bounce_buffer_size;
 
     char *sriov_pf;
+
+    /*
+     * fixed_bar_addr[N] holds the guest address configured via the
+     * fixed-bar-N property for memory BAR N. PCI_BAR_UNMAPPED means
+     * the BAR's address is not fixed.
+     */
+    uint64_t  fixed_bar_addr[PCI_NUM_REGIONS - 1];
 };
 
 static inline int pci_intx(PCIDevice *pci_dev)
--

2.34.1

#4 lore raw

PATCH 2/5 pci: add validation for fixed BAR configuration

In reply to Tushar Dave

Validate the fixed BAR configuration specified through the fixed-bar-N properties on PCI endpoint devices.

Configuring any fixed-bar-N property on an endpoint device requires every memory BAR on that device to have a fixed address. Validate that each assigned address:

- is aligned to its BAR size;
- is within the appropriate PCIe MMIO aperture; and
- does not overlap any other fixed BAR.

Under a PCIe topology with a root port, fixed BAR placement is all-or-nothing within that root port's subtree. If any one endpoint device below the root port has a fixed BAR, every other endpoint device below that same root port with a memory BAR must have all of its memory BARs fixed too.

Endpoint devices with no root port in their ancestry, such as those attached directly to the host bridge, are not required to match their sibling devices. One such device may use fixed-bar-N for all of its memory BARs while another sibling device on the same host bridge uses none at all. Per-device completeness still applies regardless of ancestry. Once any fixed-bar-N property is set on a device, every memory BAR on that device must be fixed.

Abort QEMU if any validation fails.

---
 hw/pci/meson.build              |   1 +
 hw/pci/pci-fixed-bar-validate.c | 326 ++++++++++++++++++++++++++++++++
 hw/pci/pci-fixed-bar-validate.h |  21 ++
 3 files changed, 348 insertions(+)
 create mode 100644 hw/pci/pci-fixed-bar-validate.c
 create mode 100644 hw/pci/pci-fixed-bar-validate.h
hw/pci/meson.build +1 -0
index 984c7327e5..150085c997 100644
@@ -19,6 +19,7 @@ endif
 pci_ss.add(files('pcie.c', 'pcie_aer.c'))
 pci_ss.add(files('pcie_doe.c'))
 system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pcie_port.c', 'pcie_host.c'))
+system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pci-fixed-bar-validate.c'))
 system_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss)
 
 stub_ss.add(files('pci-stub.c'))
hw/pci/pci-fixed-bar-validate.c new file +326 -0

326 lines not on this page · raw message

hw/pci/pci-fixed-bar-validate.h new file +21 -0
new file mode 100644
index 0000000000..297d1480c0
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved
+ *
+ * Written by Tushar Dave
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef HW_PCI_FIXED_BAR_VALIDATE_H
+#define HW_PCI_FIXED_BAR_VALIDATE_H
+
+typedef struct {
+    bool      any_fixed;
+    uint64_t  mmio32_base;
+    uint64_t  mmio32_limit;
+    uint64_t  mmio64_base;
+    uint64_t  mmio64_limit;
+} FixedBarsInfo;
+
+bool fixed_bars_validate(FixedBarsInfo *info);
+
+#endif /* HW_PCI_FIXED_BAR_VALIDATE_H */
Signature · 1 line
2.34.1
#5 lore raw

RE: [PATCH 2/5] pci: add validation for fixed BAR configuration

Quoted 93 lines

-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 16 September 2026 19:56
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 2/5] pci: add validation for fixed BAR configuration

Validate the fixed BAR configuration specified through the fixed-bar-N properties on PCI endpoint devices.

Configuring any fixed-bar-N property on an endpoint device requires every memory BAR on that device to have a fixed address. Validate that each assigned address:

- is aligned to its BAR size;
- is within the appropriate PCIe MMIO aperture; and
- does not overlap any other fixed BAR.

Under a PCIe topology with a root port, fixed BAR placement is all-or-nothing within that root port's subtree. If any one endpoint device below the root port has a fixed BAR, every other endpoint device below that same root port with a memory BAR must have all of its memory BARs fixed too.

Endpoint devices with no root port in their ancestry, such as those attached directly to the host bridge, are not required to match their sibling devices. One such device may use fixed-bar-N for all of its memory BARs while another sibling device on the same host bridge uses none at all. Per-device completeness still applies regardless of ancestry. Once any fixed-bar-N property is set on a device, every memory BAR on that device must be fixed.

Abort QEMU if any validation fails.

---
 hw/pci/meson.build              |   1 +
 hw/pci/pci-fixed-bar-validate.c | 326
++++++++++++++++++++++++++++++++
 hw/pci/pci-fixed-bar-validate.h |  21 ++
 3 files changed, 348 insertions(+)
 create mode 100644 hw/pci/pci-fixed-bar-validate.c
 create mode 100644 hw/pci/pci-fixed-bar-validate.h
hw/pci/meson.build +1 -0
index 984c7327e5..150085c997 100644
@@ -19,6 +19,7 @@ endif
 pci_ss.add(files('pcie.c', 'pcie_aer.c'))
 pci_ss.add(files('pcie_doe.c'))
 system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pcie_port.c',
 'pcie_host.c'))
+system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pci-fixed-bar-
 validate.c'))
 system_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss)

stub_ss.add(files('pci-stub.c'))

hw/pci/pci-fixed-bar-validate.c new file +2 -0
new file mode 100644
index 0000000000..0b5baad8a0
@@ -0,0 +1,326 @@
+/*
+ * Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights

reserved
+ * BAR address validation for fixed-BAR placement.
+ *
+ * Written by Tushar Dave
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

hw/pci/pci-fixed-bar-validate.c new file +15 -0
+
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+#include "hw/pci/pci_bridge.h"
+#include "hw/pci/pci_host.h"
+#include "hw/pci/pcie_port.h"
+#include "qemu/error-report.h"
+#include "qemu/range.h"
+#include "qemu/units.h"
+#include "pci-internal.h"
+#include "pci-fixed-bar-validate.h"
+
+/*
+ * Claimed BAR ranges — detect inter-device and inter-hierarchy overlaps
+ * across all fixed BARs system-wide.

hw/pci/pci-fixed-bar-validate.c line 33

Quoted 10 lines
hw/pci/pci-fixed-bar-validate.c new file +10 -0
+ */
+
+typedef struct {
+    uint64_t    start;
+    uint64_t    end;
+    const char *owner;  /* device name, for error messages */
+    int         bar;
+} FixedClaim;
+
+static GArray *fixed_claims;

Can this live in the FixedBarsInfo instead? IIUC, the info context is already passed through the walk, and the claims only need to exist for that validation pass?

Quoted 141 lines
hw/pci/pci-fixed-bar-validate.c new file +52 -0
+
+static void fixed_claims_init(void)
+{
+    if (fixed_claims) {
+        g_array_free(fixed_claims, true);
+    }
+    fixed_claims = g_array_new(false, true, sizeof(FixedClaim));
+}
+
+static void fixed_claims_free(void)
+{
+    g_array_free(fixed_claims, true);
+    fixed_claims = NULL;
+}
+
+static bool fixed_claims_overlap(uint64_t start, uint64_t end,
+                                 const char **owner_out, int *bar_out,
+                                 uint64_t *start_out, uint64_t *end_out)
+{
+    FixedClaim *c;
+    guint i;
+
+    for (i = 0; i < fixed_claims->len; i++) {
+        c = &g_array_index(fixed_claims, FixedClaim, i);
+        if (ranges_overlap(start, end - start + 1,
+                           c->start, c->end - c->start + 1)) {
+            *owner_out = c->owner;
+            *bar_out   = c->bar;
+            *start_out = c->start;
+            *end_out   = c->end;
+            return true;
+        }
+    }
+    return false;
+}
+
+static void fixed_claims_add(uint64_t start, uint64_t end,
+                             const char *owner, int bar)
+{
+    FixedClaim cl;
+
+    cl.start = start;
+    cl.end   = end;
+    cl.owner = owner;
+    cl.bar   = bar;
+    g_array_append_val(fixed_claims, cl);
+}
+
+static bool validate_bars(PCIDevice *pdev, FixedBarsInfo *info,
+                          bool is_fixed_subtree)
+{
+    const char  *devname = DEVICE(pdev)->id ? DEVICE(pdev)->id : pdev-
Quoted 1 line

name;

hw/pci/pci-fixed-bar-validate.c new file +88 -0
+    const char  *overlap_owner;
+    const char  *wname;
+    bool         has_fixed_bars = false;
+    bool         is_64bit;
+    uint64_t     addr, end, wbase, wlim, overlap_start, overlap_end;
+    PCIIORegion *r;
+    int          overlap_bar;
+    int          i;
+
+    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+        if (pdev->fixed_bar_addr[i] != PCI_BAR_UNMAPPED) {
+            has_fixed_bars = true;
+            break;
+        }
+    }
+
+    if (is_fixed_subtree && !has_fixed_bars) {
+        error_report("fixed-bar: %s [%02x:%02x.%x] under fixed-bar root "
+                     "port has memory BARs but no fixed-bar-N= specified",
+                     devname, pci_dev_bus_num(pdev),
+                     PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
+        exit(1);
+    }
+
+    if (!has_fixed_bars) {
+        return false;
+    }
+
+    /* Completeness: every memory BAR must have an address. */
+    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+        r = &pdev->io_regions[i];
+        if (!r->size || (r->type & PCI_BASE_ADDRESS_SPACE_IO)) {
+            continue;
+        }
+        if (pdev->fixed_bar_addr[i] == PCI_BAR_UNMAPPED) {
+            error_report("fixed-bar: %s [%02x:%02x.%x] BAR%d "
+                         "missing a fixed-bar-N= value",
+                         devname, pci_dev_bus_num(pdev),
+                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), i);
+            exit(1);
+        }
+    }
+
+    /* Per-BAR checks: alignment, MMIO window, overlap. */
+    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+        r = &pdev->io_regions[i];
+        if (!r->size || (r->type & PCI_BASE_ADDRESS_SPACE_IO)) {
+            continue;
+        }
+
+        is_64bit = !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64);
+        addr     = (uint64_t)pdev->fixed_bar_addr[i];
+
+        if (r->size - 1 > UINT64_MAX - addr) {
+            error_report("fixed-bar: %s [%02x:%02x.%x] BAR%d "
+                         "addr=0x%"PRIx64" + size=0x%"PRIx64" overflows",
+                         devname, pci_dev_bus_num(pdev),
+                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
+                         i, addr, r->size);
+            exit(1);
+        }
+        end = addr + r->size - 1;
+
+        if (is_64bit && !(r->type & PCI_BASE_ADDRESS_MEM_PREFETCH) &&
+            !pci_bus_is_root(pci_get_bus(pdev)) && addr >= 4 * GiB) {
+            error_report("fixed-bar: %s [%02x:%02x.%x] BAR%d is a "
+                         "non-prefetchable 64-bit BAR behind a PCI bridge "
+                         "and cannot be placed above 4GB",
+                         devname, pci_dev_bus_num(pdev),
+                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), i);
+            exit(1);
+        }
+
+        /*
+         * wbase/wlim are both inclusive bounds (mmio*_limit = base+size-1,
+         * set by the caller alongside mmio*_base), matching end's own
+         * inclusive computation above.
+         */
+        if (is_64bit) {
+            wbase = info->mmio64_base;
+            wlim  = info->mmio64_limit;
+            wname = "64-bit MMIO";
+        } else {
+            wbase = info->mmio32_base;
+            wlim  = info->mmio32_limit;
+            wname = "32-bit MMIO";
+        }
+

hw/pci/pci-fixed-bar-validate.c line 183

Quoted 10 lines
hw/pci/pci-fixed-bar-validate.c new file +10 -0
+        if (addr & (r->size - 1)) {
+            error_report("fixed-bar: %s [%02x:%02x.%x] BAR%d "
+                         "addr=0x%"PRIx64" not aligned to size=0x%"PRIx64,
+                         devname, pci_dev_bus_num(pdev),
+                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
+                         i, addr, r->size);
+            exit(1);
+        }
+
+        if (addr < wbase || end > wlim) {

This will reject a 64-bit BAR whose requested address falls within the low MMIO aperture. That is a valid placement, right?

Is restricting 64-bit BARs to the high aperture intentional?

Quoted 9 lines
hw/pci/pci-fixed-bar-validate.c new file +9 -0
+            error_report("fixed-bar: %s [%02x:%02x.%x] BAR%d "
+                         "[0x%"PRIx64"..0x%"PRIx64"] outside %s window "
+                         "[0x%"PRIx64"..0x%"PRIx64"]",
+                         devname, pci_dev_bus_num(pdev),
+                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
+                         i, addr, end, wname, wbase, wlim);
+            exit(1);
+        }
+

hw/pci/pci-fixed-bar-validate.c line 202

Quoted 10 lines
hw/pci/pci-fixed-bar-validate.c new file +10 -0
+        if (fixed_claims_overlap(addr, end, &overlap_owner, &overlap_bar,
+                                 &overlap_start, &overlap_end)) {
+            error_report("fixed-bar: %s [%02x:%02x.%x] BAR%d "
+                         "[0x%"PRIx64"..0x%"PRIx64"] overlaps %s BAR%d "
+                         "[0x%"PRIx64"..0x%"PRIx64"]",
+                         devname, pci_dev_bus_num(pdev),
+                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
+                         i, addr, end, overlap_owner, overlap_bar,
+                         overlap_start, overlap_end);
+            exit(1);

May be better if we could pass an Error **errp through the helpers instead of calling exit(1) here and let the machine code handle the error?

Thanks,
Shameer

#6 lore raw

Re: [PATCH 2/5] pci: add validation for fixed BAR configuration

Quoted 99 lines · Shameer Kolothum Thodi
Quoted 99 lines

-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 16 September 2026 19:56
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 2/5] pci: add validation for fixed BAR configuration

Validate the fixed BAR configuration specified through the fixed-bar-N properties on PCI endpoint devices.

Configuring any fixed-bar-N property on an endpoint device requires every memory BAR on that device to have a fixed address. Validate that each assigned address:

- is aligned to its BAR size;
- is within the appropriate PCIe MMIO aperture; and
- does not overlap any other fixed BAR.

Under a PCIe topology with a root port, fixed BAR placement is all-or-nothing within that root port's subtree. If any one endpoint device below the root port has a fixed BAR, every other endpoint device below that same root port with a memory BAR must have all of its memory BARs fixed too.

Endpoint devices with no root port in their ancestry, such as those attached directly to the host bridge, are not required to match their sibling devices. One such device may use fixed-bar-N for all of its memory BARs while another sibling device on the same host bridge uses none at all. Per-device completeness still applies regardless of ancestry. Once any fixed-bar-N property is set on a device, every memory BAR on that device must be fixed.

Abort QEMU if any validation fails.

---
 hw/pci/meson.build              |   1 +
 hw/pci/pci-fixed-bar-validate.c | 326
++++++++++++++++++++++++++++++++
 hw/pci/pci-fixed-bar-validate.h |  21 ++
 3 files changed, 348 insertions(+)
 create mode 100644 hw/pci/pci-fixed-bar-validate.c
 create mode 100644 hw/pci/pci-fixed-bar-validate.h
hw/pci/meson.build +1 -0
index 984c7327e5..150085c997 100644
@@ -19,6 +19,7 @@ endif
 pci_ss.add(files('pcie.c', 'pcie_aer.c'))
 pci_ss.add(files('pcie_doe.c'))
 system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pcie_port.c',
 'pcie_host.c'))
+system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pci-fixed-bar-
 validate.c'))
 system_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss)

stub_ss.add(files('pci-stub.c'))

hw/pci/pci-fixed-bar-validate.c new file +2 -0
new file mode 100644
index 0000000000..0b5baad8a0
@@ -0,0 +1,326 @@
+/*
+ * Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights

reserved
+ * BAR address validation for fixed-BAR placement.
+ *
+ * Written by Tushar Dave
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

hw/pci/pci-fixed-bar-validate.c new file +21 -0
+
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+#include "hw/pci/pci_bridge.h"
+#include "hw/pci/pci_host.h"
+#include "hw/pci/pcie_port.h"
+#include "qemu/error-report.h"
+#include "qemu/range.h"
+#include "qemu/units.h"
+#include "pci-internal.h"
+#include "pci-fixed-bar-validate.h"
+
+/*
+ * Claimed BAR ranges — detect inter-device and inter-hierarchy overlaps
+ * across all fixed BARs system-wide.
+ */
+
+typedef struct {
+    uint64_t    start;
+    uint64_t    end;
+    const char *owner;  /* device name, for error messages */
Quoted 8 lines

hw/pci/pci-fixed-bar-validate.c line 33

Quoted 4 lines
hw/pci/pci-fixed-bar-validate.c new file +4 -0
+    int         bar;
+} FixedClaim;
+
+static GArray *fixed_claims;

Can this live in the FixedBarsInfo instead? IIUC, the info context is already passed through the walk, and the claims only need to exist for that validation pass?

Sure.

Quoted 156 lines
Quoted 142 lines
hw/pci/pci-fixed-bar-validate.c new file +52 -0
+
+static void fixed_claims_init(void)
+{
+    if (fixed_claims) {
+        g_array_free(fixed_claims, true);
+    }
+    fixed_claims = g_array_new(false, true, sizeof(FixedClaim));
+}
+
+static void fixed_claims_free(void)
+{
+    g_array_free(fixed_claims, true);
+    fixed_claims = NULL;
+}
+
+static bool fixed_claims_overlap(uint64_t start, uint64_t end,
+                                 const char **owner_out, int *bar_out,
+                                 uint64_t *start_out, uint64_t *end_out)
+{
+    FixedClaim *c;
+    guint i;
+
+    for (i = 0; i < fixed_claims->len; i++) {
+        c = &g_array_index(fixed_claims, FixedClaim, i);
+        if (ranges_overlap(start, end - start + 1,
+                           c->start, c->end - c->start + 1)) {
+            *owner_out = c->owner;
+            *bar_out   = c->bar;
+            *start_out = c->start;
+            *end_out   = c->end;
+            return true;
+        }
+    }
+    return false;
+}
+
+static void fixed_claims_add(uint64_t start, uint64_t end,
+                             const char *owner, int bar)
+{
+    FixedClaim cl;
+
+    cl.start = start;
+    cl.end   = end;
+    cl.owner = owner;
+    cl.bar   = bar;
+    g_array_append_val(fixed_claims, cl);
+}
+
+static bool validate_bars(PCIDevice *pdev, FixedBarsInfo *info,
+                          bool is_fixed_subtree)
+{
+    const char  *devname = DEVICE(pdev)->id ? DEVICE(pdev)->id : pdev-
Quoted 1 line

name;

hw/pci/pci-fixed-bar-validate.c new file +88 -0
+    const char  *overlap_owner;
+    const char  *wname;
+    bool         has_fixed_bars = false;
+    bool         is_64bit;
+    uint64_t     addr, end, wbase, wlim, overlap_start, overlap_end;
+    PCIIORegion *r;
+    int          overlap_bar;
+    int          i;
+
+    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+        if (pdev->fixed_bar_addr[i] != PCI_BAR_UNMAPPED) {
+            has_fixed_bars = true;
+            break;
+        }
+    }
+
+    if (is_fixed_subtree && !has_fixed_bars) {
+        error_report("fixed-bar: %s [%02x:%02x.%x] under fixed-bar root "
+                     "port has memory BARs but no fixed-bar-N= specified",
+                     devname, pci_dev_bus_num(pdev),
+                     PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
+        exit(1);
+    }
+
+    if (!has_fixed_bars) {
+        return false;
+    }
+
+    /* Completeness: every memory BAR must have an address. */
+    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+        r = &pdev->io_regions[i];
+        if (!r->size || (r->type & PCI_BASE_ADDRESS_SPACE_IO)) {
+            continue;
+        }
+        if (pdev->fixed_bar_addr[i] == PCI_BAR_UNMAPPED) {
+            error_report("fixed-bar: %s [%02x:%02x.%x] BAR%d "
+                         "missing a fixed-bar-N= value",
+                         devname, pci_dev_bus_num(pdev),
+                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), i);
+            exit(1);
+        }
+    }
+
+    /* Per-BAR checks: alignment, MMIO window, overlap. */
+    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+        r = &pdev->io_regions[i];
+        if (!r->size || (r->type & PCI_BASE_ADDRESS_SPACE_IO)) {
+            continue;
+        }
+
+        is_64bit = !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64);
+        addr     = (uint64_t)pdev->fixed_bar_addr[i];
+
+        if (r->size - 1 > UINT64_MAX - addr) {
+            error_report("fixed-bar: %s [%02x:%02x.%x] BAR%d "
+                         "addr=0x%"PRIx64" + size=0x%"PRIx64" overflows",
+                         devname, pci_dev_bus_num(pdev),
+                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
+                         i, addr, r->size);
+            exit(1);
+        }
+        end = addr + r->size - 1;
+
+        if (is_64bit && !(r->type & PCI_BASE_ADDRESS_MEM_PREFETCH) &&
+            !pci_bus_is_root(pci_get_bus(pdev)) && addr >= 4 * GiB) {
+            error_report("fixed-bar: %s [%02x:%02x.%x] BAR%d is a "
+                         "non-prefetchable 64-bit BAR behind a PCI bridge "
+                         "and cannot be placed above 4GB",
+                         devname, pci_dev_bus_num(pdev),
+                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), i);
+            exit(1);
+        }
+
+        /*
+         * wbase/wlim are both inclusive bounds (mmio*_limit = base+size-1,
+         * set by the caller alongside mmio*_base), matching end's own
+         * inclusive computation above.
+         */
+        if (is_64bit) {
+            wbase = info->mmio64_base;
+            wlim  = info->mmio64_limit;
+            wname = "64-bit MMIO";
+        } else {
+            wbase = info->mmio32_base;
+            wlim  = info->mmio32_limit;
+            wname = "32-bit MMIO";
+        }
+

hw/pci/pci-fixed-bar-validate.c line 183

Quoted 10 lines
hw/pci/pci-fixed-bar-validate.c new file +10 -0
+        if (addr & (r->size - 1)) {
+            error_report("fixed-bar: %s [%02x:%02x.%x] BAR%d "
+                         "addr=0x%"PRIx64" not aligned to size=0x%"PRIx64,
+                         devname, pci_dev_bus_num(pdev),
+                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
+                         i, addr, r->size);
+            exit(1);
+        }
+
+        if (addr < wbase || end > wlim) {

This will reject a 64-bit BAR whose requested address falls within the low MMIO aperture. That is a valid placement, right?

Quoted 1 line

Is restricting 64-bit BARs to the high aperture intentional?

We shouldn't have to. I will amend this in V2.

Quoted 21 lines
Quoted 10 lines
hw/pci/pci-fixed-bar-validate.c new file +9 -0
+            error_report("fixed-bar: %s [%02x:%02x.%x] BAR%d "
+                         "[0x%"PRIx64"..0x%"PRIx64"] outside %s window "
+                         "[0x%"PRIx64"..0x%"PRIx64"]",
+                         devname, pci_dev_bus_num(pdev),
+                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
+                         i, addr, end, wname, wbase, wlim);
+            exit(1);
+        }
+

hw/pci/pci-fixed-bar-validate.c line 202

Quoted 10 lines
hw/pci/pci-fixed-bar-validate.c new file +10 -0
+        if (fixed_claims_overlap(addr, end, &overlap_owner, &overlap_bar,
+                                 &overlap_start, &overlap_end)) {
+            error_report("fixed-bar: %s [%02x:%02x.%x] BAR%d "
+                         "[0x%"PRIx64"..0x%"PRIx64"] overlaps %s BAR%d "
+                         "[0x%"PRIx64"..0x%"PRIx64"]",
+                         devname, pci_dev_bus_num(pdev),
+                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
+                         i, addr, end, overlap_owner, overlap_bar,
+                         overlap_start, overlap_end);
+            exit(1);
Quoted 2 lines

May be better if we could pass an Error **errp through the helpers instead of calling exit(1) here and let the machine code handle the error?

Yes.

Thanks.
-Tushar

Quoted 3 lines

Thanks,
Shameer

#7 lore raw

PATCH 3/5 pci: add fixed BAR fw_cfg blob export

In reply to Tushar Dave

Introduce a fixed BAR fw_cfg blob exporter that serializes PCI device and BAR information into the "etc/fixed-bars" fw_cfg file.

The blob contains an entry for every PCI function with memory BARs. Each entry carries the device's vendor and device ID, whether it has a fixed BAR configuration, and its firmware device path. Fixed BAR entries also include the configured BAR address, size, and type information for each BAR.

---
 hw/pci/meson.build          |   1 +
 hw/pci/pci-fixed-bar-blob.c | 305 ++++++++++++++++++++++++++++++++++++
 hw/pci/pci-fixed-bar.h      |  63 ++++++++
 3 files changed, 369 insertions(+)
 create mode 100644 hw/pci/pci-fixed-bar-blob.c
 create mode 100644 hw/pci/pci-fixed-bar.h
hw/pci/meson.build +1 -0
index 150085c997..b81cc056c0 100644
@@ -20,6 +20,7 @@ pci_ss.add(files('pcie.c', 'pcie_aer.c'))
 pci_ss.add(files('pcie_doe.c'))
 system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pcie_port.c', 'pcie_host.c'))
 system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pci-fixed-bar-validate.c'))
+system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pci-fixed-bar-blob.c'))
 system_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss)
 
 stub_ss.add(files('pci-stub.c'))
hw/pci/pci-fixed-bar-blob.c new file +305 -0

305 lines not on this page · raw message

hw/pci/pci-fixed-bar.h new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
2.34.1
#8 lore raw

RE: [PATCH 3/5] pci: add fixed BAR fw_cfg blob export

Quoted 213 lines

-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 16 September 2026 19:56
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 3/5] pci: add fixed BAR fw_cfg blob export

Introduce a fixed BAR fw_cfg blob exporter that serializes PCI device and BAR information into the "etc/fixed-bars" fw_cfg file.

The blob contains an entry for every PCI function with memory BARs. Each entry carries the device's vendor and device ID, whether it has a fixed BAR configuration, and its firmware device path. Fixed BAR entries also include the configured BAR address, size, and type information for each BAR.

---
 hw/pci/meson.build          |   1 +
 hw/pci/pci-fixed-bar-blob.c | 305
++++++++++++++++++++++++++++++++++++
 hw/pci/pci-fixed-bar.h      |  63 ++++++++
 3 files changed, 369 insertions(+)
 create mode 100644 hw/pci/pci-fixed-bar-blob.c
 create mode 100644 hw/pci/pci-fixed-bar.h
hw/pci/meson.build +1 -0
index 150085c997..b81cc056c0 100644
@@ -20,6 +20,7 @@ pci_ss.add(files('pcie.c', 'pcie_aer.c'))
 pci_ss.add(files('pcie_doe.c'))
 system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pcie_port.c',
 'pcie_host.c'))
 system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pci-fixed-bar-
 validate.c'))
+system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pci-fixed-bar-
 blob.c'))

system_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss)

stub_ss.add(files('pci-stub.c'))

hw/pci/pci-fixed-bar-blob.c new file +2 -0
new file mode 100644
index 0000000000..b9fdc6b7d4
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights

reserved
+ * Write validated fixed-BAR device info to the etc/fixed-bars fw_cfg blob.
+ *
+ * Written by Tushar Dave
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

hw/pci/pci-fixed-bar-blob.c new file +45 -0
+
+#include "qemu/osdep.h"
+#include "hw/nvram/fw_cfg.h"
+#include "hw/pci/pci.h"
+#include "hw/pci/pci_bridge.h"
+#include "hw/pci/pci_host.h"
+#include "hw/pci/pcie_port.h"
+#include "hw/core/qdev.h"
+#include "qemu/error-report.h"
+#include "pci-internal.h"
+#include "pci-fixed-bar.h"
+#include "pci-fixed-bar-validate.h"
+
+typedef struct {
+    uint8_t  bar;
+    uint32_t flags;
+    uint64_t addr;
+    uint64_t size;
+} BarInfo;
+
+/* One PCI function entry to be written to the blob. */
+typedef struct {
+    uint8_t  rp_bus;     /* primary bus of the root port this device is under */
+    uint16_t vendor_id;
+    uint16_t device_id;
+    bool     is_fixed;
+    char     fw_path[QEMU_FIXED_BARS_MAX_PATH];
+    GArray  *bars;  /* array of BarInfo */
+} DeviceInfo;
+
+typedef struct {
+    GArray *devices;
+    PCIBus *root_bus;
+} CollectCtx;
+
+static void collect_device(PCIBus *bus, PCIDevice *pdev, void *opaque);
+
+/* Visit every device on this bus, in devfn order. */
+static void collect_bus(PCIBus *bus, void *opaque)
+{
+    pci_for_each_device_under_bus(bus, collect_device, opaque);
+}
+
+/*
+ * Primary bus number of the nearest TYPE_PCIE_ROOT_PORT ancestor of

bus
+ * — i.e. the bus the root port device itself lives on, not its
+ * secondary bus. Falls back to the host bridge's own bus number if bus
+ * isn't under any root port (e.g. a device directly on the host
+ * bridge's primary bus).
+ */

hw/pci/pci-fixed-bar-blob.c new file +101 -0
+static uint8_t find_root_port_bus(PCIBus *bus, PCIBus *host_bus)
+{
+    PCIDevice *parent;
+
+    while (bus) {
+        parent = bus->parent_dev;
+        if (!parent) {
+            break;
+        }
+        if (object_dynamic_cast(OBJECT(parent), TYPE_PCIE_ROOT_PORT)) {
+            return pci_bus_num(pci_get_bus(parent));
+        }
+        bus = pci_get_bus(parent);
+    }
+    return pci_bus_num(host_bus);
+}
+
+static void collect_device(PCIBus *bus, PCIDevice *pdev, void *opaque)
+{
+    CollectCtx *ctx = opaque;
+    bool has_mem_bar = false;
+    bool is_64bit, is_pref;
+    DeviceInfo dev;
+    PCIIORegion *r;
+    PCIBus *sec;
+    BarInfo bi;
+    int i;
+
+    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+        r = &pdev->io_regions[i];
+        if (r->size && !(r->type & PCI_BASE_ADDRESS_SPACE_IO)) {
+            has_mem_bar = true;
+            break;
+        }
+    }
+
+    /*
+     * Every device with a memory BAR gets an entry, fixed or not — not
+     * just ones with fixed-bar-N= set. This preserves the exact device
+     * sequence CheckDevice() needs for positional VID:DID matching (see
+     * collect_all_host_bridges()); only fixed devices carry BAR records
+     * (dev.bars stays empty, dev.is_fixed false, otherwise).
+     */
+    if (has_mem_bar) {
+        g_autofree char *fw_path = qdev_get_fw_dev_path(DEVICE(pdev));
+
+        memset(&dev, 0, sizeof(dev));
+        dev.rp_bus    = find_root_port_bus(bus, ctx->root_bus);
+        dev.vendor_id = pci_get_word(pdev->config + PCI_VENDOR_ID);
+        dev.device_id = pci_get_word(pdev->config + PCI_DEVICE_ID);
+        dev.is_fixed  = false;
+        for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+            if (pdev->fixed_bar_addr[i] != PCI_BAR_UNMAPPED) {
+                dev.is_fixed = true;
+                break;
+            }
+        }
+        if (fw_path) {
+            g_strlcpy(dev.fw_path, fw_path, sizeof(dev.fw_path));
+        }
+        dev.bars = g_array_new(false, true, sizeof(BarInfo));
+
+        if (dev.is_fixed) {
+            for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+                r = &pdev->io_regions[i];
+                if (!r->size || (r->type & PCI_BASE_ADDRESS_SPACE_IO)) {
+                    continue;
+                }
+                is_64bit = !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64);
+                is_pref  = !!(r->type & PCI_BASE_ADDRESS_MEM_PREFETCH);
+
+                memset(&bi, 0, sizeof(bi));
+                bi.bar   = i;
+                bi.addr  = (uint64_t)pdev->fixed_bar_addr[i];
+                bi.size  = r->size;
+                bi.flags = (is_64bit ? QEMU_FIXED_BAR_F_MEM64 : 0) |
+                           (is_pref  ? QEMU_FIXED_BAR_F_PREF  : 0);
+                g_array_append_val(dev.bars, bi);
+            }
+        }
+        g_array_append_val(ctx->devices, dev);
+    }
+
+    if (!object_dynamic_cast(OBJECT(pdev), TYPE_PCI_BRIDGE)) {
+        return;
+    }
+    sec = pci_bridge_get_sec_bus(PCI_BRIDGE(pdev));
+    if (sec) {
+        collect_bus(sec, opaque);
+    }
+}
+
+static gint cmp_host_bus_num(gconstpointer a, gconstpointer b)
+{
+    PCIHostState *ha = *(PCIHostState **)a;
+    PCIHostState *hb = *(PCIHostState **)b;
+    return (gint)pci_bus_num(ha->bus) - (gint)pci_bus_num(hb->bus);
+}
+
+/*
+ * EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL's CheckDevice
Quoted 7 lines

interface
+ * (UEFI PI Spec 1.2 Vol 5) only passes VendorId/DeviceId/RevisionId/
+ * SubsystemVendorId/SubsystemDeviceId, no BDF — so in EDK2 we can't
+ * match a blob entry to a specific device directly using BDF. To work
+ * around that, we prepare the blob entries in the same order PciBusDxe
+ * discovers devices, so matching by VID:DID inherently works.
+ */

The blob now also includes firmware device paths for future matching, right? Should we mention that as well?

Quoted 165 lines
hw/pci/pci-fixed-bar-blob.c new file +79 -0
+static void collect_all_host_bridges(CollectCtx *ctx)
+{
+    PCIHostState *hb;
+    GPtrArray *sorted;
+    guint i;
+
+    sorted = g_ptr_array_new();
+    QLIST_FOREACH(hb, &pci_host_bridges, next) {
+        if (hb->bus) {
+            g_ptr_array_add(sorted, hb);
+        }
+    }
+    g_ptr_array_sort(sorted, cmp_host_bus_num);
+
+    for (i = 0; i < sorted->len; i++) {
+        hb = g_ptr_array_index(sorted, i);
+        ctx->root_bus = hb->bus;
+        collect_bus(hb->bus, ctx);
+    }
+
+    g_ptr_array_free(sorted, true);
+}
+
+static uint8_t *create_blob(CollectCtx *ctx, size_t *blob_size)
+{
+    QemuFixedBarsDevice *dout;
+    QemuFixedBarsBar *bout;
+    QemuFixedBarsHdr *hdr;
+    DeviceInfo *dev;
+    uint8_t *blob;
+    uint8_t *ptr;
+    BarInfo *bi;
+    size_t sz;
+    guint d, b;
+
+    sz = sizeof(QemuFixedBarsHdr);
+    for (d = 0; d < ctx->devices->len; d++) {
+        dev = &g_array_index(ctx->devices, DeviceInfo, d);
+        sz += sizeof(QemuFixedBarsDevice);
+        sz += dev->bars->len * sizeof(QemuFixedBarsBar);
+    }
+
+    blob = g_malloc0(sz);
+    hdr  = (QemuFixedBarsHdr *)blob;
+    hdr->version     = cpu_to_le32(QEMU_FIXED_BARS_VERSION);
+    hdr->num_devices = cpu_to_le32(ctx->devices->len);
+
+    ptr = blob + sizeof(*hdr);
+    for (d = 0; d < ctx->devices->len; d++) {
+        dev  = &g_array_index(ctx->devices, DeviceInfo, d);
+        dout = (QemuFixedBarsDevice *)ptr;
+
+        dout->vendor_id = cpu_to_le16(dev->vendor_id);
+        dout->device_id = cpu_to_le16(dev->device_id);
+        dout->dev_flags = dev->is_fixed ? QEMU_FIXED_BARS_DEV_F_FIXED : 0;
+        dout->rp_bus    = dev->rp_bus;
+        dout->num_bars  = dev->bars->len;
+        dout->reserved  = 0;
+        memcpy(dout->fw_path, dev->fw_path, sizeof(dout->fw_path));
+        ptr += sizeof(QemuFixedBarsDevice);
+
+        for (b = 0; b < dev->bars->len; b++) {
+            bi   = &g_array_index(dev->bars, BarInfo, b);
+            bout = (QemuFixedBarsBar *)ptr;
+
+            bout->bar     = bi->bar;
+            bout->flags   = cpu_to_le32(bi->flags);
+            bout->address = cpu_to_le64(bi->addr);
+            bout->size    = cpu_to_le64(bi->size);
+            ptr += sizeof(QemuFixedBarsBar);
+        }
+    }
+
+    *blob_size = sz;
+    return blob;
+}
+
+/*
+ * fixed_bars_write_blob - validate fixed BAR addresses and write fw_cfg

blob.
+ *

+ * @fw_cfg:       fw_cfg state to write the etc/fixed-bars blob into.
+ * @mmio32_base:  base of the machine's 32-bit PCIe MMIO aperture.
+ * @mmio32_size:  size of the machine's 32-bit PCIe MMIO aperture.
+ * @mmio64_base:  base of the machine's 64-bit PCIe MMIO aperture.
+ * @mmio64_size:  size of the machine's 64-bit PCIe MMIO aperture.

+ *
+ * Returns true if any fixed BAR device was found and the blob was
+ * written, false if there was nothing to do. Aborts if any BAR
+ * address fails validation.
+ */

hw/pci/pci-fixed-bar-blob.c new file +50 -0
+bool fixed_bars_write_blob(FWCfgState *fw_cfg,
+                           uint64_t mmio32_base,
+                           uint64_t mmio32_size,
+                           uint64_t mmio64_base,
+                           uint64_t mmio64_size)
+{
+    FixedBarsInfo info;
+    CollectCtx ctx;
+    uint8_t *blob;
+    size_t blob_size;
+    guint d;
+
+    if (!mmio32_size || !mmio64_size) {
+        error_report("fixed-bar: zero-size PCIe MMIO aperture "
+                     "(32-bit=0x%"PRIx64", 64-bit=0x%"PRIx64")",
+                     mmio32_size, mmio64_size);
+        exit(1);
+    }
+    if (mmio32_size - 1 > UINT64_MAX - mmio32_base ||
+        mmio64_size - 1 > UINT64_MAX - mmio64_base) {
+        error_report("fixed-bar: PCIe MMIO aperture base+size overflows "
+                     "(32-bit base=0x%"PRIx64" size=0x%"PRIx64", "
+                     "64-bit base=0x%"PRIx64" size=0x%"PRIx64")",
+                     mmio32_base, mmio32_size, mmio64_base, mmio64_size);
+        exit(1);
+    }
+
+    info.mmio32_base = mmio32_base;
+    info.mmio32_limit = mmio32_base + mmio32_size - 1;
+    info.mmio64_base = mmio64_base;
+    info.mmio64_limit = mmio64_base + mmio64_size - 1;
+
+    if (!fixed_bars_validate(&info)) {
+        return false;
+    }
+
+    ctx.devices  = g_array_new(false, true, sizeof(DeviceInfo));
+    ctx.root_bus = NULL;
+    collect_all_host_bridges(&ctx);
+
+    blob = create_blob(&ctx, &blob_size);
+    fw_cfg_add_file(fw_cfg, FW_CFG_FIXED_BARS, blob, blob_size);
+
+    for (d = 0; d < ctx.devices->len; d++) {
+        g_array_free(g_array_index(ctx.devices, DeviceInfo, d).bars, true);
+    }
+    g_array_free(ctx.devices, true);
+
+    return true;
+}
hw/pci/pci-fixed-bar.h new file +2 -0
new file mode 100644
index 0000000000..0d4e31b301
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights

reserved
+ * Fixed-BAR — QEMU side declarations.
+ *
+ * Written by Tushar Dave
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

hw/pci/pci-fixed-bar.h new file +9 -0
+#ifndef HW_PCI_FIXED_BAR_H
+#define HW_PCI_FIXED_BAR_H
+
+#include "hw/nvram/fw_cfg.h"
+#include "hw/pci/pci_bus.h"
+
+#define FW_CFG_FIXED_BARS        "etc/fixed-bars"
+#define QEMU_FIXED_BARS_VERSION  1
+#define QEMU_FIXED_BARS_MAX_PATH 128

hw/pci/pci-fixed-bar.h line 27

Quoted 10 lines
hw/pci/pci-fixed-bar.h new file +10 -0
+
+/*
+ * On-wire layout (little-endian, packed):
+ *
+ *   QemuFixedBarsHdr
+ *
+ *   For each device (num_devices total):
+ *     QemuFixedBarsDevice               -- device header
+ *     QemuFixedBarsBar[num_bars]        -- one record per BAR (FIXED only)
+ */

Could we document this new etc/fixed-bars format under docs/specs/ ?

Thanks,
Shameer

#9 lore raw

Re: [PATCH 3/5] pci: add fixed BAR fw_cfg blob export

Quoted 215 lines · Shameer Kolothum Thodi
Quoted 215 lines

-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 16 September 2026 19:56
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 3/5] pci: add fixed BAR fw_cfg blob export

Introduce a fixed BAR fw_cfg blob exporter that serializes PCI device and BAR information into the "etc/fixed-bars" fw_cfg file.

The blob contains an entry for every PCI function with memory BARs. Each entry carries the device's vendor and device ID, whether it has a fixed BAR configuration, and its firmware device path. Fixed BAR entries also include the configured BAR address, size, and type information for each BAR.

---
 hw/pci/meson.build          |   1 +
 hw/pci/pci-fixed-bar-blob.c | 305
++++++++++++++++++++++++++++++++++++
 hw/pci/pci-fixed-bar.h      |  63 ++++++++
 3 files changed, 369 insertions(+)
 create mode 100644 hw/pci/pci-fixed-bar-blob.c
 create mode 100644 hw/pci/pci-fixed-bar.h
hw/pci/meson.build +1 -0
index 150085c997..b81cc056c0 100644
@@ -20,6 +20,7 @@ pci_ss.add(files('pcie.c', 'pcie_aer.c'))
 pci_ss.add(files('pcie_doe.c'))
 system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pcie_port.c',
 'pcie_host.c'))
 system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pci-fixed-bar-
 validate.c'))
+system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pci-fixed-bar-
 blob.c'))

system_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss)

stub_ss.add(files('pci-stub.c'))

hw/pci/pci-fixed-bar-blob.c new file +2 -0
new file mode 100644
index 0000000000..b9fdc6b7d4
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights

reserved
+ * Write validated fixed-BAR device info to the etc/fixed-bars fw_cfg blob.
+ *
+ * Written by Tushar Dave
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

hw/pci/pci-fixed-bar-blob.c new file +45 -0
+
+#include "qemu/osdep.h"
+#include "hw/nvram/fw_cfg.h"
+#include "hw/pci/pci.h"
+#include "hw/pci/pci_bridge.h"
+#include "hw/pci/pci_host.h"
+#include "hw/pci/pcie_port.h"
+#include "hw/core/qdev.h"
+#include "qemu/error-report.h"
+#include "pci-internal.h"
+#include "pci-fixed-bar.h"
+#include "pci-fixed-bar-validate.h"
+
+typedef struct {
+    uint8_t  bar;
+    uint32_t flags;
+    uint64_t addr;
+    uint64_t size;
+} BarInfo;
+
+/* One PCI function entry to be written to the blob. */
+typedef struct {
+    uint8_t  rp_bus;     /* primary bus of the root port this device is under */
+    uint16_t vendor_id;
+    uint16_t device_id;
+    bool     is_fixed;
+    char     fw_path[QEMU_FIXED_BARS_MAX_PATH];
+    GArray  *bars;  /* array of BarInfo */
+} DeviceInfo;
+
+typedef struct {
+    GArray *devices;
+    PCIBus *root_bus;
+} CollectCtx;
+
+static void collect_device(PCIBus *bus, PCIDevice *pdev, void *opaque);
+
+/* Visit every device on this bus, in devfn order. */
+static void collect_bus(PCIBus *bus, void *opaque)
+{
+    pci_for_each_device_under_bus(bus, collect_device, opaque);
+}
+
+/*
+ * Primary bus number of the nearest TYPE_PCIE_ROOT_PORT ancestor of

bus
+ * — i.e. the bus the root port device itself lives on, not its
+ * secondary bus. Falls back to the host bridge's own bus number if bus
+ * isn't under any root port (e.g. a device directly on the host
+ * bridge's primary bus).
+ */

hw/pci/pci-fixed-bar-blob.c new file +101 -0
+static uint8_t find_root_port_bus(PCIBus *bus, PCIBus *host_bus)
+{
+    PCIDevice *parent;
+
+    while (bus) {
+        parent = bus->parent_dev;
+        if (!parent) {
+            break;
+        }
+        if (object_dynamic_cast(OBJECT(parent), TYPE_PCIE_ROOT_PORT)) {
+            return pci_bus_num(pci_get_bus(parent));
+        }
+        bus = pci_get_bus(parent);
+    }
+    return pci_bus_num(host_bus);
+}
+
+static void collect_device(PCIBus *bus, PCIDevice *pdev, void *opaque)
+{
+    CollectCtx *ctx = opaque;
+    bool has_mem_bar = false;
+    bool is_64bit, is_pref;
+    DeviceInfo dev;
+    PCIIORegion *r;
+    PCIBus *sec;
+    BarInfo bi;
+    int i;
+
+    for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+        r = &pdev->io_regions[i];
+        if (r->size && !(r->type & PCI_BASE_ADDRESS_SPACE_IO)) {
+            has_mem_bar = true;
+            break;
+        }
+    }
+
+    /*
+     * Every device with a memory BAR gets an entry, fixed or not — not
+     * just ones with fixed-bar-N= set. This preserves the exact device
+     * sequence CheckDevice() needs for positional VID:DID matching (see
+     * collect_all_host_bridges()); only fixed devices carry BAR records
+     * (dev.bars stays empty, dev.is_fixed false, otherwise).
+     */
+    if (has_mem_bar) {
+        g_autofree char *fw_path = qdev_get_fw_dev_path(DEVICE(pdev));
+
+        memset(&dev, 0, sizeof(dev));
+        dev.rp_bus    = find_root_port_bus(bus, ctx->root_bus);
+        dev.vendor_id = pci_get_word(pdev->config + PCI_VENDOR_ID);
+        dev.device_id = pci_get_word(pdev->config + PCI_DEVICE_ID);
+        dev.is_fixed  = false;
+        for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+            if (pdev->fixed_bar_addr[i] != PCI_BAR_UNMAPPED) {
+                dev.is_fixed = true;
+                break;
+            }
+        }
+        if (fw_path) {
+            g_strlcpy(dev.fw_path, fw_path, sizeof(dev.fw_path));
+        }
+        dev.bars = g_array_new(false, true, sizeof(BarInfo));
+
+        if (dev.is_fixed) {
+            for (i = 0; i < PCI_NUM_REGIONS - 1; i++) {
+                r = &pdev->io_regions[i];
+                if (!r->size || (r->type & PCI_BASE_ADDRESS_SPACE_IO)) {
+                    continue;
+                }
+                is_64bit = !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64);
+                is_pref  = !!(r->type & PCI_BASE_ADDRESS_MEM_PREFETCH);
+
+                memset(&bi, 0, sizeof(bi));
+                bi.bar   = i;
+                bi.addr  = (uint64_t)pdev->fixed_bar_addr[i];
+                bi.size  = r->size;
+                bi.flags = (is_64bit ? QEMU_FIXED_BAR_F_MEM64 : 0) |
+                           (is_pref  ? QEMU_FIXED_BAR_F_PREF  : 0);
+                g_array_append_val(dev.bars, bi);
+            }
+        }
+        g_array_append_val(ctx->devices, dev);
+    }
+
+    if (!object_dynamic_cast(OBJECT(pdev), TYPE_PCI_BRIDGE)) {
+        return;
+    }
+    sec = pci_bridge_get_sec_bus(PCI_BRIDGE(pdev));
+    if (sec) {
+        collect_bus(sec, opaque);
+    }
+}
+
+static gint cmp_host_bus_num(gconstpointer a, gconstpointer b)
+{
+    PCIHostState *ha = *(PCIHostState **)a;
+    PCIHostState *hb = *(PCIHostState **)b;
+    return (gint)pci_bus_num(ha->bus) - (gint)pci_bus_num(hb->bus);
+}
+
+/*
+ * EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL's CheckDevice

interface
+ * (UEFI PI Spec 1.2 Vol 5) only passes VendorId/DeviceId/RevisionId/

Quoted 8 lines
Quoted 5 lines

+ * SubsystemVendorId/SubsystemDeviceId, no BDF — so in EDK2 we can't
+ * match a blob entry to a specific device directly using BDF. To work
+ * around that, we prepare the blob entries in the same order PciBusDxe
+ * discovers devices, so matching by VID:DID inherently works.
+ */

The blob now also includes firmware device paths for future matching, right? Should we mention that as well?

Sure I'll add a note.

Quoted 170 lines
Quoted 170 lines
hw/pci/pci-fixed-bar-blob.c new file +79 -0
+static void collect_all_host_bridges(CollectCtx *ctx)
+{
+    PCIHostState *hb;
+    GPtrArray *sorted;
+    guint i;
+
+    sorted = g_ptr_array_new();
+    QLIST_FOREACH(hb, &pci_host_bridges, next) {
+        if (hb->bus) {
+            g_ptr_array_add(sorted, hb);
+        }
+    }
+    g_ptr_array_sort(sorted, cmp_host_bus_num);
+
+    for (i = 0; i < sorted->len; i++) {
+        hb = g_ptr_array_index(sorted, i);
+        ctx->root_bus = hb->bus;
+        collect_bus(hb->bus, ctx);
+    }
+
+    g_ptr_array_free(sorted, true);
+}
+
+static uint8_t *create_blob(CollectCtx *ctx, size_t *blob_size)
+{
+    QemuFixedBarsDevice *dout;
+    QemuFixedBarsBar *bout;
+    QemuFixedBarsHdr *hdr;
+    DeviceInfo *dev;
+    uint8_t *blob;
+    uint8_t *ptr;
+    BarInfo *bi;
+    size_t sz;
+    guint d, b;
+
+    sz = sizeof(QemuFixedBarsHdr);
+    for (d = 0; d < ctx->devices->len; d++) {
+        dev = &g_array_index(ctx->devices, DeviceInfo, d);
+        sz += sizeof(QemuFixedBarsDevice);
+        sz += dev->bars->len * sizeof(QemuFixedBarsBar);
+    }
+
+    blob = g_malloc0(sz);
+    hdr  = (QemuFixedBarsHdr *)blob;
+    hdr->version     = cpu_to_le32(QEMU_FIXED_BARS_VERSION);
+    hdr->num_devices = cpu_to_le32(ctx->devices->len);
+
+    ptr = blob + sizeof(*hdr);
+    for (d = 0; d < ctx->devices->len; d++) {
+        dev  = &g_array_index(ctx->devices, DeviceInfo, d);
+        dout = (QemuFixedBarsDevice *)ptr;
+
+        dout->vendor_id = cpu_to_le16(dev->vendor_id);
+        dout->device_id = cpu_to_le16(dev->device_id);
+        dout->dev_flags = dev->is_fixed ? QEMU_FIXED_BARS_DEV_F_FIXED : 0;
+        dout->rp_bus    = dev->rp_bus;
+        dout->num_bars  = dev->bars->len;
+        dout->reserved  = 0;
+        memcpy(dout->fw_path, dev->fw_path, sizeof(dout->fw_path));
+        ptr += sizeof(QemuFixedBarsDevice);
+
+        for (b = 0; b < dev->bars->len; b++) {
+            bi   = &g_array_index(dev->bars, BarInfo, b);
+            bout = (QemuFixedBarsBar *)ptr;
+
+            bout->bar     = bi->bar;
+            bout->flags   = cpu_to_le32(bi->flags);
+            bout->address = cpu_to_le64(bi->addr);
+            bout->size    = cpu_to_le64(bi->size);
+            ptr += sizeof(QemuFixedBarsBar);
+        }
+    }
+
+    *blob_size = sz;
+    return blob;
+}
+
+/*
+ * fixed_bars_write_blob - validate fixed BAR addresses and write fw_cfg

blob.
+ *

+ * @fw_cfg:       fw_cfg state to write the etc/fixed-bars blob into.
+ * @mmio32_base:  base of the machine's 32-bit PCIe MMIO aperture.
+ * @mmio32_size:  size of the machine's 32-bit PCIe MMIO aperture.
+ * @mmio64_base:  base of the machine's 64-bit PCIe MMIO aperture.
+ * @mmio64_size:  size of the machine's 64-bit PCIe MMIO aperture.

+ *
+ * Returns true if any fixed BAR device was found and the blob was
+ * written, false if there was nothing to do. Aborts if any BAR
+ * address fails validation.
+ */

hw/pci/pci-fixed-bar-blob.c new file +50 -0
+bool fixed_bars_write_blob(FWCfgState *fw_cfg,
+                           uint64_t mmio32_base,
+                           uint64_t mmio32_size,
+                           uint64_t mmio64_base,
+                           uint64_t mmio64_size)
+{
+    FixedBarsInfo info;
+    CollectCtx ctx;
+    uint8_t *blob;
+    size_t blob_size;
+    guint d;
+
+    if (!mmio32_size || !mmio64_size) {
+        error_report("fixed-bar: zero-size PCIe MMIO aperture "
+                     "(32-bit=0x%"PRIx64", 64-bit=0x%"PRIx64")",
+                     mmio32_size, mmio64_size);
+        exit(1);
+    }
+    if (mmio32_size - 1 > UINT64_MAX - mmio32_base ||
+        mmio64_size - 1 > UINT64_MAX - mmio64_base) {
+        error_report("fixed-bar: PCIe MMIO aperture base+size overflows "
+                     "(32-bit base=0x%"PRIx64" size=0x%"PRIx64", "
+                     "64-bit base=0x%"PRIx64" size=0x%"PRIx64")",
+                     mmio32_base, mmio32_size, mmio64_base, mmio64_size);
+        exit(1);
+    }
+
+    info.mmio32_base = mmio32_base;
+    info.mmio32_limit = mmio32_base + mmio32_size - 1;
+    info.mmio64_base = mmio64_base;
+    info.mmio64_limit = mmio64_base + mmio64_size - 1;
+
+    if (!fixed_bars_validate(&info)) {
+        return false;
+    }
+
+    ctx.devices  = g_array_new(false, true, sizeof(DeviceInfo));
+    ctx.root_bus = NULL;
+    collect_all_host_bridges(&ctx);
+
+    blob = create_blob(&ctx, &blob_size);
+    fw_cfg_add_file(fw_cfg, FW_CFG_FIXED_BARS, blob, blob_size);
+
+    for (d = 0; d < ctx.devices->len; d++) {
+        g_array_free(g_array_index(ctx.devices, DeviceInfo, d).bars, true);
+    }
+    g_array_free(ctx.devices, true);
+
+    return true;
+}
hw/pci/pci-fixed-bar.h new file +2 -0
new file mode 100644
index 0000000000..0d4e31b301
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights

reserved
+ * Fixed-BAR — QEMU side declarations.
+ *
+ * Written by Tushar Dave
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

hw/pci/pci-fixed-bar.h new file +13 -0
+#ifndef HW_PCI_FIXED_BAR_H
+#define HW_PCI_FIXED_BAR_H
+
+#include "hw/nvram/fw_cfg.h"
+#include "hw/pci/pci_bus.h"
+
+#define FW_CFG_FIXED_BARS        "etc/fixed-bars"
+#define QEMU_FIXED_BARS_VERSION  1
+#define QEMU_FIXED_BARS_MAX_PATH 128
+
+/*
+ * On-wire layout (little-endian, packed):
+ *
Quoted 8 lines
Quoted 6 lines

+ * QemuFixedBarsHdr
+ *
+ * For each device (num_devices total):

+ *     QemuFixedBarsDevice               -- device header
+ *     QemuFixedBarsBar[num_bars]        -- one record per BAR (FIXED only)

+ */

Could we document this new etc/fixed-bars format under docs/specs/ ?

Yes, I will add it into docs/specs/pci-fixed-bars.rst

-Tushar

Quoted 3 lines

Thanks,
Shameer

#10 lore raw

PATCH 4/5 hw/arm/virt: export fixed BAR metadata via fw_cfg

In reply to Tushar Dave

Export fixed BAR metadata from the virt machine through the "etc/fixed-bars" fw_cfg file during machine initialization.

Fixed BAR placement requires firmware to preserve the PCI resource configuration established by QEMU. ACPI provides this via the PCI boot configuration preservation mechanism, _DSM function 5.

Reject fixed BAR configuration when ACPI is disabled, and request PCI boot configuration preservation when ACPI is enabled.

---
 hw/arm/virt.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
hw/arm/virt.c +16 -0
index 3eecf094bc..c5db663858 100644
@@ -95,6 +95,7 @@
 #include "hw/cxl/cxl_host.h"
 #include "qemu/guest-random.h"
 #include "hw/watchdog/sbsa_gwdt.h"
+#include "hw/pci/pci-fixed-bar.h"
 
 static GlobalProperty arm_virt_compat_defaults[] = {
     { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "48" },
@@ -2438,6 +2439,21 @@ void virt_machine_done(Notifier *notifier, void *data)
                                        vms->memmap[VIRT_PLATFORM_BUS].size,
                                        vms->irqmap[VIRT_PLATFORM_BUS]);
     }
+    if (fixed_bars_write_blob(vms->fw_cfg,
+                              vms->memmap[VIRT_PCIE_MMIO].base,
+                              vms->memmap[VIRT_PCIE_MMIO].size,
+                              vms->memmap[VIRT_HIGH_PCIE_MMIO].base,
+                              vms->memmap[VIRT_HIGH_PCIE_MMIO].size)) {
+        if (!virt_is_acpi_enabled(vms)) {
+            error_report("fixed-bar: fixed BAR placement requires ACPI to "
+                         "preserve the PCI boot configuration, otherwise "
+                         "these BAR assignments could be reassigned later "
+                         "with no protection");
+            exit(1);
+        }
+        vms->pci_preserve_config = true;
+    }
+
     if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as, ms, cpu) < 0) {
         exit(1);
     }
Signature · 1 line
2.34.1
#11 lore raw

RE: [PATCH 4/5] hw/arm/virt: export fixed BAR metadata via fw_cfg

Quoted 40 lines

-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 16 September 2026 19:56
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 4/5] hw/arm/virt: export fixed BAR metadata via fw_cfg

Export fixed BAR metadata from the virt machine through the "etc/fixed-bars" fw_cfg file during machine initialization.

Fixed BAR placement requires firmware to preserve the PCI resource configuration established by QEMU. ACPI provides this via the PCI boot configuration preservation mechanism, _DSM function 5.

Reject fixed BAR configuration when ACPI is disabled, and request PCI boot configuration preservation when ACPI is enabled.

---
 hw/arm/virt.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
hw/arm/virt.c +1 -0
index 3eecf094bc..c5db663858 100644
@@ -95,6 +95,7 @@
 #include "hw/cxl/cxl_host.h"
 #include "qemu/guest-random.h"
 #include "hw/watchdog/sbsa_gwdt.h"
+#include "hw/pci/pci-fixed-bar.h"
 
 static GlobalProperty arm_virt_compat_defaults[] = {
     { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "48" },

hw/arm/virt.c void virt_machine_done(Notifier *notifier, void · line 2447

Quoted 9 lines
hw/arm/virt.c +5 -0
@@ -2438,6 +2439,21 @@ void virt_machine_done(Notifier *notifier, void
 *data)
                                        vms->memmap[VIRT_PLATFORM_BUS].size,
                                        vms->irqmap[VIRT_PLATFORM_BUS]);
     }
+    if (fixed_bars_write_blob(vms->fw_cfg,
+                              vms->memmap[VIRT_PCIE_MMIO].base,
+                              vms->memmap[VIRT_PCIE_MMIO].size,
+                              vms->memmap[VIRT_HIGH_PCIE_MMIO].base,
+                              vms->memmap[VIRT_HIGH_PCIE_MMIO].size)) {

Should we check for vms->highmem_mmio here? The memmap entry still contains a base and size when highmem-mmio=off, but the aperture is not mapped or advertised in ACPI.

hw/arm/virt.c void virt_machine_done(Notifier *notifier, void *data) · line 2447

Quoted 1 line
hw/arm/virt.c +1 -0
+        if (!virt_is_acpi_enabled(vms)) {

virt_is_acpi_enabled() merely checks that ACPI is not explicitly disabled. With the default acpi=auto, it returns true even for direct kernel boot without firmware.

Should check vms->bootinfo.firmware_loaded as well.

Thanks,
Shameer

#12 lore raw

Re: [PATCH 4/5] hw/arm/virt: export fixed BAR metadata via fw_cfg

Quoted 37 lines · Shameer Kolothum Thodi
Quoted 37 lines

-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 16 September 2026 19:56
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 4/5] hw/arm/virt: export fixed BAR metadata via fw_cfg

Export fixed BAR metadata from the virt machine through the "etc/fixed-bars" fw_cfg file during machine initialization.

Fixed BAR placement requires firmware to preserve the PCI resource configuration established by QEMU. ACPI provides this via the PCI boot configuration preservation mechanism, _DSM function 5.

Reject fixed BAR configuration when ACPI is disabled, and request PCI boot configuration preservation when ACPI is enabled.

---
 hw/arm/virt.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
hw/arm/virt.c +1 -0
index 3eecf094bc..c5db663858 100644
@@ -95,6 +95,7 @@
 #include "hw/cxl/cxl_host.h"
 #include "qemu/guest-random.h"
 #include "hw/watchdog/sbsa_gwdt.h"
+#include "hw/pci/pci-fixed-bar.h"
 
Quoted 16 lines

hw/arm/virt.c void virt_machine_done(Notifier *notifier, void · line 2447

Quoted 12 lines
hw/arm/virt.c +5 -0
 static GlobalProperty arm_virt_compat_defaults[] = {
     { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "48" },
@@ -2438,6 +2439,21 @@ void virt_machine_done(Notifier *notifier, void
 *data)
                                        vms->memmap[VIRT_PLATFORM_BUS].size,
                                        vms->irqmap[VIRT_PLATFORM_BUS]);
     }
+    if (fixed_bars_write_blob(vms->fw_cfg,
+                              vms->memmap[VIRT_PCIE_MMIO].base,
+                              vms->memmap[VIRT_PCIE_MMIO].size,
+                              vms->memmap[VIRT_HIGH_PCIE_MMIO].base,
+                              vms->memmap[VIRT_HIGH_PCIE_MMIO].size)) {

Should we check for vms->highmem_mmio here? The memmap entry still contains a base and size when highmem-mmio=off, but the aperture is not mapped or advertised in ACPI.

You are right, we should.

Quoted 6 lines

hw/arm/virt.c void virt_machine_done(Notifier *notifier, void *data) · line 2447

Quoted 2 lines
hw/arm/virt.c +1 -0
+        if (!virt_is_acpi_enabled(vms)) {

virt_is_acpi_enabled() merely checks that ACPI is not explicitly disabled. With the default acpi=auto, it returns true even for direct kernel boot without firmware.

Should check vms->bootinfo.firmware_loaded as well.

Okay. I will add the check in V2.

-Tushar

Quoted 3 lines

Thanks,
Shameer

#13 lore raw

PATCH 5/5 hw/arm/virt: add highmem-mmio-base property

In reply to Tushar Dave

Add a highmem-mmio-base property to override the base of the virt machine's high PCIe MMIO window, alongside the existing highmem-mmio-size:

-machine virt,highmem-mmio-base=<addr>,highmem-mmio-size=<size>

Some PCI devices require MMIO resources to be placed within a specific address range that cannot be satisfied by the default placement. The configured base is validated to be non-zero, aligned to highmem-mmio-size, non-overlapping with the existing high memory layout, and within the configured physical address space.

---
 hw/arm/virt.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)
hw/arm/virt.c +61 -1
index c5db663858..3a554dd26c 100644
@@ -2513,9 +2513,34 @@ static void virt_set_high_memmap(VirtMachineState *vms,
 
     for (i = VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) {
         region_enabled = virt_get_high_memmap_enabled(vms, i);
-        region_base = ROUND_UP(base, extended_memmap[i].size);
         region_size = extended_memmap[i].size;
 
+        if (i == VIRT_HIGH_PCIE_MMIO && extended_memmap[i].base) {
+            region_base = extended_memmap[i].base;
+
+            if (region_base < base) {
+                error_report("highmem-mmio-base 0x%"PRIx64" overlaps prior "
+                             "high memory layout (must be >= 0x%"PRIx64")",
+                             region_base, base);
+                exit(1);
+            }
+            if (region_base % region_size != 0) {
+                error_report("highmem-mmio-base 0x%"PRIx64" must be "
+                             "aligned to highmem-mmio-size 0x%"PRIx64,
+                             region_base, region_size);
+                exit(1);
+            }
+            if (region_base + region_size > BIT_ULL(pa_bits)) {
+                error_report("highmem-mmio-base + highmem-mmio-size "
+                             "[0x%"PRIx64", 0x%"PRIx64") exceeds %d-bit PA "
+                             "space", region_base,
+                             region_base + region_size, pa_bits);
+                exit(1);
+            }
+        } else {
+            region_base = ROUND_UP(base, region_size);
+        }
+
         vms->memmap[i].base = region_base;
         vms->memmap[i].size = region_size;
 
@@ -3416,6 +3441,33 @@ static void virt_set_highmem_mmio_size(Object *obj, Visitor *v,
     extended_memmap[VIRT_HIGH_PCIE_MMIO].size = size;
 }
 
+static void virt_get_highmem_mmio_base(Object *obj, Visitor *v,
+                                       const char *name, void *opaque,
+                                       Error **errp)
+{
+    uint64_t base = extended_memmap[VIRT_HIGH_PCIE_MMIO].base;
+
+    visit_type_size(v, name, &base, errp);
+}
+
+static void virt_set_highmem_mmio_base(Object *obj, Visitor *v,
+                                       const char *name, void *opaque,
+                                       Error **errp)
+{
+    uint64_t base;
+
+    if (!visit_type_size(v, name, &base, errp)) {
+        return;
+    }
+
+    if (base == 0) {
+        error_setg(errp, "highmem-mmio-base cannot be 0");
+        return;
+    }
+
+    extended_memmap[VIRT_HIGH_PCIE_MMIO].base = base;
+}
+
 static char *virt_get_msi(Object *obj, Error **errp)
 {
     VirtMachineState *vms = VIRT_MACHINE(obj);
@@ -4286,6 +4338,14 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)
                                           "Set the high memory region size "
                                           "for PCI MMIO");
 
+    object_class_property_add(oc, "highmem-mmio-base", "size",
+                                   virt_get_highmem_mmio_base,
+                                   virt_set_highmem_mmio_base,
+                                   NULL, NULL);
+    object_class_property_set_description(oc, "highmem-mmio-base",
+                                          "Set the high memory region base "
+                                          "for PCI MMIO");
+
     object_class_property_add(oc, "virtio-mmio-transports", "uint8",
                                    virt_get_virtio_transports,
                                    virt_set_virtio_transports,
Signature · 1 line
2.34.1
#14 lore raw

RE: [PATCH 5/5] hw/arm/virt: add highmem-mmio-base property

Quoted 49 lines

-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 16 September 2026 19:56
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 5/5] hw/arm/virt: add highmem-mmio-base property

Add a highmem-mmio-base property to override the base of the virt machine's high PCIe MMIO window, alongside the existing highmem-mmio-size:

-machine virt,highmem-mmio-base=<addr>,highmem-mmio-size=<size>

Some PCI devices require MMIO resources to be placed within a specific address range that cannot be satisfied by the default placement. The configured base is validated to be non-zero, aligned to highmem-mmio-size, non-overlapping with the existing high memory layout, and within the configured physical address space.

---
 hw/arm/virt.c | 62
++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)
hw/arm/virt.c +6 -1
index c5db663858..3a554dd26c 100644
@@ -2513,9 +2513,34 @@ static void
 virt_set_high_memmap(VirtMachineState *vms,
 
     for (i = VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap);
 i++) {
         region_enabled = virt_get_high_memmap_enabled(vms, i);
-        region_base = ROUND_UP(base, extended_memmap[i].size);
         region_size = extended_memmap[i].size;
 
+        if (i == VIRT_HIGH_PCIE_MMIO && extended_memmap[i].base) {
+            region_base = extended_memmap[i].base;
+
+            if (region_base < base) {
+                error_report("highmem-mmio-base 0x%"PRIx64" overlaps prior "
+                             "high memory layout (must be >= 0x%"PRIx64")",

hw/arm/virt.c static void · line 2535

Quoted 10 lines
hw/arm/virt.c +10 -0
+                             region_base, base);
+                exit(1);
+            }
+            if (region_base % region_size != 0) {
+                error_report("highmem-mmio-base 0x%"PRIx64" must be "
+                             "aligned to highmem-mmio-size 0x%"PRIx64,
+                             region_base, region_size);
+                exit(1);
+            }
+            if (region_base + region_size > BIT_ULL(pa_bits)) {

region_base + region_size can overflow and bypass this check.

Quoted 51 lines
hw/arm/virt.c +10 -0
+                error_report("highmem-mmio-base + highmem-mmio-size "
+                             "[0x%"PRIx64", 0x%"PRIx64") exceeds %d-bit PA "
+                             "space", region_base,
+                             region_base + region_size, pa_bits);
+                exit(1);
+            }
+        } else {
+            region_base = ROUND_UP(base, region_size);
+        }
+
         vms->memmap[i].base = region_base;
         vms->memmap[i].size = region_size;
hw/arm/virt.c +27 -0
@@ -3416,6 +3441,33 @@ static void virt_set_highmem_mmio_size(Object
 *obj, Visitor *v,
     extended_memmap[VIRT_HIGH_PCIE_MMIO].size = size;
 }
 
+static void virt_get_highmem_mmio_base(Object *obj, Visitor *v,
+                                       const char *name, void *opaque,
+                                       Error **errp)
+{
+    uint64_t base = extended_memmap[VIRT_HIGH_PCIE_MMIO].base;
+
+    visit_type_size(v, name, &base, errp);
+}
+
+static void virt_set_highmem_mmio_base(Object *obj, Visitor *v,
+                                       const char *name, void *opaque,
+                                       Error **errp)
+{
+    uint64_t base;
+
+    if (!visit_type_size(v, name, &base, errp)) {
+        return;
+    }
+
+    if (base == 0) {
+        error_setg(errp, "highmem-mmio-base cannot be 0");
+        return;
+    }
+
+    extended_memmap[VIRT_HIGH_PCIE_MMIO].base = base;
+}
+
 static char *virt_get_msi(Object *obj, Error **errp)
 {
     VirtMachineState *vms = VIRT_MACHINE(obj);
hw/arm/virt.c +0 -0
@@ -4286,6 +4338,14 @@ static void virt_machine_class_init(ObjectClass
 *oc, const void *data)
                                           "Set the high memory region size "

hw/arm/virt.c static void virt_machine_class_init(ObjectClass · line 4349

Quoted 10 lines
hw/arm/virt.c +8 -0
                                           "for PCI MMIO");
 
+    object_class_property_add(oc, "highmem-mmio-base", "size",
+                                   virt_get_highmem_mmio_base,
+                                   virt_set_highmem_mmio_base,
+                                   NULL, NULL);
+    object_class_property_set_description(oc, "highmem-mmio-base",
+                                          "Set the high memory region base "
+                                          "for PCI MMIO");
+

Add this to docs/system/arm/virt.rst as well.

Thanks,
Shameer

#15 lore raw

Re: [PATCH 5/5] hw/arm/virt: add highmem-mmio-base property

Quoted 53 lines · Shameer Kolothum Thodi
Quoted 53 lines

-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 16 September 2026 19:56
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 5/5] hw/arm/virt: add highmem-mmio-base property

Add a highmem-mmio-base property to override the base of the virt machine's high PCIe MMIO window, alongside the existing highmem-mmio-size:

-machine virt,highmem-mmio-base=<addr>,highmem-mmio-size=<size>

Some PCI devices require MMIO resources to be placed within a specific address range that cannot be satisfied by the default placement. The configured base is validated to be non-zero, aligned to highmem-mmio-size, non-overlapping with the existing high memory layout, and within the configured physical address space.

---
 hw/arm/virt.c | 62
++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)
hw/arm/virt.c +10 -1
index c5db663858..3a554dd26c 100644
@@ -2513,9 +2513,34 @@ static void
 virt_set_high_memmap(VirtMachineState *vms,
 
     for (i = VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap);
 i++) {
         region_enabled = virt_get_high_memmap_enabled(vms, i);
-        region_base = ROUND_UP(base, extended_memmap[i].size);
         region_size = extended_memmap[i].size;
 
+        if (i == VIRT_HIGH_PCIE_MMIO && extended_memmap[i].base) {
+            region_base = extended_memmap[i].base;
+
+            if (region_base < base) {
+                error_report("highmem-mmio-base 0x%"PRIx64" overlaps prior "
+                             "high memory layout (must be >= 0x%"PRIx64")",
+                             region_base, base);
+                exit(1);
+            }
+            if (region_base % region_size != 0) {
Quoted 8 lines

hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 2533

Quoted 6 lines
hw/arm/virt.c +6 -0
+                error_report("highmem-mmio-base 0x%"PRIx64" must be "
+                             "aligned to highmem-mmio-size 0x%"PRIx64,
+                             region_base, region_size);
+                exit(1);
+            }
+            if (region_base + region_size > BIT_ULL(pa_bits)) {

region_base + region_size can overflow and bypass this check.

Good catch. I will amend this in V2 with overflow check.

Quoted 54 lines
Quoted 54 lines
hw/arm/virt.c +10 -0
+                error_report("highmem-mmio-base + highmem-mmio-size "
+                             "[0x%"PRIx64", 0x%"PRIx64") exceeds %d-bit PA "
+                             "space", region_base,
+                             region_base + region_size, pa_bits);
+                exit(1);
+            }
+        } else {
+            region_base = ROUND_UP(base, region_size);
+        }
+
         vms->memmap[i].base = region_base;
         vms->memmap[i].size = region_size;
hw/arm/virt.c +27 -0
@@ -3416,6 +3441,33 @@ static void virt_set_highmem_mmio_size(Object
 *obj, Visitor *v,
     extended_memmap[VIRT_HIGH_PCIE_MMIO].size = size;
 }
 
+static void virt_get_highmem_mmio_base(Object *obj, Visitor *v,
+                                       const char *name, void *opaque,
+                                       Error **errp)
+{
+    uint64_t base = extended_memmap[VIRT_HIGH_PCIE_MMIO].base;
+
+    visit_type_size(v, name, &base, errp);
+}
+
+static void virt_set_highmem_mmio_base(Object *obj, Visitor *v,
+                                       const char *name, void *opaque,
+                                       Error **errp)
+{
+    uint64_t base;
+
+    if (!visit_type_size(v, name, &base, errp)) {
+        return;
+    }
+
+    if (base == 0) {
+        error_setg(errp, "highmem-mmio-base cannot be 0");
+        return;
+    }
+
+    extended_memmap[VIRT_HIGH_PCIE_MMIO].base = base;
+}
+
 static char *virt_get_msi(Object *obj, Error **errp)
 {
     VirtMachineState *vms = VIRT_MACHINE(obj);
hw/arm/virt.c +0 -0
@@ -4286,6 +4338,14 @@ static void virt_machine_class_init(ObjectClass
 *oc, const void *data)
                                           "Set the high memory region size "
                                           "for PCI MMIO");
 
Quoted 10 lines

hw/arm/virt.c static void virt_machine_class_init(ObjectClass *oc, const void *data) · line 4348

Quoted 8 lines
hw/arm/virt.c +8 -0
+    object_class_property_add(oc, "highmem-mmio-base", "size",
+                                   virt_get_highmem_mmio_base,
+                                   virt_set_highmem_mmio_base,
+                                   NULL, NULL);
+    object_class_property_set_description(oc, "highmem-mmio-base",
+                                          "Set the high memory region base "
+                                          "for PCI MMIO");
+

Add this to docs/system/arm/virt.rst as well.

Sure thing.

Thanks.
-Tushar

Quoted 3 lines

Thanks,
Shameer