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 <muislam@microsoft.com>
This commit is contained in:
Muminul Islam 2021-06-17 15:50:36 -07:00 committed by Bo Chen
parent cff190fa5f
commit 5cd82cb2e2
3 changed files with 23 additions and 2 deletions

View File

@ -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<SuspendRegisters>;
}

View File

@ -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<SuspendRegisters> {
self.fd
.get_suspend_regs()
.map_err(|e| cpu::HypervisorCpuError::GetSuspendRegs(e.into()))
}
}
struct MshvEmulatorContext<'a> {

View File

@ -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)]