Skip to content

virt: add irqfd trait and implement for mshv and KVM#3206

Open
will-j-wright wants to merge 1 commit intomicrosoft:mainfrom
will-j-wright:irqfd-pr
Open

virt: add irqfd trait and implement for mshv and KVM#3206
will-j-wright wants to merge 1 commit intomicrosoft:mainfrom
will-j-wright:irqfd-pr

Conversation

@will-j-wright
Copy link
Copy Markdown
Contributor

Add irqfd support enabling the kernel to inject MSIs directly into the guest when an event is signaled, without a userspace transition. This is required for VFIO device passthrough where physical device interrupts must be delivered to the guest via the hypervisor's irqfd mechanism.

New traits

  • IrqFd — creates irqfd routes (GSI allocation + event registration)
  • IrqFdRoute — manages per-vector MSI routing, masking, and pending state for PBA support
  • Partition::irqfd() — returns the irqfd interface if the backend supports it

The event is created by the implementation rather than provided by the caller. This accommodates backends like WHP where the hypervisor owns the event handle (WHvCreateTrigger).

mshv implementation

  • GSI allocation table (2048 slots)
  • MSHV_IRQFD ioctl for register/unregister eventfds
  • MSHV_SET_MSI_ROUTING ioctl to push full routing table atomically
  • Automatic cleanup on route drop; GSI only freed on successful unregister

KVM implementation

  • KvmIrqFdState wraps existing GsiRoute infrastructure
  • KvmIrqFdRoute delegates to GsiRoute::enable/disable

Testing

End-to-end with VFIO NVMe passthrough on mshv.

@will-j-wright will-j-wright requested a review from a team as a code owner April 6, 2026 21:17
Copilot AI review requested due to automatic review settings April 6, 2026 21:17
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

@github-actions github-actions bot added the unsafe Related to unsafe code label Apr 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 introduces an irqfd abstraction to the virt layer and wires up backend implementations for mshv and KVM, enabling kernel-assisted MSI injection (needed for VFIO-style interrupt delivery without userspace transitions).

Changes:

  • Add new virt::irqfd module defining IrqFd / IrqFdRoute traits and Partition::irqfd() capability hook.
  • Implement irqfd + MSI routing for mshv (GSI allocation, MSHV_IRQFD, atomic MSHV_SET_MSI_ROUTING updates).
  • Implement irqfd support for KVM by wrapping existing GsiRoute infrastructure and exposing it via Partition::irqfd() on x86_64.

Reviewed changes

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

Show a summary per file
File Description
vmm_core/virt/src/lib.rs Exposes the new irqfd module.
vmm_core/virt/src/irqfd.rs Adds IrqFd / IrqFdRoute traits and semantics for MSI routing + mask/unmask behavior.
vmm_core/virt/src/generic.rs Adds Partition::irqfd() optional capability entrypoint.
vmm_core/virt_mshv/src/lib.rs Stores shared MshvIrqFdState in the partition and exposes it via Partition::irqfd().
vmm_core/virt_mshv/src/irqfd.rs New mshv irqfd implementation: GSI table + irqfd registration + full routing table push.
vmm_core/virt_mshv/Cargo.toml Adds headervec dependency for variable-length ioctl buffer building.
vmm_core/virt_kvm/src/gsi.rs Adds KvmIrqFdState/KvmIrqFdRoute wrapper implementing the new traits.
vmm_core/virt_kvm/src/arch/x86_64/mod.rs Wires Partition::irqfd() for KVM x86_64 partitions.

Add irqfd support enabling the kernel to inject MSIs directly into the
guest when an eventfd is signaled, without a userspace transition. This
is required for VFIO device passthrough where physical device interrupts
must be delivered to the guest via the hypervisor's irqfd mechanism.

New traits in virt crate:
- IrqFd: allocates GSIs and registers eventfds as irqfd routes
- IrqFdRoute: updates/clears MSI routing (address/data) per GSI
- Partition::irqfd(): returns the irqfd interface if supported

mshv implementation (virt_mshv/src/irqfd.rs):
- GSI allocation table (2048 slots)
- MSHV_IRQFD ioctl for register/unregister eventfds
- MSHV_SET_MSI_ROUTING ioctl to push full routing table
- Automatic cleanup on route drop (unregister + free GSI)
- VmFd changed to Arc<VmFd> for shared ownership

KVM implementation (virt_kvm/src/gsi.rs):
- KvmIrqFdState wraps existing GsiRoute infrastructure
- KvmIrqFdRoute delegates to GsiRoute::enable/disable
- Partition::irqfd() wired in x86_64 arch module

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants