• Sean Christopherson's avatar
    KVM: selftests: Provide error code as a KVM_ASM_SAFE() output · b9635930
    Sean Christopherson authored
    Provide the error code on a fault in KVM_ASM_SAFE(), e.g. to allow tests
    to assert that #PF generates the correct error code without needing to
    manually install a #PF handler.  Use r10 as the scratch register for the
    error code, as it's already clobbered by the asm blob (loaded with the
    RIP of the to-be-executed instruction).  Deliberately load the output
    "error_code" even in the non-faulting path so that error_code is always
    initialized with deterministic data (the aforementioned RIP), i.e to
    ensure a selftest won't end up with uninitialized consumption regardless
    of how KVM_ASM_SAFE() is used.
    
    Don't clear r10 in the non-faulting case and instead load error code with
    the RIP (see above).  The error code is valid if and only if an exception
    occurs, and '0' isn't necessarily a better "invalid" value, e.g. '0'
    could result in false passes for a buggy test.
    Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
    Signed-off-by: default avatarDavid Matlack <dmatlack@google.com>
    Link: https://lore.kernel.org/r/20221102184654.282799-9-dmatlack@google.com
    b9635930
hyperv_features.c 14.7 KB