From 23bb6292413fd4e60b293ec39043fd2ac29db663 Mon Sep 17 00:00:00 2001 From: Akira Moroo Date: Fri, 4 Feb 2022 18:51:31 +0900 Subject: [PATCH] vmm: Add `stop_on_boot` to `Vm` to stop VM on boot This commit adds `stop_on_boot` to `Vm` so that the VM stops before starting on boot requested. This change is required to keep the target VM stopped before a debugger attached as the user expected. Signed-off-by: Akira Moroo --- vmm/src/vm.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 5ddb772f4..6d72b55c4 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -541,6 +541,7 @@ pub struct Vm { exit_evt: EventFd, #[cfg(all(feature = "kvm", target_arch = "x86_64"))] hypervisor: Arc, + stop_on_boot: bool, } impl Vm { @@ -574,6 +575,8 @@ impl Vm { #[cfg(not(feature = "tdx"))] let force_iommu = false; + let stop_on_boot = false; + let device_manager = DeviceManager::new( vm.clone(), config.clone(), @@ -670,6 +673,7 @@ impl Vm { exit_evt, #[cfg(all(feature = "kvm", target_arch = "x86_64"))] hypervisor, + stop_on_boot, }) } @@ -2009,7 +2013,11 @@ impl Vm { return self.resume().map_err(Error::Resume); } - let new_state = VmState::Running; + let new_state = if self.stop_on_boot { + VmState::BreakPoint + } else { + VmState::Running + }; current_state.valid_transition(new_state)?; // Load kernel if configured @@ -2077,11 +2085,13 @@ impl Vm { self.vm.tdx_finalize().map_err(Error::FinalizeTdx)?; } - self.cpu_manager - .lock() - .unwrap() - .start_boot_vcpus() - .map_err(Error::CpuManager)?; + if new_state == VmState::Running { + self.cpu_manager + .lock() + .unwrap() + .start_boot_vcpus() + .map_err(Error::CpuManager)?; + } self.setup_signal_handler()?; self.setup_tty()?;