Skip to content

Commit e6c8728

Browse files
calmisisean-jc
authored andcommitted
KVM: x86: Remove the unreachable case for 0x80000022 leaf in __do_cpuid_func()
Remove dead/unreachable (and misguided) code in KVM's processing of 0x80000022. The case statement breaks early if PERFMON_V2 isnt supported, i.e. kvm_cpu_cap_has(X86_FEATURE_PERFMON_V2) must be true when KVM reaches the code code to setup EBX. Note, early versions of the patch that became commit 94cdeeb ("KVM: x86/cpuid: Add AMD CPUID ExtPerfMonAndDbg leaf 0x80000022") didn't break early on lack of PERFMON_V2 support, and instead enumerated the effective number of counters KVM could emulate. All of that code was flawed, e.g. the APM explicitly states EBX is valid only for v2. Performance Monitoring Version 2 supported. When set, CPUID_Fn8000_0022_EBX reports the number of available performance counters. When the flaw of not respecting v2 support was addressed, the misguided stuffing of the number of counters got left behind. Link: https://lore.kernel.org/all/20220919093453.71737-4-likexu@tencent.com Fixes: 94cdeeb ("KVM: x86/cpuid: Add AMD CPUID ExtPerfMonAndDbg leaf 0x80000022") Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> Link: https://lore.kernel.org/r/20250304082314.472202-2-xiaoyao.li@intel.com [sean: elaborate on the situation a bit more, add Fixes] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 2a289ae commit e6c8728

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,13 +1773,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
17731773

17741774
cpuid_entry_override(entry, CPUID_8000_0022_EAX);
17751775

1776-
if (kvm_cpu_cap_has(X86_FEATURE_PERFMON_V2))
1777-
ebx.split.num_core_pmc = kvm_pmu_cap.num_counters_gp;
1778-
else if (kvm_cpu_cap_has(X86_FEATURE_PERFCTR_CORE))
1779-
ebx.split.num_core_pmc = AMD64_NUM_COUNTERS_CORE;
1780-
else
1781-
ebx.split.num_core_pmc = AMD64_NUM_COUNTERS;
1782-
1776+
ebx.split.num_core_pmc = kvm_pmu_cap.num_counters_gp;
17831777
entry->ebx = ebx.full;
17841778
break;
17851779
}

0 commit comments

Comments
 (0)