• Sean Christopherson's avatar
    KVM: nVMX: Pull KVM L0's desired controls directly from vmcs01 · 389ab252
    Sean Christopherson authored
    When preparing controls for vmcs02, grab KVM's desired controls from
    vmcs01's shadow state instead of recalculating the controls from scratch,
    or in the secondary execution controls, instead of using the dedicated
    cache.  Calculating secondary exec controls is eye-poppingly expensive
    due to the guest CPUID checks, hence the dedicated cache, but the other
    calculations aren't exactly free either.
    
    Explicitly clear several bits (x2APIC, DESC exiting, and load EFER on
    exit) as appropriate as they may be set in vmcs01, whereas the previous
    implementation relied on dynamic bits being cleared in the calculator.
    
    Intentionally propagate VM_{ENTRY,EXIT}_LOAD_IA32_PERF_GLOBAL_CTRL from
    vmcs01 to vmcs02.  Whether or not PERF_GLOBAL_CTRL is loaded depends on
    whether or not perf itself is active, so unless perf stops between the
    exit from L1 and entry to L2, vmcs01 will hold the desired value.  This
    is purely an optimization as atomic_switch_perf_msrs() will set/clear
    the control as needed at VM-Enter, i.e. it avoids two extra VMWRITEs in
    the case where perf is active (versus starting with the bits clear in
    vmcs02, which was the previous behavior).
    
    Cc: Zeng Guang <guang.zeng@intel.com>
    Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
    Message-Id: <20210810171952.2758100-3-seanjc@google.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    389ab252
nested.c 205 KB