diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 5723e4915..683946f5f 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -2004,6 +2004,18 @@ impl Vm { }) .transpose()?; + #[cfg(target_arch = "x86_64")] + // Note: For x86, always call this function before invoking start boot vcpus. + // Otherwise guest would fail to boot because we haven't created the + // userspace mappings to update the hypervisor about the memory mappings. + // These mappings must be created before we start the vCPU threads for + // the very first time. + self.memory_manager + .lock() + .unwrap() + .allocate_address_space() + .map_err(Error::MemoryManager)?; + #[cfg(feature = "tdx")] if let Some(hob_address) = hob_address { // With the HOB address extracted the vCPUs can have @@ -2021,18 +2033,6 @@ impl Vm { self.vm.tdx_finalize().map_err(Error::FinalizeTdx)?; } - #[cfg(target_arch = "x86_64")] - // Note: For x86, always call this function before invoking start boot vcpus. - // Otherwise guest would fail to boot because we haven't created the - // userspace mappings to update the hypervisor about the memory mappings. - // These mappings must be created before we start the vCPU threads for - // the very first time. - self.memory_manager - .lock() - .unwrap() - .allocate_address_space() - .map_err(Error::MemoryManager)?; - self.cpu_manager .lock() .unwrap()