• Sean Christopherson's avatar
    KVM: x86: Treat #DBs from the emulator as fault-like (code and DR7.GD=1) · 5623f751
    Sean Christopherson authored
    Add a dedicated "exception type" for #DBs, as #DBs can be fault-like or
    trap-like depending the sub-type of #DB, and effectively defer the
    decision of what to do with the #DB to the caller.
    
    For the emulator's two calls to exception_type(), treat the #DB as
    fault-like, as the emulator handles only code breakpoint and general
    detect #DBs, both of which are fault-like.
    
    For event injection, which uses exception_type() to determine whether to
    set EFLAGS.RF=1 on the stack, keep the current behavior of not setting
    RF=1 for #DBs.  Intel and AMD explicitly state RF isn't set on code #DBs,
    so exempting by failing the "== EXCPT_FAULT" check is correct.  The only
    other fault-like #DB is General Detect, and despite Intel and AMD both
    strongly implying (through omission) that General Detect #DBs should set
    RF=1, hardware (multiple generations of both Intel and AMD), in fact does
    not.  Through insider knowledge, extreme foresight, sheer dumb luck, or
    some combination thereof, KVM correctly handled RF for General Detect #DBs.
    
    Fixes: 38827dbd ("KVM: x86: Do not update EFLAGS on faulting emulation")
    Cc: stable@vger.kernel.org
    Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
    Reviewed-by: default avatarMaxim Levitsky <mlevitsk@redhat.com>
    Link: https://lore.kernel.org/r/20220830231614.3580124-9-seanjc@google.comSigned-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    5623f751
x86.c 356 KB