Skip to content

feat: Assign pio/mmio resource for pci devices - #182

Merged
junyu0312 merged 1 commit into
mainfrom
dev
Jun 25, 2026
Merged

junyu0312 merged 1 commit into
mainfrom
dev

Conversation

@junyu0312

@junyu0312 junyu0312 commented Jun 25, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • PCI-backed virtual devices now initialize with automatic BAR window allocation, improving device setup consistency.
    • Added clearer device transport handling for virtio and VFIO devices.
  • Bug Fixes

    • Improved PCI BAR reporting and routing so devices are mapped to the correct I/O or memory regions.
    • Enhanced error messages for several PCI-related failures to make troubleshooting easier.
  • Refactor

    • Streamlined PCI root complex and device construction to use shared allocation flows.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 51bf487d-4f77-474f-b605-bf2799753458

📥 Commits

Reviewing files that changed from the base of the PR and between fc1c2b0 and 997d6c1.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (15)
  • crates/vm-cli/src/cmd/device.rs
  • crates/vm-device/src/device/mod.rs
  • crates/vm-pci/src/device/function/type0.rs
  • crates/vm-pci/src/error.rs
  • crates/vm-pci/src/host_bridge.rs
  • crates/vm-pci/src/root_complex/pci_root_complex.rs
  • crates/vm-pci/src/root_complex_device.rs
  • crates/vm-pci/src/types/bar.rs
  • crates/vm-pci/src/types/function/type0.rs
  • crates/vm-vfio/Cargo.toml
  • crates/vm-vfio/src/vfio_pci/device.rs
  • crates/vm-vfio/src/vfio_pci/function.rs
  • crates/vm-virtio/src/transport/pci.rs
  • crates/vm-vmm/src/vm/device_builder.rs
  • crates/vm-vmm/src/vm/device_builder/vfio.rs

📝 Walkthrough

Walkthrough

Virtio device conversion now uses VirtioTransport. The PCI stack adds PciBarInfo, allocator-backed BAR programming, and allocator plumbing through Type0 functions, root-complex setup, VFIO PCI handling, virtio PCI transport, and VM device construction.

Changes

Virtio transport rename

Layer / File(s) Summary
Transport type rename
crates/vm-device/src/device/mod.rs, crates/vm-cli/src/cmd/device.rs
VirtioBlk, VirtioBalloon, and VirtioEntropy now use VirtioTransport, and the CLI conversion maps virtio devices to the renamed transport enum.

PCI BAR allocator flow

Layer / File(s) Summary
BAR contract
crates/vm-pci/src/types/bar.rs, crates/vm-pci/src/error.rs
PciBarInfo and BAR construction helpers are added, and PCI error variants gain explicit thiserror messages.
Type0 BAR programming
crates/vm-pci/src/device/function/type0.rs, crates/vm-pci/src/types/function/type0.rs, crates/vm-pci/src/host_bridge.rs
Type0 BAR reads and router updates use PciBarInfo, Type0Function programs BARs from allocator inputs, and HostBridgeFunction adopts bar_info() with allocator-aware construction.
Root complex allocators
crates/vm-pci/src/root_complex/pci_root_complex.rs, crates/vm-pci/src/root_complex_device.rs
PciRootComplex::new replaces Default, and PciRootComplexDevice::new threads allocator inputs into root-complex construction.
VFIO BAR allocation
crates/vm-vfio/Cargo.toml, crates/vm-vfio/src/vfio_pci/device.rs
VfioPciDevice::new allocates PCI BAR windows from passed allocators and stores PciBarInfo values.
VFIO BAR routing
crates/vm-vfio/src/vfio_pci/function.rs
VfioPciFunction switches BAR sizing and router callbacks to PciBarInfo.
Virtio PCI transport
crates/vm-virtio/src/transport/pci.rs
VirtioPciTransport reports PciBarInfo, builds Type0Function with allocators, and removes the TryFrom conversion path.
VM builder PCI wiring
crates/vm-vmm/src/vm/device_builder.rs, crates/vm-vmm/src/vm/device_builder/vfio.rs
DeviceManagerBuilder stores PCI allocators, installs them during PCI root-complex setup, and passes them into virtio and VFIO PCI device construction.

Sequence Diagram(s)

sequenceDiagram
  participant DeviceManagerBuilder
  participant PciRootComplexDevice
  participant VirtioPciDevice
  participant VirtioPciTransport
  participant Type0Function

  DeviceManagerBuilder->>PciRootComplexDevice: new(..., pci_pio_allocator, pci_mmio_allocator)
  DeviceManagerBuilder->>VirtioPciDevice: into_pci_device(pci_io_window_allocator, pci_mmio_window_allocator)
  VirtioPciDevice->>VirtioPciTransport: into_pci_device(pci_io_window_allocator, pci_mmio_window_allocator)
  VirtioPciTransport->>Type0Function: new_with_configuration_space(..., configuration_space, function)
  Type0Function-->>VirtioPciTransport: BARs programmed from bar_info()
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • junyu0312/rust-vm#170: Introduces the virtio transport enum and the same virtio PCI wiring that this PR renames and updates.
  • junyu0312/rust-vm#176: Touches the same PCI Type0 command-routing path that this PR refactors to use PciBarInfo.
  • junyu0312/rust-vm#169: Modifies the VFIO PCI device/function code that this PR updates for allocator-backed BAR handling.

Poem

🐇 I hopped through windows, BARs aglow,
and named the virtio paths anew.
The allocators now help things flow,
while PCI lines stay neat and true.
Hoppity! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@junyu0312
junyu0312 merged commit c5fe913 into main Jun 25, 2026
11 of 12 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant