Skip to content

Commit

Permalink
hypervisor: implement freeze/unfreeze API for MSHV
Browse files Browse the repository at this point in the history
Implement freeze and unfreeze partition API for MSHV.
Here we set/reset the partition property(TIME_FREEZE)

Signed-off-by: Muminul Islam <muislam@microsoft.com>
  • Loading branch information
russell-islam committed May 3, 2024
1 parent 36029db commit a677ceb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions hypervisor/src/mshv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2083,4 +2083,26 @@ impl vm::Vm for MshvVm {
fn get_preferred_target(&self, kvi: &mut VcpuInit) -> vm::Result<()> {
unimplemented!()
}

/// Freeze the Partiton/VM
#[cfg(feature = "mshv")]
fn freeze_vm(&self) -> vm::Result<()> {
self.fd
.set_partition_property(
hv_partition_property_code_HV_PARTITION_PROPERTY_TIME_FREEZE,
1u64,
)
.map_err(|e| vm::HypervisorVmError::SetPartitionProperty(e.into()))
}

/// Unfreeze the Partiton/VM
#[cfg(feature = "mshv")]
fn unfreeze_vm(&self) -> vm::Result<()> {
self.fd
.set_partition_property(
hv_partition_property_code_HV_PARTITION_PROPERTY_TIME_FREEZE,
0u64,
)
.map_err(|e| vm::HypervisorVmError::SetPartitionProperty(e.into()))
}
}
5 changes: 5 additions & 0 deletions hypervisor/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ pub enum HypervisorVmError {
///
#[error("Failed to complete isolated import: {0}")]
CompleteIsolatedImport(#[source] anyhow::Error),
#[cfg(feature = "mshv")]
/// Failed to set partition property
///
#[error("Failed to set partition property: {0}")]
SetPartitionProperty(#[source] anyhow::Error),
}
///
/// Result type for returning from a function
Expand Down

0 comments on commit a677ceb

Please sign in to comment.