diff --git a/hypervisor/src/hypervisor.rs b/hypervisor/src/hypervisor.rs index 3ad975abb..dc628c932 100644 --- a/hypervisor/src/hypervisor.rs +++ b/hypervisor/src/hypervisor.rs @@ -12,8 +12,6 @@ use crate::arch::x86::CpuIdEntry; #[cfg(feature = "tdx")] use crate::kvm::TdxCapabilities; use crate::vm::Vm; -#[cfg(target_arch = "x86_64")] -use crate::x86_64::MsrList; use std::sync::Arc; use thiserror::Error; @@ -107,11 +105,6 @@ pub trait Hypervisor: Send + Sync { fn check_required_extensions(&self) -> Result<()> { Ok(()) } - #[cfg(target_arch = "x86_64")] - /// - /// Retrieve the list of MSRs supported by the hypervisor. - /// - fn get_msr_list(&self) -> Result; #[cfg(target_arch = "aarch64")] /// /// Retrieve AArch64 host maximum IPA size supported by KVM. diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index 4fe12f0f8..7e8be2ca8 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -875,6 +875,19 @@ fn tdx_command( pub struct KvmHypervisor { kvm: Kvm, } + +impl KvmHypervisor { + #[cfg(target_arch = "x86_64")] + /// + /// Retrieve the list of MSRs supported by the hypervisor. + /// + fn get_msr_list(&self) -> hypervisor::Result { + self.kvm + .get_msr_index_list() + .map_err(|e| hypervisor::HypervisorError::GetMsrList(e.into())) + } +} + /// Enum for KVM related error #[derive(Debug, Error)] pub enum KvmError { @@ -1003,15 +1016,6 @@ impl hypervisor::Hypervisor for KvmHypervisor { Ok(v) } - #[cfg(target_arch = "x86_64")] - /// - /// Retrieve the list of MSRs supported by KVM. - /// - fn get_msr_list(&self) -> hypervisor::Result { - self.kvm - .get_msr_index_list() - .map_err(|e| hypervisor::HypervisorError::GetMsrList(e.into())) - } #[cfg(target_arch = "aarch64")] /// /// Retrieve AArch64 host maximum IPA size supported by KVM. diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index 39fe4eabf..40147a817 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -160,6 +160,18 @@ pub struct MshvHypervisor { mshv: Mshv, } +impl MshvHypervisor { + #[cfg(target_arch = "x86_64")] + /// + /// Retrieve the list of MSRs supported by MSHV. + /// + fn get_msr_list(&self) -> hypervisor::Result { + self.mshv + .get_msr_index_list() + .map_err(|e| hypervisor::HypervisorError::GetMsrList(e.into())) + } +} + impl MshvHypervisor { /// Create a hypervisor based on Mshv pub fn new() -> hypervisor::Result { @@ -238,15 +250,6 @@ impl hypervisor::Hypervisor for MshvHypervisor { fn get_cpuid(&self) -> hypervisor::Result> { Ok(Vec::new()) } - #[cfg(target_arch = "x86_64")] - /// - /// Retrieve the list of MSRs supported by MSHV. - /// - fn get_msr_list(&self) -> hypervisor::Result { - self.mshv - .get_msr_index_list() - .map_err(|e| hypervisor::HypervisorError::GetMsrList(e.into())) - } } #[allow(dead_code)]