Skip to content

Commit

Permalink
vmm: pause/resume VM during the VM events
Browse files Browse the repository at this point in the history
For MSHV we always create frozen partition, so we
resume the VM during boot. Also during pause and resume
VM events we call hypervisor specific API.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
  • Loading branch information
russell-islam committed May 7, 2024
1 parent 9d4168f commit 75dd690
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions vmm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ pub enum Error {

#[error("Error injecting NMI")]
ErrorNmi,
#[cfg(feature = "mshv")]
#[error("Error unfreezing the VM: {0}")]
UnfreezeVm(#[source] hypervisor::HypervisorVmError),
}
pub type Result<T> = result::Result<T, Error>;

Expand Down Expand Up @@ -2173,6 +2176,11 @@ impl Vm {
self.vm.tdx_finalize().map_err(Error::FinalizeTdx)?;
}

// Unfreeze the vm for MSHV
#[cfg(feature = "mshv")]
if current_state == VmState::Created {
self.vm.resume().map_err(Error::UnfreezeVm)?;
}
self.cpu_manager
.lock()
.unwrap()
Expand Down Expand Up @@ -2487,6 +2495,11 @@ impl Pausable for Vm {
self.cpu_manager.lock().unwrap().pause()?;
self.device_manager.lock().unwrap().pause()?;

#[cfg(feature = "mshv")]
self.vm
.pause()
.map_err(|e| MigratableError::Pause(anyhow!("Could not freeze the VM: {}", e)))?;

*state = new_state;

event!("vm", "paused");
Expand All @@ -2495,6 +2508,8 @@ impl Pausable for Vm {

fn resume(&mut self) -> std::result::Result<(), MigratableError> {
event!("vm", "resuming");
#[cfg(feature = "mshv")]
let current_state = self.get_state().unwrap();
let mut state = self
.state
.try_write()
Expand All @@ -2514,6 +2529,13 @@ impl Pausable for Vm {
})?;
}
}
#[cfg(feature = "mshv")]
if current_state == VmState::Paused {
self.vm.resume().map_err(|e| {
MigratableError::Resume(anyhow!("Could not unfreeze the VM: {}", e))
})?;
}

self.device_manager.lock().unwrap().resume()?;

// And we're back to the Running state.
Expand Down

0 comments on commit 75dd690

Please sign in to comment.