From 5cd82cb2e23ed89a573ee2cfe33f0266e1c1d1d7 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Thu, 17 Jun 2021 15:50:36 -0700 Subject: [PATCH] hypervisor: implement get_suspend_regs for MSHV vcpu trait This vcpu API is necessary for MSHV related debugging. These two registers controls the vcpu_run in the /dev/mshv driver code. Signed-off-by: Muminul Islam --- hypervisor/src/cpu.rs | 12 ++++++++++++ hypervisor/src/mshv/mod.rs | 9 +++++++++ hypervisor/src/mshv/x86_64/mod.rs | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/hypervisor/src/cpu.rs b/hypervisor/src/cpu.rs index d49c85415..1cffb88ed 100644 --- a/hypervisor/src/cpu.rs +++ b/hypervisor/src/cpu.rs @@ -21,6 +21,8 @@ use crate::x86_64::{ use crate::CpuState; #[cfg(feature = "kvm")] use crate::MpState; +#[cfg(all(feature = "mshv", target_arch = "x86_64"))] +use crate::SuspendRegisters; #[cfg(target_arch = "x86_64")] use crate::Xsave; #[cfg(feature = "mshv")] @@ -42,6 +44,11 @@ pub enum HypervisorCpuError { #[error("Failed to get standard registers: {0}")] GetStandardRegs(#[source] anyhow::Error), /// + /// Getting suspend registers error + /// + #[error("Failed to get suspend registers: {0}")] + GetSuspendRegs(#[source] anyhow::Error), + /// /// Setting special register error /// #[error("Failed to set special registers: {0}")] @@ -421,4 +428,9 @@ pub trait Vcpu: Send + Sync { /// #[cfg(feature = "tdx")] fn tdx_init(&self, hob_address: u64) -> Result<()>; + #[cfg(all(feature = "mshv", target_arch = "x86_64"))] + /// + /// Return suspend registers(explicit and intercept suspend registers) + /// + fn get_suspend_regs(&self) -> Result; } diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index 781d00d11..3c0120c13 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -534,6 +534,15 @@ impl cpu::Vcpu for MshvVcpu { Ok(r) } + #[cfg(target_arch = "x86_64")] + /// + /// X86 specific call that returns the vcpu's current "suspend registers". + /// + fn get_suspend_regs(&self) -> cpu::Result { + self.fd + .get_suspend_regs() + .map_err(|e| cpu::HypervisorCpuError::GetSuspendRegs(e.into())) + } } struct MshvEmulatorContext<'a> { diff --git a/hypervisor/src/mshv/x86_64/mod.rs b/hypervisor/src/mshv/x86_64/mod.rs index e1a204945..11aae6248 100644 --- a/hypervisor/src/mshv/x86_64/mod.rs +++ b/hypervisor/src/mshv/x86_64/mod.rs @@ -19,8 +19,8 @@ pub use { mshv_bindings::FloatingPointUnit as FpuState, mshv_bindings::LapicState, mshv_bindings::MsrList, mshv_bindings::Msrs as MsrEntries, mshv_bindings::Msrs, mshv_bindings::SegmentRegister, mshv_bindings::SpecialRegisters, - mshv_bindings::StandardRegisters, mshv_bindings::VcpuEvents, mshv_bindings::XSave as Xsave, - mshv_bindings::Xcrs as ExtendedControlRegisters, + mshv_bindings::StandardRegisters, mshv_bindings::SuspendRegisters, mshv_bindings::VcpuEvents, + mshv_bindings::XSave as Xsave, mshv_bindings::Xcrs as ExtendedControlRegisters, }; #[derive(Clone, Serialize, Deserialize)]