All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022
@ 2025-03-04  8:23 Xiaoyao Li
  2025-03-04  8:23 ` [PATCH 1/2] KVM: x86: Remove the unreachable case for 0x80000022 leaf in __do_cpuid_func() Xiaoyao Li
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Xiaoyao Li @ 2025-03-04  8:23 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, 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 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
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] KVM: x86: Remove the unreachable case for 0x80000022 leaf in __do_cpuid_func()
  2025-03-04  8:23 [PATCH 0/2] KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022 Xiaoyao Li
@ 2025-03-04  8:23 ` Xiaoyao Li
  2025-03-04  8:23 ` [PATCH 2/2] KVM: x86: Explicitly set eax and ebx to 0 when X86_FEATURE_PERFMON_V2 cannot be exposed to guest Xiaoyao Li
  2025-03-06  0:57 ` [PATCH 0/2] KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022 Sean Christopherson
  2 siblings, 0 replies; 6+ messages in thread
From: Xiaoyao Li @ 2025-03-04  8:23 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, Xiaoyao Li

kvm_cpu_cap_has(X86_FEATURE_PERFMON_V2) must be true when it reaches
to setup value for EBX. Remove the unreachable code.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
 arch/x86/kvm/cpuid.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 0779437edd23..f9a9175e3fe8 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -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;
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] KVM: x86: Explicitly set eax and ebx to 0 when X86_FEATURE_PERFMON_V2 cannot be exposed to guest
  2025-03-04  8:23 [PATCH 0/2] KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022 Xiaoyao Li
  2025-03-04  8:23 ` [PATCH 1/2] KVM: x86: Remove the unreachable case for 0x80000022 leaf in __do_cpuid_func() Xiaoyao Li
@ 2025-03-04  8:23 ` Xiaoyao Li
  2025-03-04 14:29   ` Sean Christopherson
  2025-03-06  0:57 ` [PATCH 0/2] KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022 Sean Christopherson
  2 siblings, 1 reply; 6+ messages in thread
From: Xiaoyao Li @ 2025-03-04  8:23 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, Xiaoyao Li

It wrongly exposes the host ebx value of leaf 0x80000022 to userspace
when it's supposed to return 0.

Fixes: 94cdeebd8211 ("KVM: x86/cpuid: Add AMD CPUID ExtPerfMonAndDbg leaf 0x80000022")
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
 arch/x86/kvm/cpuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index f9a9175e3fe8..5e4d4934c0d3 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -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;
 		}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] KVM: x86: Explicitly set eax and ebx to 0 when X86_FEATURE_PERFMON_V2 cannot be exposed to guest
  2025-03-04  8:23 ` [PATCH 2/2] KVM: x86: Explicitly set eax and ebx to 0 when X86_FEATURE_PERFMON_V2 cannot be exposed to guest Xiaoyao Li
@ 2025-03-04 14:29   ` Sean Christopherson
  0 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2025-03-04 14:29 UTC (permalink / raw)
  To: Xiaoyao Li; +Cc: Paolo Bonzini, kvm

On Tue, Mar 04, 2025, Xiaoyao Li wrote:
> It wrongly exposes the host ebx value of leaf 0x80000022 to userspace
> when it's supposed to return 0.
> 
> Fixes: 94cdeebd8211 ("KVM: x86/cpuid: Add AMD CPUID ExtPerfMonAndDbg leaf 0x80000022")
> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> ---
>  arch/x86/kvm/cpuid.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index f9a9175e3fe8..5e4d4934c0d3 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -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:

https://lore.kernel.org/all/Y1sIHXX3HEJEXJm+@google.com

> +			entry->eax = entry->ebx = 0;
>  			break;
>  		}
>  
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022
  2025-03-04  8:23 [PATCH 0/2] KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022 Xiaoyao Li
  2025-03-04  8:23 ` [PATCH 1/2] KVM: x86: Remove the unreachable case for 0x80000022 leaf in __do_cpuid_func() Xiaoyao Li
  2025-03-04  8:23 ` [PATCH 2/2] KVM: x86: Explicitly set eax and ebx to 0 when X86_FEATURE_PERFMON_V2 cannot be exposed to guest Xiaoyao Li
@ 2025-03-06  0:57 ` Sean Christopherson
  2025-03-06  1:46   ` Xiaoyao Li
  2 siblings, 1 reply; 6+ messages in thread
From: Sean Christopherson @ 2025-03-06  0:57 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Xiaoyao Li; +Cc: kvm

On Tue, 04 Mar 2025 03:23:12 -0500, Xiaoyao Li wrote:
> 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
> 
> [...]

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

--
https://github.com/kvm-x86/linux/tree/next

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022
  2025-03-06  0:57 ` [PATCH 0/2] KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022 Sean Christopherson
@ 2025-03-06  1:46   ` Xiaoyao Li
  0 siblings, 0 replies; 6+ messages in thread
From: Xiaoyao Li @ 2025-03-06  1:46 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: kvm

On 3/6/2025 8:57 AM, Sean Christopherson wrote:
> On Tue, 04 Mar 2025 03:23:12 -0500, Xiaoyao Li wrote:
>> 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
>>
>> [...]
> 
> 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!

> 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
> 
> --
> https://github.com/kvm-x86/linux/tree/next


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-03-06  1:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-04  8:23 [PATCH 0/2] KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022 Xiaoyao Li
2025-03-04  8:23 ` [PATCH 1/2] KVM: x86: Remove the unreachable case for 0x80000022 leaf in __do_cpuid_func() Xiaoyao Li
2025-03-04  8:23 ` [PATCH 2/2] KVM: x86: Explicitly set eax and ebx to 0 when X86_FEATURE_PERFMON_V2 cannot be exposed to guest Xiaoyao Li
2025-03-04 14:29   ` Sean Christopherson
2025-03-06  0:57 ` [PATCH 0/2] KVM: x86: Cleanup and fix for reporting CPUID leaf 0x80000022 Sean Christopherson
2025-03-06  1:46   ` Xiaoyao Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.