All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm: x86: limit the maximum number of vPMU fixed counters to 3
@ 2020-06-24  1:59 Like Xu
  2020-07-08  7:51 ` Xu, Like
  2020-07-08 11:08 ` Paolo Bonzini
  0 siblings, 2 replies; 5+ messages in thread
From: Like Xu @ 2020-06-24  1:59 UTC (permalink / raw)
  To: Paolo Bonzini, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, linux-kernel, Like Xu

Some new Intel platforms (such as TGL) already have the
fourth fixed counter TOPDOWN.SLOTS, but it has not been
fully enabled on KVM and the host.

Therefore, we limit edx.split.num_counters_fixed to 3,
so that it does not break the kvm-unit-tests PMU test
case and bad-handled userspace.

Signed-off-by: Like Xu <like.xu@linux.intel.com>
---
 arch/x86/kvm/cpuid.c | 2 +-
 arch/x86/kvm/pmu.h   | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 8a294f9747aa..0a2c6d2b4650 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -604,7 +604,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
 		eax.split.bit_width = cap.bit_width_gp;
 		eax.split.mask_length = cap.events_mask_len;
 
-		edx.split.num_counters_fixed = cap.num_counters_fixed;
+		edx.split.num_counters_fixed = min(cap.num_counters_fixed, MAX_FIXED_COUNTERS);
 		edx.split.bit_width_fixed = cap.bit_width_fixed;
 		edx.split.reserved = 0;
 
diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h
index ab85eed8a6cc..067fef51760c 100644
--- a/arch/x86/kvm/pmu.h
+++ b/arch/x86/kvm/pmu.h
@@ -15,6 +15,8 @@
 #define VMWARE_BACKDOOR_PMC_REAL_TIME		0x10001
 #define VMWARE_BACKDOOR_PMC_APPARENT_TIME	0x10002
 
+#define MAX_FIXED_COUNTERS	3
+
 struct kvm_event_hw_type_mapping {
 	u8 eventsel;
 	u8 unit_mask;
-- 
2.21.3


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

* Re: [PATCH] kvm: x86: limit the maximum number of vPMU fixed counters to 3
  2020-06-24  1:59 [PATCH] kvm: x86: limit the maximum number of vPMU fixed counters to 3 Like Xu
@ 2020-07-08  7:51 ` Xu, Like
  2020-07-08 11:09   ` Paolo Bonzini
  2020-07-08 11:08 ` Paolo Bonzini
  1 sibling, 1 reply; 5+ messages in thread
From: Xu, Like @ 2020-07-08  7:51 UTC (permalink / raw)
  To: Like Xu, Paolo Bonzini, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, linux-kernel

Kindly ping.

I think we may need this patch, as we limit the maximum vPMU version to 2:
     eax.split.version_id = min(cap.version, 2);

Thanks,
Like Xu

On 2020/6/24 9:59, Like Xu wrote:
> Some new Intel platforms (such as TGL) already have the
> fourth fixed counter TOPDOWN.SLOTS, but it has not been
> fully enabled on KVM and the host.
>
> Therefore, we limit edx.split.num_counters_fixed to 3,
> so that it does not break the kvm-unit-tests PMU test
> case and bad-handled userspace.
>
> Signed-off-by: Like Xu <like.xu@linux.intel.com>
> ---
>   arch/x86/kvm/cpuid.c | 2 +-
>   arch/x86/kvm/pmu.h   | 2 ++
>   2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index 8a294f9747aa..0a2c6d2b4650 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -604,7 +604,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
>   		eax.split.bit_width = cap.bit_width_gp;
>   		eax.split.mask_length = cap.events_mask_len;
>   
> -		edx.split.num_counters_fixed = cap.num_counters_fixed;
> +		edx.split.num_counters_fixed = min(cap.num_counters_fixed, MAX_FIXED_COUNTERS);
>   		edx.split.bit_width_fixed = cap.bit_width_fixed;
>   		edx.split.reserved = 0;
>   
> diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h
> index ab85eed8a6cc..067fef51760c 100644
> --- a/arch/x86/kvm/pmu.h
> +++ b/arch/x86/kvm/pmu.h
> @@ -15,6 +15,8 @@
>   #define VMWARE_BACKDOOR_PMC_REAL_TIME		0x10001
>   #define VMWARE_BACKDOOR_PMC_APPARENT_TIME	0x10002
>   
> +#define MAX_FIXED_COUNTERS	3
> +
>   struct kvm_event_hw_type_mapping {
>   	u8 eventsel;
>   	u8 unit_mask;


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

* Re: [PATCH] kvm: x86: limit the maximum number of vPMU fixed counters to 3
  2020-06-24  1:59 [PATCH] kvm: x86: limit the maximum number of vPMU fixed counters to 3 Like Xu
  2020-07-08  7:51 ` Xu, Like
@ 2020-07-08 11:08 ` Paolo Bonzini
  1 sibling, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2020-07-08 11:08 UTC (permalink / raw)
  To: Like Xu, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, linux-kernel

On 24/06/20 03:59, Like Xu wrote:
> Some new Intel platforms (such as TGL) already have the
> fourth fixed counter TOPDOWN.SLOTS, but it has not been
> fully enabled on KVM and the host.
> 
> Therefore, we limit edx.split.num_counters_fixed to 3,
> so that it does not break the kvm-unit-tests PMU test
> case and bad-handled userspace.
> 
> Signed-off-by: Like Xu <like.xu@linux.intel.com>
> ---
>  arch/x86/kvm/cpuid.c | 2 +-
>  arch/x86/kvm/pmu.h   | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index 8a294f9747aa..0a2c6d2b4650 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -604,7 +604,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
>  		eax.split.bit_width = cap.bit_width_gp;
>  		eax.split.mask_length = cap.events_mask_len;
>  
> -		edx.split.num_counters_fixed = cap.num_counters_fixed;
> +		edx.split.num_counters_fixed = min(cap.num_counters_fixed, MAX_FIXED_COUNTERS);
>  		edx.split.bit_width_fixed = cap.bit_width_fixed;
>  		edx.split.reserved = 0;
>  
> diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h
> index ab85eed8a6cc..067fef51760c 100644
> --- a/arch/x86/kvm/pmu.h
> +++ b/arch/x86/kvm/pmu.h
> @@ -15,6 +15,8 @@
>  #define VMWARE_BACKDOOR_PMC_REAL_TIME		0x10001
>  #define VMWARE_BACKDOOR_PMC_APPARENT_TIME	0x10002
>  
> +#define MAX_FIXED_COUNTERS	3
> +
>  struct kvm_event_hw_type_mapping {
>  	u8 eventsel;
>  	u8 unit_mask;
> 

Queued, thanks.

Paolo


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

* Re: [PATCH] kvm: x86: limit the maximum number of vPMU fixed counters to 3
  2020-07-08  7:51 ` Xu, Like
@ 2020-07-08 11:09   ` Paolo Bonzini
  2020-07-08 14:22     ` Xu, Like
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2020-07-08 11:09 UTC (permalink / raw)
  To: like.xu, Like Xu, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, linux-kernel

On 08/07/20 09:51, Xu, Like wrote:
> Kindly ping.
> 
> I think we may need this patch, as we limit the maximum vPMU version to 2:
>     eax.split.version_id = min(cap.version, 2);

I don't think this is a problem.  Are you planning to add support for
the fourth counter?

Paolo


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

* Re: [PATCH] kvm: x86: limit the maximum number of vPMU fixed counters to 3
  2020-07-08 11:09   ` Paolo Bonzini
@ 2020-07-08 14:22     ` Xu, Like
  0 siblings, 0 replies; 5+ messages in thread
From: Xu, Like @ 2020-07-08 14:22 UTC (permalink / raw)
  To: Paolo Bonzini, Like Xu, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, linux-kernel

On 2020/7/8 19:09, Paolo Bonzini wrote:
> On 08/07/20 09:51, Xu, Like wrote:
>> Kindly ping.
>>
>> I think we may need this patch, as we limit the maximum vPMU version to 2:
>>      eax.split.version_id = min(cap.version, 2);
> I don't think this is a problem.  Are you planning to add support for
> the fourth counter?
Yes, we plan to provide this support on the KVM after fully enabling the fourth
counter (and an accompanying special counter) on the host perf side.

This may require one or two kernel cycles, so I have to prevent it from
being exposed to non-linux guest with this fix. Thanks for your support.

Thanks,
Like Xu
>
> Paolo
>


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

end of thread, other threads:[~2020-07-08 14:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-24  1:59 [PATCH] kvm: x86: limit the maximum number of vPMU fixed counters to 3 Like Xu
2020-07-08  7:51 ` Xu, Like
2020-07-08 11:09   ` Paolo Bonzini
2020-07-08 14:22     ` Xu, Like
2020-07-08 11:08 ` Paolo Bonzini

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.