From 1d9f27c9fb7a84e07bfebbc754afdc50ade7a72f Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Wed, 24 Mar 2021 16:23:56 +0000 Subject: [PATCH] vmm: interrupt: extract common code from MSHV and KVM Their make_entry functions look the same now. Extract the logic to a common function. No functional change. Signed-off-by: Wei Liu --- vmm/src/interrupt.rs | 69 ++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/vmm/src/interrupt.rs b/vmm/src/interrupt.rs index 8f1424b1e..3ff1a3e53 100644 --- a/vmm/src/interrupt.rs +++ b/vmm/src/interrupt.rs @@ -98,6 +98,27 @@ pub trait MsiInterruptGroupOps { fn set_gsi_routes(&self, routes: &HashMap>) -> Result<()>; } +use hypervisor::IrqRoutingEntry; +impl MsiInterruptGroupOps for MsiInterruptGroup { + fn set_gsi_routes(&self, routes: &HashMap>) -> Result<()> { + let mut entry_vec: Vec = Vec::new(); + for (_, entry) in routes.iter() { + if entry.masked { + continue; + } + + entry_vec.push(entry.route); + } + + self.vm.set_gsi_routing(&entry_vec).map_err(|e| { + io::Error::new( + io::ErrorKind::Other, + format!("Failed setting GSI routing: {}", e), + ) + }) + } +} + pub trait RoutingEntryExt { fn make_entry( vm: &Arc, @@ -339,7 +360,6 @@ pub mod kvm { use hypervisor::kvm::KVM_MSI_VALID_DEVID; use hypervisor::kvm::{kvm_irq_routing_entry, KVM_IRQ_ROUTING_IRQCHIP, KVM_IRQ_ROUTING_MSI}; - type KvmMsiInterruptGroup = MsiInterruptGroup; type KvmRoutingEntry = RoutingEntry; pub type KvmMsiInterruptManager = MsiInterruptManager; @@ -393,29 +413,6 @@ pub mod kvm { )) } } - - impl MsiInterruptGroupOps for KvmMsiInterruptGroup { - fn set_gsi_routes( - &self, - routes: &HashMap>, - ) -> Result<()> { - let mut entry_vec: Vec = Vec::new(); - for (_, entry) in routes.iter() { - if entry.masked { - continue; - } - - entry_vec.push(entry.route); - } - - self.vm.set_gsi_routing(&entry_vec).map_err(|e| { - io::Error::new( - io::ErrorKind::Other, - format!("Failed setting GSI routing: {}", e), - ) - }) - } - } } #[cfg(feature = "mshv")] @@ -423,7 +420,6 @@ pub mod mshv { use super::*; use hypervisor::mshv::*; - type MshvMsiInterruptGroup = MsiInterruptGroup; type MshvRoutingEntry = RoutingEntry; pub type MshvMsiInterruptManager = MsiInterruptManager; @@ -454,29 +450,6 @@ pub mod mshv { )) } } - - impl MsiInterruptGroupOps for MshvMsiInterruptGroup { - fn set_gsi_routes( - &self, - routes: &HashMap>, - ) -> Result<()> { - let mut entry_vec: Vec = Vec::new(); - for (_, entry) in routes.iter() { - if entry.masked { - continue; - } - - entry_vec.push(entry.route); - } - - self.vm.set_gsi_routing(&entry_vec).map_err(|e| { - io::Error::new( - io::ErrorKind::Other, - format!("Failed setting GSI routing: {}", e), - ) - }) - } - } } #[cfg(target_arch = "aarch64")]