From b1bd87df1932206b4c98549290075e12019da2e3 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 10 May 2022 17:00:17 +0100 Subject: [PATCH] vmm: Simplify MsiInterruptManager generics By taking advantage of the fact that IrqRoutingEntry is exported by the hypervisor crate (that is typedef'ed to the hypervisor specific version) then the code for handling the MsiInterruptManager can be simplified. This is particularly useful if in this future it is not a typedef but rather a wrapper type. Signed-off-by: Rob Bradford --- vmm/src/device_manager.rs | 5 +-- vmm/src/interrupt.rs | 76 +++++++++------------------------------ 2 files changed, 18 insertions(+), 63 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index a05fc7b22..b1b397f50 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -14,11 +14,8 @@ use crate::config::{ VdpaConfig, VhostMode, VmConfig, VsockConfig, }; use crate::device_tree::{DeviceNode, DeviceTree}; -#[cfg(feature = "kvm")] -use crate::interrupt::kvm::KvmMsiInterruptManager as MsiInterruptManager; -#[cfg(feature = "mshv")] -use crate::interrupt::mshv::MshvMsiInterruptManager as MsiInterruptManager; use crate::interrupt::LegacyUserspaceInterruptManager; +use crate::interrupt::MsiInterruptManager; use crate::memory_manager::MEMORY_MANAGER_ACPI_SIZE; use crate::memory_manager::{Error as MemoryManagerError, MemoryManager}; use crate::pci_segment::PciSegment; diff --git a/vmm/src/interrupt.rs b/vmm/src/interrupt.rs index 95ef748fb..68ebd1f9f 100644 --- a/vmm/src/interrupt.rs +++ b/vmm/src/interrupt.rs @@ -84,19 +84,19 @@ impl InterruptRoute { } } -pub struct RoutingEntry { +pub struct RoutingEntry { route: IrqRoutingEntry, masked: bool, } -pub struct MsiInterruptGroup { +pub struct MsiInterruptGroup { vm: Arc, - gsi_msi_routes: Arc>>>, + gsi_msi_routes: Arc>>, irq_routes: HashMap, } -impl MsiInterruptGroup { - fn set_gsi_routes(&self, routes: &HashMap>) -> Result<()> { +impl MsiInterruptGroup { + fn set_gsi_routes(&self, routes: &HashMap) -> Result<()> { let mut entry_vec: Vec = Vec::new(); for (_, entry) in routes.iter() { if entry.masked { @@ -115,10 +115,10 @@ impl MsiInterruptGroup { } } -impl MsiInterruptGroup { +impl MsiInterruptGroup { fn new( vm: Arc, - gsi_msi_routes: Arc>>>, + gsi_msi_routes: Arc>>, irq_routes: HashMap, ) -> Self { MsiInterruptGroup { @@ -129,7 +129,7 @@ impl MsiInterruptGroup { } } -impl InterruptSourceGroup for MsiInterruptGroup { +impl InterruptSourceGroup for MsiInterruptGroup { fn enable(&self) -> Result<()> { for (_, route) in self.irq_routes.iter() { route.enable(&self.vm)?; @@ -172,15 +172,17 @@ impl InterruptSourceGroup for MsiInterruptGroup { masked: bool, ) -> Result<()> { if let Some(route) = self.irq_routes.get(&index) { - let mut entry = RoutingEntry::<_>::make_entry(&self.vm, route.gsi, &config)?; - entry.masked = masked; + let entry = RoutingEntry { + route: self.vm.make_routing_entry(route.gsi, &config), + masked, + }; if masked { route.disable(&self.vm)?; } else { route.enable(&self.vm)?; } let mut routes = self.gsi_msi_routes.lock().unwrap(); - routes.insert(route.gsi, *entry); + routes.insert(route.gsi, entry); return self.set_gsi_routes(&routes); } @@ -234,10 +236,10 @@ pub struct LegacyUserspaceInterruptManager { ioapic: Arc>, } -pub struct MsiInterruptManager { +pub struct MsiInterruptManager { allocator: Arc>, vm: Arc, - gsi_msi_routes: Arc>>>, + gsi_msi_routes: Arc>>, } impl LegacyUserspaceInterruptManager { @@ -246,7 +248,7 @@ impl LegacyUserspaceInterruptManager { } } -impl MsiInterruptManager { +impl MsiInterruptManager { pub fn new(allocator: Arc>, vm: Arc) -> Self { // Create a shared list of GSI that can be shared through all PCI // devices. This way, we can maintain the full list of used GSI, @@ -277,7 +279,7 @@ impl InterruptManager for LegacyUserspaceInterruptManager { } } -impl InterruptManager for MsiInterruptManager { +impl InterruptManager for MsiInterruptManager { type GroupConfig = MsiIrqGroupConfig; fn create_group(&self, config: Self::GroupConfig) -> Result> { @@ -300,50 +302,6 @@ impl InterruptManager for MsiInterruptManager { } } -#[cfg(feature = "kvm")] -pub mod kvm { - use super::*; - use hypervisor::kvm::kvm_irq_routing_entry; - - type KvmRoutingEntry = RoutingEntry; - pub type KvmMsiInterruptManager = MsiInterruptManager; - - impl KvmRoutingEntry { - pub fn make_entry( - vm: &Arc, - gsi: u32, - config: &InterruptSourceConfig, - ) -> Result> { - Ok(Box::new(Self { - masked: false, - route: vm.make_routing_entry(gsi, config), - })) - } - } -} - -#[cfg(feature = "mshv")] -pub mod mshv { - use super::*; - use hypervisor::mshv::mshv_msi_routing_entry; - - type MshvRoutingEntry = RoutingEntry; - pub type MshvMsiInterruptManager = MsiInterruptManager; - - impl MshvRoutingEntry { - pub fn make_entry( - vm: &Arc, - gsi: u32, - config: &InterruptSourceConfig, - ) -> Result> { - Ok(Box::new(Self { - masked: false, - route: vm.make_routing_entry(gsi, config), - })) - } - } -} - #[cfg(target_arch = "aarch64")] #[cfg(test)] mod tests {