Skip to content

Commit d338d87

Browse files
Like Xusean-jc
authored andcommitted
KVM: x86/pmu: Advertise PERFCTR_CORE iff the min nr of counters is met
Enable and advertise PERFCTR_CORE if and only if the minimum number of required counters are available, i.e. if perf says there are less than six general purpose counters. Opportunistically, use kvm_cpu_cap_check_and_set() instead of open coding the check for host support. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Like Xu <likexu@tencent.com> [sean: massage shortlog and changelog] Link: https://lore.kernel.org/r/20230603011058.1038821-9-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 6a08083 commit d338d87

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5025,9 +5025,18 @@ static __init void svm_set_cpu_caps(void)
50255025
boot_cpu_has(X86_FEATURE_AMD_SSBD))
50265026
kvm_cpu_cap_set(X86_FEATURE_VIRT_SSBD);
50275027

5028-
/* AMD PMU PERFCTR_CORE CPUID */
5029-
if (enable_pmu && boot_cpu_has(X86_FEATURE_PERFCTR_CORE))
5030-
kvm_cpu_cap_set(X86_FEATURE_PERFCTR_CORE);
5028+
if (enable_pmu) {
5029+
/*
5030+
* Enumerate support for PERFCTR_CORE if and only if KVM has
5031+
* access to enough counters to virtualize "core" support,
5032+
* otherwise limit vPMU support to the legacy number of counters.
5033+
*/
5034+
if (kvm_pmu_cap.num_counters_gp < AMD64_NUM_COUNTERS_CORE)
5035+
kvm_pmu_cap.num_counters_gp = min(AMD64_NUM_COUNTERS,
5036+
kvm_pmu_cap.num_counters_gp);
5037+
else
5038+
kvm_cpu_cap_check_and_set(X86_FEATURE_PERFCTR_CORE);
5039+
}
50315040

50325041
/* CPUID 0x8000001F (SME/SEV features) */
50335042
sev_set_cpu_caps();

0 commit comments

Comments
 (0)