KVM: x86/mmu: Check for usable TDP MMU root while holding mmu_lock for read
[linux-block.git] / arch / x86 / kvm / mmu / mmu.c
index 3c193b096b451d2b793cbee5d7f73eab8dc1b656..c9150080fbd221f823276fa08553d36722e691bd 100644 (file)
@@ -3693,15 +3693,15 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu)
        unsigned i;
        int r;
 
+       if (tdp_mmu_enabled)
+               return kvm_tdp_mmu_alloc_root(vcpu);
+
        write_lock(&vcpu->kvm->mmu_lock);
        r = make_mmu_pages_available(vcpu);
        if (r < 0)
                goto out_unlock;
 
-       if (tdp_mmu_enabled) {
-               root = kvm_tdp_mmu_get_vcpu_root_hpa(vcpu);
-               mmu->root.hpa = root;
-       } else if (shadow_root_level >= PT64_ROOT_4LEVEL) {
+       if (shadow_root_level >= PT64_ROOT_4LEVEL) {
                root = mmu_alloc_root(vcpu, 0, 0, shadow_root_level);
                mmu->root.hpa = root;
        } else if (shadow_root_level == PT32E_ROOT_LEVEL) {