KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022
cover KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022
Patch 1 is a cleanup and Patch 2 is a fix. Please see the individual patch for detail.
Xiaoyao Li (2):
KVM: x86: Remove the unreachable case for 0x80000022 leaf in
__do_cpuid_func()
KVM: x86: Explicitly set eax and ebx to 0 when X86_FEATURE_PERFMON_V2
cannot be exposed to guest
arch/x86/kvm/cpuid.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
base-commit: 7d2154117a02832ab3643fe2da4cdc9d2090dcb2
Signature · 1 line
2.34.1
PATCH 1/2 KVM: x86: Remove the unreachable case for 0x80000022 leaf in __do_cpuid_func()
kvm_cpu_cap_has(X86_FEATURE_PERFMON_V2) must be true when it reaches to setup value for EBX. Remove the unreachable code.
--- arch/x86/kvm/cpuid.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
arch/x86/kvm/cpuid.c +1 -7
@@ -1773,13 +1773,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)cpuid_entry_override (entry,CPUID_8000_0022_EAX ); -if (kvm_cpu_cap_has (X86_FEATURE_PERFMON_V2 )) - ebx.split.num_core_pmc = kvm_pmu_cap.num_counters_gp; -else if (kvm_cpu_cap_has (X86_FEATURE_PERFCTR_CORE )) - ebx.split.num_core_pmc =AMD64_NUM_COUNTERS_CORE ; -else - ebx.split.num_core_pmc =AMD64_NUM_COUNTERS ; - + ebx.split.num_core_pmc = kvm_pmu_cap.num_counters_gp; entry->ebx = ebx.full;break ; }
Signature · 1 line
2.34.1
PATCH 2/2 KVM: x86: Explicitly set eax and ebx to 0 when X86_FEATURE_PERFMON_V2 cannot be exposed to guest
In reply to Xiaoyao LiIt wrongly exposes the host ebx value of leaf 0x80000022 to userspace when it's supposed to return 0.
--- arch/x86/kvm/cpuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/cpuid.c +1 -1
@@ -1767,7 +1767,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) entry->ecx = entry->edx =0 ;if (!enable_pmu || !kvm_cpu_cap_has (X86_FEATURE_PERFMON_V2 )) { - entry->eax = entry->ebx; + entry->eax = entry->ebx =0 ;break ; }
Signature · 1 line
2.34.1
Sean Christopherson
maintainerRe: [PATCH 2/2] KVM: x86: Explicitly set eax and ebx to 0 when X86_FEATURE_PERFMON_V2 cannot be exposed to guest
Quoted 14 lines · Xiaoyao Li
It wrongly exposes the host ebx value of leaf
0x80000022to userspace when it's supposed to return 0.Fixes 94cdeebd8211 ("KVM: x86/cpuid: Add AMD CPUID ExtPerfMonAndDbg leaf 0x80000022")Signed-off-by Xiaoyao Li <[email protected]>--- arch/x86/kvm/cpuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/cpuid.c +0
-0
arch/x86/kvm/cpuid.c static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) · line 1770
Quoted 4 lines
arch/x86/kvm/cpuid.c +0
-1@@ -1767,7 +1767,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) entry->ecx = entry->edx =0 ;if (!enable_pmu || !kvm_cpu_cap_has (X86_FEATURE_PERFMON_V2 )) { - entry->eax = entry->ebx;
Ugh, that typo came from me:
Quoted 7 lines
arch/x86/kvm/cpuid.c +1
-0+ entry->eax = entry->ebx =0 ;break ; }Signature · 1 line
2.34.1
Sean Christopherson
maintainerQuoted 10 lines · Xiaoyao Li
Patch 1 is a cleanup and Patch 2 is a fix. Please see the individual patch for detail.
Xiaoyao Li (2):
KVM: x86: Remove the unreachable case for0x80000022leaf in__do_cpuid_func()KVM: x86: Explicitly set eax and ebx to 0 when
X86_FEATURE_PERFMON_V2
cannot be exposed to guest[...]
Applied patch 2 to kvm-x86 fixes and tagged it for stable, and applied patch 1 to misc. Not zeroing eax/ebx is relatively benign, as it only affects the !enable_pmu case, but it's most definitely a bug and the fix is about as safe as a fix can be.
I also added quite a bit of extra information to both changelogs.
Thanks!
[1/2] KVM: x86: Remove the unreachable case for 0x80000022 leaf in __do_cpuid_func()
https://github.com/kvm-x86/linux/commit/e6c8728a8e2d [2/2] KVM: x86: Explicitly zero EAX and EBX when PERFMON_V2 isn't supported by KVM https://github.com/kvm-x86/linux/commit/f9dc8fb3afc9
Quoted 10 lines · Sean Christopherson
Quoted 9 lines · Xiaoyao Li
Patch 1 is a cleanup and Patch 2 is a fix. Please see the individual patch for detail.
Xiaoyao Li (2):
KVM: x86: Remove the unreachable case for0x80000022leaf in__do_cpuid_func()KVM: x86: Explicitly set eax and ebx to 0 when
X86_FEATURE_PERFMON_V2
cannot be exposed to guest
Quoted 8 lines
Quoted 1 line
[...]
Applied patch 2 to kvm-x86 fixes and tagged it for stable, and applied patch 1 to misc. Not zeroing eax/ebx is relatively benign, as it only affects the !enable_pmu case, but it's most definitely a bug and the fix is about as safe as a fix can be.
I also added quite a bit of extra information to both changelogs.
Thanks! It's much better!
Quoted 9 lines
Thanks!
[1/2] KVM: x86: Remove the unreachable case for
0x80000022leaf in__do_cpuid_func()https://github.com/kvm-x86/linux/commit/e6c8728a8e2d [2/2] KVM: x86: Explicitly zero EAX and EBX when PERFMON_V2 isn't supported by KVM https://github.com/kvm-x86/linux/commit/f9dc8fb3afc9