2022-03-29 19:50:54 -04:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#if !defined(KVM_X86_PMU_OP) || !defined(KVM_X86_PMU_OP_OPTIONAL)
|
|
|
|
BUILD_BUG_ON(1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* KVM_X86_PMU_OP() and KVM_X86_PMU_OP_OPTIONAL() are used to help generate
|
|
|
|
* both DECLARE/DEFINE_STATIC_CALL() invocations and
|
|
|
|
* "static_call_update()" calls.
|
|
|
|
*
|
|
|
|
* KVM_X86_PMU_OP_OPTIONAL() can be used for those functions that can have
|
|
|
|
* a NULL definition, for example if "static_call_cond()" will be used
|
|
|
|
* at the call sites.
|
|
|
|
*/
|
|
|
|
KVM_X86_PMU_OP(rdpmc_ecx_to_pmc)
|
|
|
|
KVM_X86_PMU_OP(msr_idx_to_pmc)
|
KVM: x86/pmu: Prioritize VMX interception over #GP on RDPMC due to bad index
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: 8061252ee0d2 ("KVM: SVM: Add intercept checks for remaining twobyte instructions")
Cc: Jim Mattson <jmattson@google.com>
Tested-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Link: https://lore.kernel.org/r/20240109230250.424295-8-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
2024-01-09 18:02:27 -05:00
|
|
|
KVM_X86_PMU_OP_OPTIONAL(check_rdpmc_early)
|
2022-03-29 19:50:54 -04:00
|
|
|
KVM_X86_PMU_OP(is_valid_msr)
|
|
|
|
KVM_X86_PMU_OP(get_msr)
|
|
|
|
KVM_X86_PMU_OP(set_msr)
|
|
|
|
KVM_X86_PMU_OP(refresh)
|
|
|
|
KVM_X86_PMU_OP(init)
|
2023-11-03 19:05:36 -04:00
|
|
|
KVM_X86_PMU_OP_OPTIONAL(reset)
|
2022-03-29 19:50:54 -04:00
|
|
|
KVM_X86_PMU_OP_OPTIONAL(deliver_pmi)
|
|
|
|
KVM_X86_PMU_OP_OPTIONAL(cleanup)
|
|
|
|
|
|
|
|
#undef KVM_X86_PMU_OP
|
|
|
|
#undef KVM_X86_PMU_OP_OPTIONAL
|