From 77634a3c05ceaabe7be39dcda51e7400e8bf5095 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Mon, 16 Oct 2023 11:04:17 -0700 Subject: [PATCH] vmm: tdx: Fix a deadlock while accessing `vm_config` The lock to `vm_config` is held for accessing `cpus.kvm_hyperv` passing as a reference to `arch::generate_common_cpuid()`, so acquiring the same lock again while calling to the same function is a deadlock. Fixes: https://github.com/cloud-hypervisor/cloud-hypervisor/commit/3793ffe888dbc9c4aaf929d1b4846e50f1122d6c Reported-by: Yi Wang Signed-off-by: Bo Chen (cherry picked from commit aa6e83126cf50bc5b334deb74ebff606d8cf2beb) --- vmm/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index ec12c9002..afa2cc7ab 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -1471,6 +1471,8 @@ impl Vmm { let vm_config = vm.get_config(); #[cfg(all(feature = "kvm", target_arch = "x86_64"))] let common_cpuid = { + #[cfg(feature = "tdx")] + let tdx_enabled = vm_config.lock().unwrap().is_tdx_enabled(); let phys_bits = vm::physical_bits(vm_config.lock().unwrap().cpus.max_phys_bits); arch::generate_common_cpuid( hypervisor, @@ -1479,7 +1481,7 @@ impl Vmm { phys_bits, vm_config.lock().unwrap().cpus.kvm_hyperv, #[cfg(feature = "tdx")] - vm_config.lock().unwrap().is_tdx_enabled(), + tdx_enabled, ) .map_err(|e| { MigratableError::MigrateReceive(anyhow!("Error generating common cpuid': {:?}", e))