Skip to content

Commit 145dfad

Browse files
sean-jcbonzini
authored andcommitted
KVM: VMX: Advertise PMU LBRs if and only if perf supports LBRs
Advertise LBR support to userspace via MSR_IA32_PERF_CAPABILITIES if and only if perf fully supports LBRs. Perf may disable LBRs (by zeroing the number of LBRs) even on platforms the allegedly support LBRs, e.g. if probing any LBR MSRs during setup fails. Fixes: be635e3 ("KVM: vmx/pmu: Expose LBR_FMT in the MSR_IA32_PERF_CAPABILITIES") Reported-by: Like Xu <like.xu.linux@gmail.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20221006000314.73240-3-seanjc@google.com> Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 7353633 commit 145dfad

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

arch/x86/kvm/vmx/capabilities.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ static inline bool vmx_pebs_supported(void)
400400
static inline u64 vmx_get_perf_capabilities(void)
401401
{
402402
u64 perf_cap = PMU_CAP_FW_WRITES;
403+
struct x86_pmu_lbr lbr;
403404
u64 host_perf_cap = 0;
404405

405406
if (!enable_pmu)
@@ -408,7 +409,8 @@ static inline u64 vmx_get_perf_capabilities(void)
408409
if (boot_cpu_has(X86_FEATURE_PDCM))
409410
rdmsrl(MSR_IA32_PERF_CAPABILITIES, host_perf_cap);
410411

411-
perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT;
412+
if (x86_perf_get_lbr(&lbr) >= 0 && lbr.nr)
413+
perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT;
412414

413415
if (vmx_pebs_supported()) {
414416
perf_cap |= host_perf_cap & PERF_CAP_PEBS_MASK;

0 commit comments

Comments
 (0)