Skip to content

Commit bb9dc85

Browse files
committed
KVM: VMX: Disable LBR virtualization if the CPU doesn't support LBR callstacks
Disable LBR virtualization if the CPU doesn't support callstacks, which were introduced in HSW (see commit e9d7f7c ("perf/x86/intel: Add basic Haswell LBR call stack support"), as KVM unconditionally configures the perf LBR event with PERF_SAMPLE_BRANCH_CALL_STACK, i.e. LBR virtualization always fails on pre-HSW CPUs. Simply disable LBR support on such CPUs, as it has never worked, i.e. there is no risk of breaking an existing setup, and figuring out a way to performantly context switch LBRs on old CPUs is not worth the effort. Fixes: be635e3 ("KVM: vmx/pmu: Expose LBR_FMT in the MSR_IA32_PERF_CAPABILITIES") Cc: Mingwei Zhang <[email protected]> Cc: Jim Mattson <[email protected]> Tested-by: Mingwei Zhang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 0d0b608 commit bb9dc85

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7877,7 +7877,15 @@ static __init u64 vmx_get_perf_capabilities(void)
78777877

78787878
if (!cpu_feature_enabled(X86_FEATURE_ARCH_LBR)) {
78797879
x86_perf_get_lbr(&vmx_lbr_caps);
7880-
if (vmx_lbr_caps.nr)
7880+
7881+
/*
7882+
* KVM requires LBR callstack support, as the overhead due to
7883+
* context switching LBRs without said support is too high.
7884+
* See intel_pmu_create_guest_lbr_event() for more info.
7885+
*/
7886+
if (!vmx_lbr_caps.has_callstack)
7887+
memset(&vmx_lbr_caps, 0, sizeof(vmx_lbr_caps));
7888+
else if (vmx_lbr_caps.nr)
78817889
perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT;
78827890
}
78837891

0 commit comments

Comments
 (0)