virt: add irqfd trait and implement for mshv and KVM#3194
Open
will-j-wright wants to merge 1 commit intomicrosoft:mainfrom
Open
virt: add irqfd trait and implement for mshv and KVM#3194will-j-wright wants to merge 1 commit intomicrosoft:mainfrom
will-j-wright wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a cross-backend irqfd abstraction in virt and wires up backend implementations for mshv and KVM so VFIO-style MSI/MSI-X interrupts can be injected by the kernel on eventfd signal (avoiding userspace transitions).
Changes:
- Added
virt::irqfdtraits and aPartition::irqfd()entry point to access irqfd routing when supported. - Implemented mshv irqfd + MSI routing support (GSI allocation +
MSHV_IRQFD/MSHV_SET_MSI_ROUTINGioctls), including sharedVmFdownership viaArc. - Implemented KVM irqfd support by wrapping existing
GsiRouteinfrastructure and exposing it through the new traits.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| vmm_core/virt/src/lib.rs | Exposes the new irqfd module from the virt crate. |
| vmm_core/virt/src/irqfd.rs | Defines the new IrqFd / IrqFdRoute traits and access patterns. |
| vmm_core/virt/src/generic.rs | Adds Partition::irqfd() default method returning None for unsupported backends. |
| vmm_core/virt_mshv/src/lib.rs | Wires mshv partition to provide irqfd support; switches VmFd storage to Arc<VmFd>. |
| vmm_core/virt_mshv/src/irqfd.rs | Implements irqfd + MSI routing table management for mshv via ioctls. |
| vmm_core/virt_kvm/src/gsi.rs | Adds KvmIrqFdState/KvmIrqFdRoute backed by existing GsiRoute. |
| vmm_core/virt_kvm/src/arch/x86_64/mod.rs | Exposes KVM irqfd support through Partition::irqfd() on x86_64. |
Comments suppressed due to low confidence (1)
vmm_core/virt_kvm/src/gsi.rs:152
KvmIrqFdRoute::set_msi/clear_msialways returnOk(()), but the underlyingGsiRoute::enable/disablepaths can panic on KVM ioctl failures (set_gsi_routes(...).expect("should not fail"),kvm.irqfd(...).expect("should not fail")). Since the newIrqFdRouteAPI is fallible, it would be better to plumb errors through instead of panicking (change enable/disable/update_routes/irqfd calls to returnResultand propagate up).
pub fn enable(&self, entry: kvm::RoutingEntry) {
let partition = self.set_entry(Some(entry));
let _lock = self.enable_mutex.lock();
if !self.enabled.load(Ordering::Relaxed) {
if let (Some(partition), Some(event)) = (&partition, &self.irqfd_event) {
partition
.kvm
.irqfd(self.gsi, event.as_fd().as_raw_fd(), true)
.expect("should not fail");
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>
e0cc2a5 to
9ee6044
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 routesIrqFdRoute: updates/clears MSI routing (address/data) per GSIPartition::irqfd(): returns the irqfd interface if supportedmshv implementation (
virt_mshv/src/irqfd.rs):MSHV_IRQFDioctl for register/unregister eventfdsMSHV_SET_MSI_ROUTINGioctl to push full routing tableVmFdchanged toArc<VmFd>for shared ownershipKVM implementation (
virt_kvm/src/gsi.rs):KvmIrqFdStatewraps existingGsiRouteinfrastructureKvmIrqFdRoutedelegates toGsiRoute::enable/disablePartition::irqfd()wired in x86_64 arch moduleTested: End-to-end with VFIO NVMe passthrough on mshv (L1 Azure Linux VM → L2 guest). NVMe driver probes, reads 100MB at 425MB/s with MSI-X interrupts delivered via irqfd.