• Sean Christopherson's avatar
    KVM: x86/pmu: Prioritize VMX interception over #GP on RDPMC due to bad index · 7bb7fce1
    Sean Christopherson authored
    Apply the pre-intercepts RDPMC validity check only to AMD, and rename all
    relevant functions to make it as clear as possible that the check is not a
    standard PMC index check.  On Intel, the basic rule is that only invalid
    opcodes and privilege/permission/mode checks have priority over VM-Exit,
    i.e. RDPMC with an invalid index should VM-Exit, not #GP.  While the SDM
    doesn't explicitly call out RDPMC, it _does_ explicitly use RDMSR of a
    non-existent MSR as an example where VM-Exit has priority over #GP, and
    RDPMC is effectively just a variation of RDMSR.
    
    Manually testing on various Intel CPUs confirms this behavior, and the
    inverted priority was introduced for SVM compatibility, i.e. was not an
    intentional change for Intel PMUs.  On AMD, *all* exceptions on RDPMC have
    priority over VM-Exit.
    
    Check for a NULL kvm_pmu_ops.check_rdpmc_early instead of using a RET0
    static call so as to provide a convenient location to document the
    difference between Intel and AMD, and to again try to make it as obvious
    as possible that the early check is a one-off thing, not a generic "is
    this PMC valid?" helper.
    
    Fixes: 8061252e ("KVM: SVM: Add intercept checks for remaining twobyte instructions")
    Cc: Jim Mattson <jmattson@google.com>
    Tested-by: default avatarDapeng Mi <dapeng1.mi@linux.intel.com>
    Link: https://lore.kernel.org/r/20240109230250.424295-8-seanjc@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
    7bb7fce1
kvm-x86-pmu-ops.h 884 Bytes