From aabfc9513ec7f52204039347a15638bde75f5078 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Wed, 1 May 2024 14:46:04 -0700 Subject: [PATCH] hypervisor: implement pause/resume API for MSHV Implementing pause/Resume API for MSHV. Here we set/reset the partition property(TIME_FREEZE) Signed-off-by: Muminul Islam --- hypervisor/src/mshv/mod.rs | 32 ++++++++++++++++++++++++++++++++ hypervisor/src/vm.rs | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index b1b3a9c6c..bd5e9dfb3 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -2076,4 +2076,36 @@ impl vm::Vm for MshvVm { fn get_preferred_target(&self, kvi: &mut VcpuInit) -> vm::Result<()> { unimplemented!() } + + /// Pause the VM + fn pause(&self) -> vm::Result<()> { + // Freeze the partition + self.fd + .set_partition_property( + hv_partition_property_code_HV_PARTITION_PROPERTY_TIME_FREEZE, + 1u64, + ) + .map_err(|e| { + vm::HypervisorVmError::SetVmProperty(anyhow!( + "Failed to set partition property: {}", + e + )) + }) + } + + /// Resume the VM + fn resume(&self) -> vm::Result<()> { + // Resuming the partition using TIME_FREEZE property + self.fd + .set_partition_property( + hv_partition_property_code_HV_PARTITION_PROPERTY_TIME_FREEZE, + 0u64, + ) + .map_err(|e| { + vm::HypervisorVmError::SetVmProperty(anyhow!( + "Failed to set partition property: {}", + e + )) + }) + } } diff --git a/hypervisor/src/vm.rs b/hypervisor/src/vm.rs index bf57f2342..ed15ed9db 100644 --- a/hypervisor/src/vm.rs +++ b/hypervisor/src/vm.rs @@ -231,6 +231,10 @@ pub enum HypervisorVmError { /// #[error("Failed to complete isolated import: {0}")] CompleteIsolatedImport(#[source] anyhow::Error), + /// Failed to set VM property + /// + #[error("Failed to set VM property: {0}")] + SetVmProperty(#[source] anyhow::Error), } /// /// Result type for returning from a function