Skip to content

pci_resource_assignment: static BAR address assignment for P2P DMA#3671

Open
jstarks wants to merge 16 commits into
microsoft:mainfrom
jstarks:pinned
Open

pci_resource_assignment: static BAR address assignment for P2P DMA#3671
jstarks wants to merge 16 commits into
microsoft:mainfrom
jstarks:pinned

Conversation

@jstarks

@jstarks jstarks commented Jun 4, 2026

Copy link
Copy Markdown
Member

Allow specific PCI BARs to be pinned to their physical addresses so that VFIO passthrough devices can participate in peer-to-peer DMA without ATS. When a VFIO device is configured with bar0=pt (through bar5=pt) on the CLI, its virtual BAR is pre-programmed with the host physical BAR address read from sysfs. The preserve_bars flag on the root complex tells the resource allocator to treat non-zero BAR values found during probing as fixed--pinned BARs stay at their physical addresses (GPA=HPA) while dynamic BARs are bump-allocated after the pinned region.

The allocation algorithm extends the existing hierarchical bottom-up sizing / top-down assignment approach. During sizing, pinned BARs establish a constrained base for their bridge window; dynamic demands are summed on top. During assignment, pinned demands are placed at their fixed addresses and dynamic demands bump-allocate forward from the highest pinned end. Bridges with pinned descendants propagate their position constraint upward so parent windows are correctly sized and placed. When no BARs are pinned, the algorithm produces identical results to the previous code.

When preserve_bars is set, the ACPI SSDT emits a _DSM method telling the guest OS to preserve firmware-assigned BAR values, and the device tree path sets linux,pci-probe-only for the same effect.

New CLI surface:

  • --pcie-root-complex gains low_mmio_base=, high_mmio_base= (producing Fixed MMIO ranges), and preserve_bars
  • --vfio gains bar0=pt through bar5=pt

Validation rejects pinned BARs that are misaligned, overlapping, or outside the MMIO aperture. Physical BAR addresses are read from the kernel's /sys/bus/pci/devices//resource table rather than VFIO config space, which returns cleared BARs after device reset.

Allow specific PCI BARs to be pinned to their physical addresses so that
VFIO passthrough devices can participate in peer-to-peer DMA without ATS.
When a VFIO device is configured with `bar0=pt` (through `bar5=pt`) on
the CLI, its virtual BAR is pre-programmed with the host physical BAR
address read from sysfs. The `preserve_bars` flag on the root complex
tells the resource allocator to treat non-zero BAR values found during
probing as fixed--pinned BARs stay at their physical addresses (GPA=HPA)
while dynamic BARs are bump-allocated after the pinned region.

The allocation algorithm extends the existing hierarchical bottom-up
sizing / top-down assignment approach. During sizing, pinned BARs
establish a constrained base for their bridge window; dynamic demands
are summed on top. During assignment, pinned demands are placed at their
fixed addresses and dynamic demands bump-allocate forward from the
highest pinned end. Bridges with pinned descendants propagate their
position constraint upward so parent windows are correctly sized and
placed. When no BARs are pinned, the algorithm produces identical
results to the previous code.

New CLI surface:
- `--pcie-root-complex` gains `low_mmio_base=`, `high_mmio_base=`
  (producing Fixed MMIO ranges), and `preserve_bars`
- `--vfio` gains `bar0=pt` through `bar5=pt`

Validation rejects pinned BARs that are misaligned, overlapping, or
outside the MMIO aperture. Physical BAR addresses are read from the
kernel's `/sys/bus/pci/devices/<bdf>/resource` table rather than VFIO
config space, which returns cleared BARs after device reset.
Copilot AI review requested due to automatic review settings June 4, 2026 23:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for “pinned” PCI BAR address assignment to enable VFIO passthrough devices to participate in peer-to-peer DMA (GPA=HPA) without ATS. It introduces CLI/config surface to (a) pre-program VFIO virtual BARs with host physical BAR addresses and (b) have the PCI resource allocator preserve (treat as fixed) non-zero BAR values discovered during probing, extending the allocator to size/assign bridge windows with pinned descendants.

Changes:

  • Add preserve_bars plumbing from CLI/config → topology → resource assignment to treat discovered non-zero BARs as pinned/fixed addresses.
  • Add VFIO bar0=pt..bar5=pt flags to seed virtual BARs from host /sys/bus/pci/devices/<bdf>/resource.
  • Extend the PCI resource assignment algorithm and tests to validate and place pinned BARs, and to size/position bridge windows accordingly.

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
vmm_core/src/acpi_builder.rs Adds TODO notes for ACPI behavior when firmware BAR assignments must be preserved.
vm/vmcore/vm_topology/src/pcie.rs Extends PcieHostBridge with preserve_bars.
vm/devices/pci/vfio_assigned_device/src/resolver.rs Threads bar_pt through VFIO device resolver paths.
vm/devices/pci/vfio_assigned_device/src/lib.rs Implements BAR “passthrough” seeding from sysfs resource table and uses it for initial virtual BAR state.
vm/devices/pci/vfio_assigned_device_resources/src/lib.rs Extends VFIO handle resources with bar_pt.
vm/devices/pci/pci_resource_assignment/src/tests.rs Adds extensive pinned-BAR unit tests and updates params with preserve_bars.
vm/devices/pci/pci_resource_assignment/src/lib.rs Adds preserve_bars parameter and new pinned-BAR error variants.
vm/devices/pci/pci_resource_assignment/src/enumerate.rs Captures pre-probe BAR values as pinned_address when preserve_bars is enabled.
vm/devices/pci/pci_resource_assignment/src/assign.rs Updates sizing/assignment to account for fixed-position (pinned) demands; adds pinned BAR validation helpers.
petri/src/vm/openvmm/modify.rs Wires new preserve_bars field into Petri OpenVMM config generation.
openvmm/openvmm_entry/src/lib.rs Adds low_mmio_base / high_mmio_base fixed MMIO range handling and threads preserve_bars; passes bar_pt into VFIO resources.
openvmm/openvmm_entry/src/cli_args.rs Adds CLI parsing for low_mmio_base, high_mmio_base, preserve_bars, and --vfio barX=pt.
openvmm/openvmm_entry/Cargo.toml Adds memory_range dependency for fixed MMIO range construction.
openvmm/openvmm_defs/src/config.rs Adds preserve_bars to PcieRootComplexConfig.
openvmm/openvmm_core/src/worker/memory_layout.rs Updates test configs to include preserve_bars.
openvmm/openvmm_core/src/worker/dispatch/ecam_config_access.rs Plumbs preserve_bars into pci_resource_assignment::AssignmentParams.
openvmm/openvmm_core/src/worker/dispatch.rs Threads preserve_bars from config into PcieHostBridge.
Cargo.lock Records new workspace dependency usage (memory_range).

Comment thread openvmm/openvmm_entry/src/lib.rs Outdated
Comment thread openvmm/openvmm_entry/src/lib.rs Outdated
Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs Outdated
Comment thread vm/devices/pci/vfio_assigned_device/src/lib.rs Outdated
Comment thread openvmm/openvmm_entry/src/cli_args.rs
@github-actions github-actions Bot added the Guide label Jun 5, 2026
Copilot AI review requested due to automatic review settings June 5, 2026 19:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 20 changed files in this pull request and generated 7 comments.

Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs Outdated
Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs Outdated
Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs
Comment thread openvmm/openvmm_entry/src/cli_args.rs
Comment thread openvmm/openvmm_entry/src/lib.rs
Comment thread openvmm/openvmm_entry/src/lib.rs
Comment thread Guide/src/user_guide/openvmm/vfio.md
Copilot AI review requested due to automatic review settings June 5, 2026 20:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 2 comments.

Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs
Comment thread openvmm/openvmm_defs/src/config.rs
Comment thread openvmm/openvmm_entry/src/lib.rs Outdated
Comment thread vm/devices/pci/vfio_assigned_device/src/lib.rs Outdated
Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs Outdated
Copilot AI review requested due to automatic review settings June 9, 2026 05:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 8 comments.

Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs Outdated
Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs Outdated
Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs Outdated
Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs Outdated
Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs
Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs Outdated
Comment thread openvmm/openvmm_entry/src/lib.rs
Comment thread openvmm/openvmm_entry/src/lib.rs
@jstarks jstarks marked this pull request as ready for review June 9, 2026 05:35
@jstarks jstarks requested a review from a team as a code owner June 9, 2026 05:35
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Comment thread Guide/src/user_guide/openvmm/vfio.md Outdated
Copilot AI review requested due to automatic review settings June 9, 2026 18:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.

Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs
Comment thread vm/devices/pci/pci_resource_assignment/src/assign.rs Outdated
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants