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