• Vitaly Kuznetsov's avatar
    x86/kvm/nVMX: fix VMCLEAR when Enlightened VMCS is in use · 11e34914
    Vitaly Kuznetsov authored
    When Enlightened VMCS is in use, it is valid to do VMCLEAR and,
    according to TLFS, this should "transition an enlightened VMCS from the
    active to the non-active state". It is, however, wrong to assume that
    it is only valid to do VMCLEAR for the eVMCS which is currently active
    on the vCPU performing VMCLEAR.
    
    Currently, the logic in handle_vmclear() is broken: in case, there is no
    active eVMCS on the vCPU doing VMCLEAR we treat the argument as a 'normal'
    VMCS and kvm_vcpu_write_guest() to the 'launch_state' field irreversibly
    corrupts the memory area.
    
    So, in case the VMCLEAR argument is not the current active eVMCS on the
    vCPU, how can we know if the area it is pointing to is a normal or an
    enlightened VMCS?
    Thanks to the bug in Hyper-V (see commit 72aeb60c ("KVM: nVMX: Verify
    eVMCS revision id match supported eVMCS version on eVMCS VMPTRLD")) we can
    not, the revision can't be used to distinguish between them. So let's
    assume it is always enlightened in case enlightened vmentry is enabled in
    the assist page. Also, check if vmx->nested.enlightened_vmcs_enabled to
    minimize the impact for 'unenlightened' workloads.
    
    Fixes: b8bbab92 ("KVM: nVMX: implement enlightened VMPTRLD and VMCLEAR")
    Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    11e34914
evmcs.h 5.56 KB