• S
    KVM: x86: WARN on non-zero CRs at RESET to detect improper initalization · 62dd57dd
    Sean Christopherson 提交于
    WARN if CR0, CR3, or CR4 are non-zero at RESET, which given the current
    KVM implementation, really means WARN if they're not zeroed at vCPU
    creation.  VMX in particular has several ->set_*() flows that read other
    registers to handle side effects, and because those flows are common to
    RESET and INIT, KVM subtly relies on emulated/virtualized registers to be
    zeroed at vCPU creation in order to do the right thing at RESET.
    
    Use CRs as a sentinel because they are most likely to be written as side
    effects, and because KVM specifically needs CR0.PG and CR0.PE to be '0'
    to correctly reflect the state of the vCPU's MMU.  CRs are also loaded
    and stored from/to the VMCS, and so adds some level of coverage to verify
    that KVM doesn't conflate zero-allocating the VMCS with properly
    initializing the VMCS with VMWRITEs.
    
    Note, '0' is somewhat arbitrary, vCPU creation can technically stuff any
    value for a register so long as it's coherent with respect to the current
    vCPU state.  In practice, '0' works for all registers and is convenient.
    Suggested-by: NVitaly Kuznetsov <vkuznets@redhat.com>
    Signed-off-by: NSean Christopherson <seanjc@google.com>
    Reviewed-by: NVitaly Kuznetsov <vkuznets@redhat.com>
    Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
    Message-Id: <20210921000303.400537-11-seanjc@google.com>
    Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
    62dd57dd
x86.c 324.1 KB