KVM: arm64: Refine PMU defines for number of counters
authorRob Herring (Arm) <robh@kernel.org>
Wed, 31 Jul 2024 16:51:23 +0000 (10:51 -0600)
committerWill Deacon <will@kernel.org>
Fri, 16 Aug 2024 12:09:12 +0000 (13:09 +0100)
There are 2 defines for the number of PMU counters:
ARMV8_PMU_MAX_COUNTERS and ARMPMU_MAX_HWEVENTS. Both are the same
currently, but Armv9.4/8.9 increases the number of possible counters
from 32 to 33. With this change, the maximum number of counters will
differ for KVM's PMU emulation which is PMUv3.4. Give KVM PMU emulation
its own define to decouple it from the rest of the kernel's number PMU
counters.

The VHE PMU code needs to match the PMU driver, so switch it to use
ARMPMU_MAX_HWEVENTS instead.

Acked-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Tested-by: James Clark <james.clark@linaro.org>
Link: https://lore.kernel.org/r/20240731-arm-pmu-3-9-icntr-v3-6-280a8d7ff465@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/kvm/pmu-emul.c
arch/arm64/kvm/pmu.c
include/kvm/arm_pmu.h
include/linux/perf/arm_pmuv3.h

index 0e598f6c42c006ecd91c7993ee1da7b08c1d2897..ac36c438b8c18c9d4a06781707dc73ea202c948e 100644 (file)
@@ -233,7 +233,7 @@ void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu)
        int i;
        struct kvm_pmu *pmu = &vcpu->arch.pmu;
 
-       for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++)
+       for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++)
                pmu->pmc[i].idx = i;
 }
 
@@ -260,7 +260,7 @@ void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu)
 {
        int i;
 
-       for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++)
+       for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++)
                kvm_pmu_release_perf_event(kvm_vcpu_idx_to_pmc(vcpu, i));
        irq_work_sync(&vcpu->arch.pmu.overflow_work);
 }
@@ -291,7 +291,7 @@ void kvm_pmu_enable_counter_mask(struct kvm_vcpu *vcpu, u64 val)
        if (!(kvm_vcpu_read_pmcr(vcpu) & ARMV8_PMU_PMCR_E) || !val)
                return;
 
-       for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) {
+       for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++) {
                struct kvm_pmc *pmc;
 
                if (!(val & BIT(i)))
@@ -323,7 +323,7 @@ void kvm_pmu_disable_counter_mask(struct kvm_vcpu *vcpu, u64 val)
        if (!kvm_vcpu_has_pmu(vcpu) || !val)
                return;
 
-       for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) {
+       for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++) {
                struct kvm_pmc *pmc;
 
                if (!(val & BIT(i)))
index a47ae311d4a82f40e27045aa117f1314997e6a3a..215b748758159a277a69f841abda226ce478a9c3 100644 (file)
@@ -5,6 +5,7 @@
  */
 #include <linux/kvm_host.h>
 #include <linux/perf_event.h>
+#include <linux/perf/arm_pmu.h>
 #include <linux/perf/arm_pmuv3.h>
 
 static DEFINE_PER_CPU(struct kvm_pmu_events, kvm_pmu_events);
@@ -95,7 +96,7 @@ static void kvm_vcpu_pmu_enable_el0(unsigned long events)
        u64 typer;
        u32 counter;
 
-       for_each_set_bit(counter, &events, 32) {
+       for_each_set_bit(counter, &events, ARMPMU_MAX_HWEVENTS) {
                typer = kvm_vcpu_pmu_read_evtype_direct(counter);
                typer &= ~ARMV8_PMU_EXCLUDE_EL0;
                kvm_vcpu_pmu_write_evtype_direct(counter, typer);
@@ -110,7 +111,7 @@ static void kvm_vcpu_pmu_disable_el0(unsigned long events)
        u64 typer;
        u32 counter;
 
-       for_each_set_bit(counter, &events, 32) {
+       for_each_set_bit(counter, &events, ARMPMU_MAX_HWEVENTS) {
                typer = kvm_vcpu_pmu_read_evtype_direct(counter);
                typer |= ARMV8_PMU_EXCLUDE_EL0;
                kvm_vcpu_pmu_write_evtype_direct(counter, typer);
index 871067fb26164ba0d6301481c208ab8e1f8fdf1a..e08aeec5d936fb1cee2900e6996196854afb2094 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/perf_event.h>
 #include <linux/perf/arm_pmuv3.h>
 
+#define KVM_ARMV8_PMU_MAX_COUNTERS     32
 
 #if IS_ENABLED(CONFIG_HW_PERF_EVENTS) && IS_ENABLED(CONFIG_KVM)
 struct kvm_pmc {
@@ -25,7 +26,7 @@ struct kvm_pmu_events {
 struct kvm_pmu {
        struct irq_work overflow_work;
        struct kvm_pmu_events events;
-       struct kvm_pmc pmc[ARMV8_PMU_MAX_COUNTERS];
+       struct kvm_pmc pmc[KVM_ARMV8_PMU_MAX_COUNTERS];
        int irq_num;
        bool created;
        bool irq_level;
index f4ec76f725a36c4f4a5172e698d75924d9efde1b..4f7a7f2222e574a008ccc5d5810be608ab9f0707 100644 (file)
@@ -7,8 +7,6 @@
 #define __PERF_ARM_PMUV3_H
 
 #define ARMV8_PMU_MAX_GENERAL_COUNTERS 31
-#define ARMV8_PMU_MAX_COUNTERS 32
-
 #define ARMV8_PMU_CYCLE_IDX            31