• Sean Christopherson's avatar
    KVM: VMX: Condition ENCLS-exiting enabling on CPU support for SGX1 · 7a57c09b
    Sean Christopherson authored
    Enable ENCLS-exiting (and thus set vmcs.ENCLS_EXITING_BITMAP) only if
    the CPU supports SGX1.  Per Intel's SDM, all ENCLS leafs #UD if SGX1
    is not supported[*], i.e. intercepting ENCLS to inject a #UD is
    unnecessary.
    
    Avoiding ENCLS-exiting even when it is reported as supported by the CPU
    works around a reported issue where SGX is "hard" disabled after an S3
    suspend/resume cycle, i.e. CPUID.0x7.SGX=0 and the VMCS field/control
    are enumerated as unsupported.  While the root cause of the S3 issue is
    unknown, it's definitely _not_ a KVM (or kernel) bug, i.e. this is a
    workaround for what is most likely a hardware or firmware issue.  As a
    bonus side effect, KVM saves a VMWRITE when first preparing vmcs01 and
    vmcs02.
    
    Note, SGX must be disabled in BIOS to take advantage of this workaround
    
    [*] The additional ENCLS CPUID check on SGX1 exists so that SGX can be
        globally "soft" disabled post-reset, e.g. if #MC bits in MCi_CTL are
        cleared.  Soft disabled meaning disabling SGX without clearing the
        primary CPUID bit (in leaf 0x7) and without poking into non-SGX
        CPU paths, e.g. for the VMCS controls.
    
    Fixes: 0b665d30 ("KVM: vmx: Inject #UD for SGX ENCLS instruction in guest")
    Reported-by: default avatarToni Spets <toni.spets@iki.fi>
    Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    7a57c09b
vmx.c 222 KB