• Sean Christopherson's avatar
    KVM: VMX: Explicitly initialize controls shadow at VMCS allocation · 3af80fec
    Sean Christopherson authored
    Or: Don't re-initialize vmcs02's controls on every nested VM-Entry.
    
    VMWRITEs to the major VMCS controls are deceptively expensive.  Intel
    CPUs with VMCS caching (Westmere and later) also optimize away
    consistency checks on VM-Entry, i.e. skip consistency checks if the
    relevant fields have not changed since the last successful VM-Entry (of
    the cached VMCS).  Because uops are a precious commodity, uCode's dirty
    VMCS field tracking isn't as precise as software would prefer.  Notably,
    writing any of the major VMCS fields effectively marks the entire VMCS
    dirty, i.e. causes the next VM-Entry to perform all consistency checks,
    which consumes several hundred cycles.
    
    Zero out the controls' shadow copies during VMCS allocation and use the
    optimized setter when "initializing" controls.  While this technically
    affects both non-nested and nested virtualization, nested virtualization
    is the primary beneficiary as avoid VMWRITEs when prepare vmcs02 allows
    hardware to optimizie away consistency checks.
    Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    3af80fec
nested.c 179 KB