• Sean Christopherson's avatar
    KVM: x86: Don't clear EFER during SMM transitions for 32-bit vCPU · 8f4dc2e7
    Sean Christopherson authored
    Neither AMD nor Intel CPUs have an EFER field in the legacy SMRAM save
    state area, i.e. don't save/restore EFER across SMM transitions.  KVM
    somewhat models this, e.g. doesn't clear EFER on entry to SMM if the
    guest doesn't support long mode.  But during RSM, KVM unconditionally
    clears EFER so that it can get back to pure 32-bit mode in order to
    start loading CRs with their actual non-SMM values.
    
    Clear EFER only when it will be written when loading the non-SMM state
    so as to preserve bits that can theoretically be set on 32-bit vCPUs,
    e.g. KVM always emulates EFER_SCE.
    
    And because CR4.PAE is cleared only to play nice with EFER, wrap that
    code in the long mode check as well.  Note, this may result in a
    compiler warning about cr4 being consumed uninitialized.  Re-read CR4
    even though it's technically unnecessary, as doing so allows for more
    readable code and RSM emulation is not a performance critical path.
    
    Fixes: 660a5d51 ("KVM: x86: save/load state on SMM switch")
    Cc: stable@vger.kernel.org
    Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    8f4dc2e7
emulate.c 150 KB