All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tushar Dave <tdave@nvidia.com>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org, peter.maydell@linaro.org, mst@redhat.com,
	marcel@redhat.com, devel@edk2.groups.io, alwilliamson@nvidia.com,
	jgg@nvidia.com, skolothumtho@nvidia.com, ardb@kernel.org,
	kraxel@redhat.com, clg@redhat.com, tdave@nvidia.com
Subject: [PATCH v3 0/5] hw/pci, hw/arm/virt: fixed PCI BAR placement
Date: Mon, 23 Nov 2026 16:11:00 -0600	[thread overview]
Message-ID: <20261123221105.37029-1-tdave@nvidia.com> (raw)

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 when the machine is done initializing. 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 addresses reach firmware and the guest through the standard PCI
Enhanced Allocation (EA) capability: a device with fixed-bar-N properties gets
an EA capability with one entry for each fixed BAR, holding its address and
size.

EA is a conventional capability, so it has to fit in the first 256 bytes of the
configuration space. A device that has no room, or that already has an EA
capability, is rejected with an error.

The fixed-bar-N property and its validation are generic and apply to any PCI
device. A machine type opts in by setting the new pci_fixed_bar_supported
MachineClass flag. Machine types that leave it unset reject fixed-bar-N. This
series enables it on the virt machine only, by setting the flag and calling the
validation once the devices are realized.

On the firmware side nothing new is needed. Firmware that supports EA reads
the addresses from the capability, and EDK2 has had that support since
PR 13186 (merged 2026-10-27, see link below). The Linux kernel reads EA for
endpoint devices and reports each BAR as "from Enhanced Allocation".

Fixed BAR placement requires the guest to preserve the PCI resource
configuration established by firmware. This is requested through the PCI boot
configuration preservation mechanism using ACPI _DSM function 5. Fixed BAR
configuration is rejected when firmware is not loaded or 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.
* SR-IOV VF BARs are not covered.

Testing:

The series was tested on the AArch64 virt machine with a range of PCIe
configurations, including emulated and VFIO passthrough devices, PCIe
switches, single and multiple fixed-BAR endpoints behind a shared root port,
devices attached directly to the host bridge, and endpoints behind nested
bridges. All rejection paths were also exercised, with the corresponding
error messages verified. These included unsupported machine types,
hot-plugged devices, non-existent BARs, I/O BARs, unaligned, overlapping, or
out-of-aperture BARs, incomplete BAR configurations, highmem-mmio=off,
missing firmware, and highmem-mmio-base values that cause address-space
overflow.

Changes since v2:

* Describe fixed BARs using an Enhanced Allocation (EA) capability in the
  device configuration space instead of the etc/fixed-bars fw_cfg blob. This
  replaces patch 3 and removes the blob, its format documentation, and the
  corresponding EDK2 change to IncompatiblePciDeviceSupportDxe, since EDK2
  already handles EA capabilities natively.
* Update patches 4 and 5 accordingly: patch 4 now performs validation instead
  of writing the fw_cfg blob, and patch 5 is adjusted to the updated
  object_class_property_add() API in current master.
* Patches 1 and 2 are unchanged.

A git branch with this series applied is available at:
https://github.com/tdavenvidia/upstream-qemu/tree/Upstream-fixed-bar-v3-EA-nov-20

EDK2 EA support, used by this series:
https://github.com/tianocore/edk2/pull/13186

v2:
https://lore.kernel.org/qemu-arm/20261102181241.3077981-1-tdave@nvidia.com/

v1:
https://lore.kernel.org/qemu-arm/20260916185554.917526-1-tdave@nvidia.com/

Tushar Dave (5):
  hw/pci: introduce PCI fixed BAR properties
  hw/pci: add validation for fixed BAR configuration
  hw/pci: describe fixed BARs with an Enhanced Allocation capability
  hw/arm/virt: validate fixed BARs and preserve the PCI configuration
  hw/arm/virt: add highmem-mmio-base property

 docs/system/arm/virt.rst        |   4 +
 hw/arm/virt.c                   |  82 ++++++-
 hw/pci/meson.build              |   1 +
 hw/pci/pci-fixed-bar-validate.c | 405 ++++++++++++++++++++++++++++++++
 hw/pci/pci-fixed-bar-validate.h |  22 ++
 hw/pci/pci.c                    | 219 ++++++++++++++++-
 hw/vfio/pci.c                   |  58 ++++-
 include/hw/core/boards.h        |   3 +
 include/hw/pci/pci-fixed-bar.h  |  28 +++
 include/hw/pci/pci.h            |   2 +
 include/hw/pci/pci_device.h     |   7 +
 11 files changed, 827 insertions(+), 4 deletions(-)
 create mode 100644 hw/pci/pci-fixed-bar-validate.c
 create mode 100644 hw/pci/pci-fixed-bar-validate.h
 create mode 100644 include/hw/pci/pci-fixed-bar.h

-- 
2.34.1



             reply	other threads:[~2026-11-23 22:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 22:11 Tushar Dave [this message]
2026-11-23 22:11 ` [PATCH v3 1/5] hw/pci: introduce PCI fixed BAR properties Tushar Dave
2026-11-23 22:11 ` [PATCH v3 2/5] hw/pci: add validation for fixed BAR configuration Tushar Dave
2026-11-23 22:11 ` [PATCH v3 3/5] hw/pci: describe fixed BARs with an Enhanced Allocation capability Tushar Dave
2026-11-23 22:11 ` [PATCH v3 4/5] hw/arm/virt: validate fixed BARs and preserve the PCI configuration Tushar Dave
2026-11-23 22:11 ` [PATCH v3 5/5] hw/arm/virt: add highmem-mmio-base property Tushar Dave

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123221105.37029-1-tdave@nvidia.com \
    --to=tdave@nvidia.com \
    --cc=alwilliamson@nvidia.com \
    --cc=ardb@kernel.org \
    --cc=clg@redhat.com \
    --cc=devel@edk2.groups.io \
    --cc=jgg@nvidia.com \
    --cc=kraxel@redhat.com \
    --cc=marcel@redhat.com \
    --cc=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=skolothumtho@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.