]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
kvm: x86: vmx: fix vpid leak
authorRoman Kagan <rkagan@virtuozzo.com>
Thu, 19 Jul 2018 18:59:07 +0000 (21:59 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 20 Jul 2018 16:07:22 +0000 (18:07 +0200)
VPID for the nested vcpu is allocated at vmx_create_vcpu whenever nested
vmx is turned on with the module parameter.

However, it's only freed if the L1 guest has executed VMXON which is not
a given.

As a result, on a system with nested==on every creation+deletion of an
L1 vcpu without running an L2 guest results in leaking one vpid.  Since
the total number of vpids is limited to 64k, they can eventually get
exhausted, preventing L2 from starting.

Delay allocation of the L2 vpid until VMXON emulation, thus matching its
freeing.

Fixes: 5c614b3583e7b6dab0c86356fa36c2bcbb8322a0
Cc: stable@vger.kernel.org
Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx.c

index 548bef5359e699db3099f059169a90f3c0505e4c..5d8e317c2b04f44af66b0c1c8060912dee28a510 100644 (file)
@@ -7893,6 +7893,8 @@ static int enter_vmx_operation(struct kvm_vcpu *vcpu)
                     HRTIMER_MODE_REL_PINNED);
        vmx->nested.preemption_timer.function = vmx_preemption_timer_fn;
 
+       vmx->nested.vpid02 = allocate_vpid();
+
        vmx->nested.vmxon = true;
        return 0;
 
@@ -10369,11 +10371,9 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
                        goto free_vmcs;
        }
 
-       if (nested) {
+       if (nested)
                nested_vmx_setup_ctls_msrs(&vmx->nested.msrs,
                                           kvm_vcpu_apicv_active(&vmx->vcpu));
-               vmx->nested.vpid02 = allocate_vpid();
-       }
 
        vmx->nested.posted_intr_nv = -1;
        vmx->nested.current_vmptr = -1ull;
@@ -10390,7 +10390,6 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
        return &vmx->vcpu;
 
 free_vmcs:
-       free_vpid(vmx->nested.vpid02);
        free_loaded_vmcs(vmx->loaded_vmcs);
 free_msrs:
        kfree(vmx->guest_msrs);