From 31209474b358c583ecd00f63fae0e637f4bb75c1 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 5 Dec 2022 15:43:30 +0100 Subject: [PATCH] vmm: Move TDX initialization before vCPUs creation TDX was broken by the recent refactoring moving the vCPU creation earlier than before. The simple and correct way to fix this problem is by moving the TDX initialization right before the vCPUs creation. The rest of the TDX setup can remain where it is. Signed-off-by: Sebastien Boeuf --- vmm/src/vm.rs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index c4837257e..1e9727037 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -551,6 +551,16 @@ impl Vm { ) .map_err(Error::CpuManager)?; + // The initial TDX configuration must be done before the vCPUs are + // created + #[cfg(feature = "tdx")] + if tdx_enabled { + let cpuid = cpu_manager.lock().unwrap().common_cpuid(); + let max_vcpus = cpu_manager.lock().unwrap().max_vcpus() as u32; + vm.tdx_init(&cpuid, max_vcpus) + .map_err(Error::InitializeTdxVm)?; + } + cpu_manager .lock() .unwrap() @@ -1638,16 +1648,6 @@ impl Vm { } } - #[cfg(feature = "tdx")] - fn init_tdx(&mut self) -> Result<()> { - let cpuid = self.cpu_manager.lock().unwrap().common_cpuid(); - let max_vcpus = self.cpu_manager.lock().unwrap().max_vcpus() as u32; - self.vm - .tdx_init(&cpuid, max_vcpus) - .map_err(Error::InitializeTdxVm)?; - Ok(()) - } - #[cfg(feature = "tdx")] fn extract_tdvf_sections(&mut self) -> Result> { use arch::x86_64::tdx::*; @@ -2059,13 +2059,6 @@ impl Vm { #[cfg(feature = "tdx")] let tdx_enabled = self.config.lock().unwrap().is_tdx_enabled(); - // The initial TDX configuration must be done before the vCPUs are - // created - #[cfg(feature = "tdx")] - if tdx_enabled { - self.init_tdx()?; - } - // Configure the vcpus that have been created let vcpus = self.cpu_manager.lock().unwrap().vcpus(); for vcpu in vcpus {