Skip to content

feat: Introduce InterruptManager - #184

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

junyu0312 merged 1 commit into
mainfrom
dev

Conversation

@junyu0312

@junyu0312 junyu0312 commented Jun 30, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Introduced a more flexible interrupt management system across VM setup and device initialization.
    • Added support for dynamic IRQ and GSI allocation for supported devices.
  • Bug Fixes

    • Improved interrupt handling consistency across architectures.
    • Updated device creation flows to reduce allocation failures and provide clearer error reporting.
    • Refreshed VFIO and virtio interrupt setup to better support multi-vector devices.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@junyu0312, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 50 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e68ae983-2602-4c93-888d-f2facc3a522e

📥 Commits

Reviewing files that changed from the base of the PR and between c62f5a0 and 2130655.

📒 Files selected for processing (24)
  • crates/vm-core/src/arch/aarch64/layout.rs
  • crates/vm-core/src/arch/x86_64/layout.rs
  • crates/vm-core/src/interrupt_manager.rs
  • crates/vm-core/src/lib.rs
  • crates/vm-core/src/virtualization.rs
  • crates/vm-core/src/virtualization/hvp/vm.rs
  • crates/vm-core/src/virtualization/irq_allocator.rs
  • crates/vm-core/src/virtualization/kvm/vm.rs
  • crates/vm-core/src/virtualization/vm.rs
  • crates/vm-core/src/virtualization/vm/error.rs
  • crates/vm-vfio/src/vfio_pci/device.rs
  • crates/vm-vfio/src/vfio_pci/function.rs
  • crates/vm-vfio/src/vfio_pci/interrupt/msi.rs
  • crates/vm-vfio/src/vfio_pci/interrupt/msix.rs
  • crates/vm-virtio/src/device.rs
  • crates/vm-virtio/src/result.rs
  • crates/vm-virtio/src/transport/pci.rs
  • crates/vm-vmm/src/device/error.rs
  • crates/vm-vmm/src/vm/config.rs
  • crates/vm-vmm/src/vm/device_builder.rs
  • crates/vm-vmm/src/vm/device_builder/arch/aarch64.rs
  • crates/vm-vmm/src/vm/device_builder/vfio.rs
  • crates/vm-vmm/src/vm/snapshot.rs
  • crates/vm-vmm/src/vmm/error.rs
📝 Walkthrough

Walkthrough

Removes the ad-hoc IrqAllocator module and replaces it with a new centralized InterruptManager backed by mutex-protected RangeAllocator<u32>. Layout constants are renamed from *_END to *_LEN and GSI allocation constants are added for x86_64. The manager is threaded through HypervisorVm, virtio transports, VFIO PCI, and VMM device construction.

Changes

InterruptManager Rollout

Layer / File(s) Summary
Layout constants: rename to LEN, add GSI
crates/vm-core/src/arch/aarch64/layout.rs, crates/vm-core/src/arch/x86_64/layout.rs
IRQ_ALLOCATION_END: u32 renamed to IRQ_ALLOCATION_LEN: usize on both architectures; x86_64 adds GSI_ALLOCATION_START and GSI_ALLOCATION_LEN.
InterruptManager core: errors, Allocator, methods
crates/vm-core/src/interrupt_manager.rs, crates/vm-core/src/lib.rs, crates/vm-core/src/virtualization.rs
Introduces InterruptManagerError enum, internal Allocator newtype over Mutex<RangeAllocator<u32>>, and InterruptManager struct with IRQ/GSI pools. Implements reserve_irq, allocate_irq, and arch-gated allocate_gsi. Removes old irq_allocator module export.
HypervisorVm trait + impls: create_irq_manager
crates/vm-core/src/virtualization/vm.rs, crates/vm-core/src/virtualization/vm/error.rs, crates/vm-core/src/virtualization/hvp/vm.rs, crates/vm-core/src/virtualization/kvm/vm.rs
Renames trait method to create_irq_manager returning InterruptManager; updates VmError to wrap InterruptManagerError; both AppleHypervisorVm and KvmVm impls construct InterruptManager using layout constants.
VFIO PCI: dynamic GSI allocation for INTx/MSI/MSI-X
crates/vm-vfio/src/vfio_pci/interrupt/msi.rs, crates/vm-vfio/src/vfio_pci/interrupt/msix.rs, crates/vm-vfio/src/vfio_pci/device.rs, crates/vm-vfio/src/vfio_pci/function.rs
Adds gsi: Vec<Option<u32>> to VfioMsi/VfioMsix; VfioPciDevice::new accepts Arc<InterruptManager>; INTx uses allocate_irq; VfioPciFunction stores the manager and calls allocate_gsi per MSI/MSI-X vector instead of hardcoded 32 + vector.
Virtio MMIO/PCI transport: InterruptManager threading
crates/vm-virtio/src/device.rs, crates/vm-virtio/src/result.rs, crates/vm-virtio/src/transport/pci.rs
into_mmio_device and into_pci_device/into_virtio_pci_device replace &mut IrqAllocator with &InterruptManager; VirtioError::AllocIrq now wraps InterruptManagerError; new AllocId variant added for ID allocation failures.
VMM DeviceManagerBuilder and error wiring
crates/vm-vmm/src/device/error.rs, crates/vm-vmm/src/vm/device_builder.rs, crates/vm-vmm/src/vm/device_builder/arch/aarch64.rs, crates/vm-vmm/src/vm/device_builder/vfio.rs, crates/vm-vmm/src/vm/config.rs, crates/vm-vmm/src/vm/snapshot.rs, crates/vm-vmm/src/vmm/error.rs
DeviceManagerBuilder stores Arc<InterruptManager>; all device construction sites pass &self.interrupt_manager; Pl011 uses allocate_irq(); config/snapshot use create_irq_manager(); InitDeviceError and VmmError gain #[from] variants for InterruptManagerError.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • junyu0312/rust-vm#172: Originally introduced IrqAllocator and create_irq_allocator wiring that this PR directly replaces.
  • junyu0312/rust-vm#174: Modifies the same vfio_pci/device.rs and vfio_pci/function.rs interrupt/GSI handling that this PR refactors.
  • junyu0312/rust-vm#181: Adds VFIO interrupt remapping/irqfd routing in the same vfio_pci interrupt-capability initialization code paths changed here.

Poem

🐇 Hop hop, the allocator's gone away,
A RangeAllocator guards the IRQ today.
GSI and IRQ, each in their own den,
Wrapped in a Mutex, safe from rabbit and hen.
No more 32 + vector tricks, oh my!
The InterruptManager rules—hip hip hooray! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: introducing InterruptManager.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 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 f9a2e64 into main Jun 30, 2026
11 of 12 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/vm-core/src/virtualization/kvm/vm.rs`:
- Around line 11-13: Add the same target_arch guard to the aarch64
IRQ_ALLOCATION_LEN import in vm:: imports so it only compiles on aarch64,
matching IRQ_ALLOCATION_START and the x86_64 IRQ_ALLOCATION_LEN import. Update
the import block in the vm module to keep the aarch64 symbols under
#[cfg(target_arch = "aarch64")] and leave the x86_64 symbol under its existing
cfg to avoid duplicate-name conflicts and unresolved imports on x86_64 builds.

In `@crates/vm-vfio/src/vfio_pci/function.rs`:
- Around line 147-153: The MSI/MSI-X update path in Function::write and the
related GSI allocation logic currently calls allocate_gsi().unwrap(), which can
panic and abort the VM when the shared GSI pool is exhausted. Update the
interrupt setup/update flow around msi.gsi handling so GSI allocation failures
are returned as a Result instead of unwrapping, and propagate
InterruptManagerError back through the write/update path; if easier, preallocate
per-vector GSIs during interrupt setup and reuse them in Function::write.

In `@crates/vm-virtio/src/transport/pci.rs`:
- Around line 118-124: The non-Linux PCI legacy IRQ setup in
VirtioPciTransport::new currently unwraps allocate_irq() and the IRQ conversion,
which can panic instead of surfacing failures. Update VirtioPciTransport::new to
return Result<Self> and propagate errors from interrupt_manager.allocate_irq()
and the try_into conversion, then adjust into_virtio_pci_device to handle the
new Result-returning constructor path without unwrapping.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d8beb1f0-52f1-4ba9-879f-c5fae42701ed

📥 Commits

Reviewing files that changed from the base of the PR and between 9baeabe and c62f5a0.

📒 Files selected for processing (24)
  • crates/vm-core/src/arch/aarch64/layout.rs
  • crates/vm-core/src/arch/x86_64/layout.rs
  • crates/vm-core/src/interrupt_manager.rs
  • crates/vm-core/src/lib.rs
  • crates/vm-core/src/virtualization.rs
  • crates/vm-core/src/virtualization/hvp/vm.rs
  • crates/vm-core/src/virtualization/irq_allocator.rs
  • crates/vm-core/src/virtualization/kvm/vm.rs
  • crates/vm-core/src/virtualization/vm.rs
  • crates/vm-core/src/virtualization/vm/error.rs
  • crates/vm-vfio/src/vfio_pci/device.rs
  • crates/vm-vfio/src/vfio_pci/function.rs
  • crates/vm-vfio/src/vfio_pci/interrupt/msi.rs
  • crates/vm-vfio/src/vfio_pci/interrupt/msix.rs
  • crates/vm-virtio/src/device.rs
  • crates/vm-virtio/src/result.rs
  • crates/vm-virtio/src/transport/pci.rs
  • crates/vm-vmm/src/device/error.rs
  • crates/vm-vmm/src/vm/config.rs
  • crates/vm-vmm/src/vm/device_builder.rs
  • crates/vm-vmm/src/vm/device_builder/arch/aarch64.rs
  • crates/vm-vmm/src/vm/device_builder/vfio.rs
  • crates/vm-vmm/src/vm/snapshot.rs
  • crates/vm-vmm/src/vmm/error.rs
💤 Files with no reviewable changes (2)
  • crates/vm-core/src/virtualization/irq_allocator.rs
  • crates/vm-core/src/virtualization.rs

Comment thread crates/vm-core/src/virtualization/kvm/vm.rs
Comment on lines +147 to +153
let gsi = if let Some(gsi) = msi.gsi[vector] {
gsi
} else {
let gsi = self.irq_manager.allocate_gsi().unwrap();
msi.gsi[vector] = Some(gsi);
gsi
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Propagate GSI allocation failures instead of panicking.

allocate_gsi().unwrap() can abort the VM when the shared GSI pool is exhausted. Since these paths are reached from MSI/MSI-X configuration updates, either preallocate per-vector GSIs during interrupt setup or make the update/write path return a Result and surface InterruptManagerError.

Also applies to: 360-366

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/vm-vfio/src/vfio_pci/function.rs` around lines 147 - 153, The
MSI/MSI-X update path in Function::write and the related GSI allocation logic
currently calls allocate_gsi().unwrap(), which can panic and abort the VM when
the shared GSI pool is exhausted. Update the interrupt setup/update flow around
msi.gsi handling so GSI allocation failures are returned as a Result instead of
unwrapping, and propagate InterruptManagerError back through the write/update
path; if easier, preallocate per-vector GSIs during interrupt setup and reuse
them in Function::write.

Comment on lines +118 to +124
legacy_int = Some(
interrupt_manager
.allocate_irq()
.unwrap()
.try_into()
.unwrap(),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Return allocation errors from non-Linux PCI legacy IRQ setup.

This constructor path can panic if allocate_irq() fails. Since into_virtio_pci_device already returns Result, make VirtioPciTransport::new return Result<Self> and propagate the allocation/conversion errors instead of unwrapping.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/vm-virtio/src/transport/pci.rs` around lines 118 - 124, The non-Linux
PCI legacy IRQ setup in VirtioPciTransport::new currently unwraps allocate_irq()
and the IRQ conversion, which can panic instead of surfacing failures. Update
VirtioPciTransport::new to return Result<Self> and propagate errors from
interrupt_manager.allocate_irq() and the try_into conversion, then adjust
into_virtio_pci_device to handle the new Result-returning constructor path
without unwrapping.

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