All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] KVM: x86/pmu: Move the vmx_icl_pebs_cpu[] definition out of the header file
@ 2022-05-18 17:01 Like Xu
  2022-05-18 17:01 ` [PATCH 2/3] KVM: selftests: x86: Sync the new name of the test case to the .gitignore Like Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Like Xu @ 2022-05-18 17:01 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel

From: Like Xu <likexu@tencent.com>

Defining a static const array in a header file would introduce redundant
definitions to the point of confusing semantics, and such a use case would
only bring complaints from the compiler:

arch/x86/kvm/pmu.h:20:32: warning: ‘vmx_icl_pebs_cpu’ defined but not used [-Wunused-const-variable=]
   20 | static const struct x86_cpu_id vmx_icl_pebs_cpu[] = {
      |                                ^~~~~~~~~~~~~~~~

Fixes: a095df2c5f48 ("KVM: x86/pmu: Adjust precise_ip to emulate Ice Lake guest PDIR counter")
Signed-off-by: Like Xu <likexu@tencent.com>
---
 arch/x86/kvm/pmu.c | 7 +++++++
 arch/x86/kvm/pmu.h | 8 --------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index b5d0c36b869b..a2eaae85d97b 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -16,6 +16,7 @@
 #include <linux/bsearch.h>
 #include <linux/sort.h>
 #include <asm/perf_event.h>
+#include <asm/cpu_device_id.h>
 #include "x86.h"
 #include "cpuid.h"
 #include "lapic.h"
@@ -27,6 +28,12 @@
 struct x86_pmu_capability __read_mostly kvm_pmu_cap;
 EXPORT_SYMBOL_GPL(kvm_pmu_cap);
 
+static const struct x86_cpu_id vmx_icl_pebs_cpu[] = {
+	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, NULL),
+	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, NULL),
+	{}
+};
+
 /* NOTE:
  * - Each perf counter is defined as "struct kvm_pmc";
  * - There are two types of perf counters: general purpose (gp) and fixed.
diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h
index dbf4c83519a4..ecf2962510e4 100644
--- a/arch/x86/kvm/pmu.h
+++ b/arch/x86/kvm/pmu.h
@@ -4,8 +4,6 @@
 
 #include <linux/nospec.h>
 
-#include <asm/cpu_device_id.h>
-
 #define vcpu_to_pmu(vcpu) (&(vcpu)->arch.pmu)
 #define pmu_to_vcpu(pmu)  (container_of((pmu), struct kvm_vcpu, arch.pmu))
 #define pmc_to_pmu(pmc)   (&(pmc)->vcpu->arch.pmu)
@@ -17,12 +15,6 @@
 #define VMWARE_BACKDOOR_PMC_REAL_TIME		0x10001
 #define VMWARE_BACKDOOR_PMC_APPARENT_TIME	0x10002
 
-static const struct x86_cpu_id vmx_icl_pebs_cpu[] = {
-	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, NULL),
-	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, NULL),
-	{}
-};
-
 struct kvm_event_hw_type_mapping {
 	u8 eventsel;
 	u8 unit_mask;
-- 
2.36.1


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

* [PATCH 2/3] KVM: selftests: x86: Sync the new name of the test case to the .gitignore
  2022-05-18 17:01 [PATCH 1/3] KVM: x86/pmu: Move the vmx_icl_pebs_cpu[] definition out of the header file Like Xu
@ 2022-05-18 17:01 ` Like Xu
  2022-05-18 17:01 ` [PATCH 3/3] KVM: x86/pmu: Update global enable_pmu when PMU is undetected Like Xu
  2022-05-20 12:00 ` [PATCH 1/3] KVM: x86/pmu: Move the vmx_icl_pebs_cpu[] definition out of the header file Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Like Xu @ 2022-05-18 17:01 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel

From: Like Xu <likexu@tencent.com>

Fixing side effect of the so-called opportunistic change in the commit.

Fixes: dc8a9febbab0 ("KVM: selftests: x86: Fix test failure on arch lbr capable platforms")
Signed-off-by: Like Xu <likexu@tencent.com>
---
 tools/testing/selftests/kvm/.gitignore | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore
index 4f48f9c2411d..f18ae306c916 100644
--- a/tools/testing/selftests/kvm/.gitignore
+++ b/tools/testing/selftests/kvm/.gitignore
@@ -55,7 +55,7 @@
 /x86_64/xen_shinfo_test
 /x86_64/xen_vmcall_test
 /x86_64/xss_msr_test
-/x86_64/vmx_pmu_msrs_test
+/x86_64/vmx_pmu_caps_test
 /access_tracking_perf_test
 /demand_paging_test
 /dirty_log_test
-- 
2.36.1


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

* [PATCH 3/3] KVM: x86/pmu: Update global enable_pmu when PMU is undetected
  2022-05-18 17:01 [PATCH 1/3] KVM: x86/pmu: Move the vmx_icl_pebs_cpu[] definition out of the header file Like Xu
  2022-05-18 17:01 ` [PATCH 2/3] KVM: selftests: x86: Sync the new name of the test case to the .gitignore Like Xu
@ 2022-05-18 17:01 ` Like Xu
  2022-05-20 12:00 ` [PATCH 1/3] KVM: x86/pmu: Move the vmx_icl_pebs_cpu[] definition out of the header file Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Like Xu @ 2022-05-18 17:01 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel

From: Like Xu <likexu@tencent.com>

On some virt platforms (L1 guest w/o PMU), the value of module parameter
'enable_pmu' for nested L2 guests should be updated at initialisation.

Considering that there is no concept of "architecture pmu" in AMD or Hygon
and that the versions (prior to Zen 4) are all 0, but that the theoretical
available counters are at least AMD64_NUM_COUNTERS, the utility
check_hw_exists() is reused in the initialisation call path.

Opportunistically update Intel specific comments.

Fixes: 8eeac7e999e8 ("KVM: x86/pmu: Add kvm_pmu_cap to optimize perf_get_x86_pmu_capability")
Signed-off-by: Like Xu <likexu@tencent.com>
---
 arch/x86/events/core.c |  6 ++++++
 arch/x86/kvm/pmu.h     | 15 ++++++++++-----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 7f1d10dbabc0..865eeb500a71 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2982,6 +2982,12 @@ unsigned long perf_misc_flags(struct pt_regs *regs)
 
 void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap)
 {
+	if (!check_hw_exists(&pmu, x86_pmu.num_counters,
+			     x86_pmu.num_counters_fixed)) {
+		memset(cap, 0, sizeof(*cap));
+		return;
+	}
+
 	cap->version		= x86_pmu.version;
 	/*
 	 * KVM doesn't support the hybrid PMU yet.
diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h
index ecf2962510e4..b200d080a8a3 100644
--- a/arch/x86/kvm/pmu.h
+++ b/arch/x86/kvm/pmu.h
@@ -150,14 +150,19 @@ extern struct x86_pmu_capability kvm_pmu_cap;
 
 static inline void kvm_init_pmu_capability(void)
 {
+	bool is_intel = boot_cpu_data.x86_vendor == X86_VENDOR_INTEL;
+
 	perf_get_x86_pmu_capability(&kvm_pmu_cap);
 
-	/*
-	 * Only support guest architectural pmu on
-	 * a host with architectural pmu.
-	 */
-	if (!kvm_pmu_cap.version)
+	 /*
+	  * For Intel, only support guest architectural pmu
+	  * on a host with architectural pmu.
+	  */
+	if ((is_intel && !kvm_pmu_cap.version) || !kvm_pmu_cap.num_counters_gp) {
 		memset(&kvm_pmu_cap, 0, sizeof(kvm_pmu_cap));
+		enable_pmu = false;
+		return;
+	}
 
 	kvm_pmu_cap.version = min(kvm_pmu_cap.version, 2);
 	kvm_pmu_cap.num_counters_fixed = min(kvm_pmu_cap.num_counters_fixed,
-- 
2.36.1


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

* Re: [PATCH 1/3] KVM: x86/pmu: Move the vmx_icl_pebs_cpu[] definition out of the header file
  2022-05-18 17:01 [PATCH 1/3] KVM: x86/pmu: Move the vmx_icl_pebs_cpu[] definition out of the header file Like Xu
  2022-05-18 17:01 ` [PATCH 2/3] KVM: selftests: x86: Sync the new name of the test case to the .gitignore Like Xu
  2022-05-18 17:01 ` [PATCH 3/3] KVM: x86/pmu: Update global enable_pmu when PMU is undetected Like Xu
@ 2022-05-20 12:00 ` Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2022-05-20 12:00 UTC (permalink / raw)
  To: Like Xu
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, Kernel Mailing List, Linux

Queued all three, thanks.

Paolo

On Wed, May 18, 2022 at 7:01 PM Like Xu <like.xu.linux@gmail.com> wrote:
>
> From: Like Xu <likexu@tencent.com>
>
> Defining a static const array in a header file would introduce redundant
> definitions to the point of confusing semantics, and such a use case would
> only bring complaints from the compiler:
>
> arch/x86/kvm/pmu.h:20:32: warning: ‘vmx_icl_pebs_cpu’ defined but not used [-Wunused-const-variable=]
>    20 | static const struct x86_cpu_id vmx_icl_pebs_cpu[] = {
>       |                                ^~~~~~~~~~~~~~~~
>
> Fixes: a095df2c5f48 ("KVM: x86/pmu: Adjust precise_ip to emulate Ice Lake guest PDIR counter")
> Signed-off-by: Like Xu <likexu@tencent.com>
> ---
>  arch/x86/kvm/pmu.c | 7 +++++++
>  arch/x86/kvm/pmu.h | 8 --------
>  2 files changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index b5d0c36b869b..a2eaae85d97b 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -16,6 +16,7 @@
>  #include <linux/bsearch.h>
>  #include <linux/sort.h>
>  #include <asm/perf_event.h>
> +#include <asm/cpu_device_id.h>
>  #include "x86.h"
>  #include "cpuid.h"
>  #include "lapic.h"
> @@ -27,6 +28,12 @@
>  struct x86_pmu_capability __read_mostly kvm_pmu_cap;
>  EXPORT_SYMBOL_GPL(kvm_pmu_cap);
>
> +static const struct x86_cpu_id vmx_icl_pebs_cpu[] = {
> +       X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, NULL),
> +       X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, NULL),
> +       {}
> +};
> +
>  /* NOTE:
>   * - Each perf counter is defined as "struct kvm_pmc";
>   * - There are two types of perf counters: general purpose (gp) and fixed.
> diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h
> index dbf4c83519a4..ecf2962510e4 100644
> --- a/arch/x86/kvm/pmu.h
> +++ b/arch/x86/kvm/pmu.h
> @@ -4,8 +4,6 @@
>
>  #include <linux/nospec.h>
>
> -#include <asm/cpu_device_id.h>
> -
>  #define vcpu_to_pmu(vcpu) (&(vcpu)->arch.pmu)
>  #define pmu_to_vcpu(pmu)  (container_of((pmu), struct kvm_vcpu, arch.pmu))
>  #define pmc_to_pmu(pmc)   (&(pmc)->vcpu->arch.pmu)
> @@ -17,12 +15,6 @@
>  #define VMWARE_BACKDOOR_PMC_REAL_TIME          0x10001
>  #define VMWARE_BACKDOOR_PMC_APPARENT_TIME      0x10002
>
> -static const struct x86_cpu_id vmx_icl_pebs_cpu[] = {
> -       X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, NULL),
> -       X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, NULL),
> -       {}
> -};
> -
>  struct kvm_event_hw_type_mapping {
>         u8 eventsel;
>         u8 unit_mask;
> --
> 2.36.1
>


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

end of thread, other threads:[~2022-05-20 12:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-18 17:01 [PATCH 1/3] KVM: x86/pmu: Move the vmx_icl_pebs_cpu[] definition out of the header file Like Xu
2022-05-18 17:01 ` [PATCH 2/3] KVM: selftests: x86: Sync the new name of the test case to the .gitignore Like Xu
2022-05-18 17:01 ` [PATCH 3/3] KVM: x86/pmu: Update global enable_pmu when PMU is undetected Like Xu
2022-05-20 12:00 ` [PATCH 1/3] KVM: x86/pmu: Move the vmx_icl_pebs_cpu[] definition out of the header file 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.