diff mbox series

[4/8] perf: pmuv3: Add wrappers for KVM accesses

Message ID 20230126204444.2204061-5-zalbassam@google.com (mailing list archive)
State New, archived
Headers show
Series perf: arm: Make PMUv3 driver available for aarch32 | expand

Commit Message

Zaid Al-Bassam Jan. 26, 2023, 8:44 p.m. UTC
KVM host support is available only on arm64. This patch adds wrappers
to the KVM host function references in the arm_pmuv3.c, so that it is
up to architecture to populate these wrappers if supported.

Signed-off-by: Zaid Al-Bassam <zalbassam@google.com>
---
 arch/arm64/include/asm/arm_pmuv3.h | 16 ++++++++++++++++
 drivers/perf/arm_pmuv3.c           | 11 +++++------
 2 files changed, 21 insertions(+), 6 deletions(-)

Comments

Marc Zyngier Feb. 8, 2023, 11:24 a.m. UTC | #1
On Thu, 26 Jan 2023 20:44:40 +0000,
Zaid Al-Bassam <zalbassam@google.com> wrote:
> 
> KVM host support is available only on arm64. This patch adds wrappers
> to the KVM host function references in the arm_pmuv3.c, so that it is
> up to architecture to populate these wrappers if supported.
> 
> Signed-off-by: Zaid Al-Bassam <zalbassam@google.com>
> ---
>  arch/arm64/include/asm/arm_pmuv3.h | 16 ++++++++++++++++
>  drivers/perf/arm_pmuv3.c           | 11 +++++------
>  2 files changed, 21 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/arm_pmuv3.h b/arch/arm64/include/asm/arm_pmuv3.h
> index f41a354d1022..9f2a48f5340c 100644
> --- a/arch/arm64/include/asm/arm_pmuv3.h
> +++ b/arch/arm64/include/asm/arm_pmuv3.h
> @@ -20,6 +20,7 @@
>  
>  #include <asm/cpufeature.h>
>  #include <asm/sysreg.h>
> +#include <linux/kvm_host.h>

"linux" includes must be placed before the "asm" ones.

>  
>  /*
>   * This code is really good
> @@ -191,4 +192,19 @@ static inline u32 read_pmceid1(void)
>  	return read_sysreg(pmceid1_el0);
>  }
>  
> +static inline void armv8pmu_kvm_set_events(u32 set, struct perf_event_attr *attr)
> +{
> +	kvm_set_pmu_events(set, attr);
> +}
> +
> +static inline void armv8pmu_kvm_clr_events(u32 clr)
> +{
> +	kvm_clr_pmu_events(clr);
> +}
> +
> +static inline bool armv8pmu_kvm_counter_deferred(struct perf_event_attr *attr)
> +{
> +	return kvm_pmu_counter_deferred(attr);
> +}
> +
>  #endif
> diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c
> index 505f0758260c..d7063dd52827 100644
> --- a/drivers/perf/arm_pmuv3.c
> +++ b/drivers/perf/arm_pmuv3.c
> @@ -16,7 +16,6 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/clocksource.h>
> -#include <linux/kvm_host.h>
>  #include <linux/of.h>
>  #include <linux/perf/arm_pmu.h>
>  #include <linux/perf/arm_pmuv3.h>
> @@ -607,10 +606,10 @@ static inline void armv8pmu_enable_event_counter(struct perf_event *event)
>  	struct perf_event_attr *attr = &event->attr;
>  	u32 mask = armv8pmu_event_cnten_mask(event);
>  
> -	kvm_set_pmu_events(mask, attr);
> +	armv8pmu_kvm_set_events(mask, attr);

Why the change of name? given that you will implement empty helpers in
the AArch32 code, you might as well keep the names and reduce the churn.

At the end of the day, the only thing you need to do in this patch is
to move the "#include <linux/kvm_host.h>" from this file into the
arch-specific file. Nothing else.

Thanks,

	M.
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/arm_pmuv3.h b/arch/arm64/include/asm/arm_pmuv3.h
index f41a354d1022..9f2a48f5340c 100644
--- a/arch/arm64/include/asm/arm_pmuv3.h
+++ b/arch/arm64/include/asm/arm_pmuv3.h
@@ -20,6 +20,7 @@ 
 
 #include <asm/cpufeature.h>
 #include <asm/sysreg.h>
+#include <linux/kvm_host.h>
 
 /*
  * This code is really good
@@ -191,4 +192,19 @@  static inline u32 read_pmceid1(void)
 	return read_sysreg(pmceid1_el0);
 }
 
+static inline void armv8pmu_kvm_set_events(u32 set, struct perf_event_attr *attr)
+{
+	kvm_set_pmu_events(set, attr);
+}
+
+static inline void armv8pmu_kvm_clr_events(u32 clr)
+{
+	kvm_clr_pmu_events(clr);
+}
+
+static inline bool armv8pmu_kvm_counter_deferred(struct perf_event_attr *attr)
+{
+	return kvm_pmu_counter_deferred(attr);
+}
+
 #endif
diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c
index 505f0758260c..d7063dd52827 100644
--- a/drivers/perf/arm_pmuv3.c
+++ b/drivers/perf/arm_pmuv3.c
@@ -16,7 +16,6 @@ 
 
 #include <linux/acpi.h>
 #include <linux/clocksource.h>
-#include <linux/kvm_host.h>
 #include <linux/of.h>
 #include <linux/perf/arm_pmu.h>
 #include <linux/perf/arm_pmuv3.h>
@@ -607,10 +606,10 @@  static inline void armv8pmu_enable_event_counter(struct perf_event *event)
 	struct perf_event_attr *attr = &event->attr;
 	u32 mask = armv8pmu_event_cnten_mask(event);
 
-	kvm_set_pmu_events(mask, attr);
+	armv8pmu_kvm_set_events(mask, attr);
 
 	/* We rely on the hypervisor switch code to enable guest counters */
-	if (!kvm_pmu_counter_deferred(attr))
+	if (!armv8pmu_kvm_counter_deferred(attr))
 		armv8pmu_enable_counter(mask);
 }
 
@@ -629,10 +628,10 @@  static inline void armv8pmu_disable_event_counter(struct perf_event *event)
 	struct perf_event_attr *attr = &event->attr;
 	u32 mask = armv8pmu_event_cnten_mask(event);
 
-	kvm_clr_pmu_events(mask);
+	armv8pmu_kvm_clr_events(mask);
 
 	/* We rely on the hypervisor switch code to disable guest counters */
-	if (!kvm_pmu_counter_deferred(attr))
+	if (!armv8pmu_kvm_counter_deferred(attr))
 		armv8pmu_disable_counter(mask);
 }
 
@@ -974,7 +973,7 @@  static void armv8pmu_reset(void *info)
 	armv8pmu_disable_intens(U32_MAX);
 
 	/* Clear the counters we flip at guest entry/exit */
-	kvm_clr_pmu_events(U32_MAX);
+	armv8pmu_kvm_clr_events(U32_MAX);
 
 	/*
 	 * Initialize & Reset PMNC. Request overflow interrupt for