Skip to content

Commit 2f62701

Browse files
robherringwilldeacon
authored andcommitted
KVM: arm64: Refine PMU defines for number of counters
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>
1 parent 126d7d7 commit 2f62701

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

arch/arm64/kvm/pmu-emul.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu)
233233
int i;
234234
struct kvm_pmu *pmu = &vcpu->arch.pmu;
235235

236-
for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++)
236+
for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++)
237237
pmu->pmc[i].idx = i;
238238
}
239239

@@ -260,7 +260,7 @@ void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu)
260260
{
261261
int i;
262262

263-
for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++)
263+
for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++)
264264
kvm_pmu_release_perf_event(kvm_vcpu_idx_to_pmc(vcpu, i));
265265
irq_work_sync(&vcpu->arch.pmu.overflow_work);
266266
}
@@ -291,7 +291,7 @@ void kvm_pmu_enable_counter_mask(struct kvm_vcpu *vcpu, u64 val)
291291
if (!(kvm_vcpu_read_pmcr(vcpu) & ARMV8_PMU_PMCR_E) || !val)
292292
return;
293293

294-
for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) {
294+
for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++) {
295295
struct kvm_pmc *pmc;
296296

297297
if (!(val & BIT(i)))
@@ -323,7 +323,7 @@ void kvm_pmu_disable_counter_mask(struct kvm_vcpu *vcpu, u64 val)
323323
if (!kvm_vcpu_has_pmu(vcpu) || !val)
324324
return;
325325

326-
for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) {
326+
for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++) {
327327
struct kvm_pmc *pmc;
328328

329329
if (!(val & BIT(i)))

arch/arm64/kvm/pmu.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include <linux/kvm_host.h>
77
#include <linux/perf_event.h>
8+
#include <linux/perf/arm_pmu.h>
89
#include <linux/perf/arm_pmuv3.h>
910

1011
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)
9596
u64 typer;
9697
u32 counter;
9798

98-
for_each_set_bit(counter, &events, 32) {
99+
for_each_set_bit(counter, &events, ARMPMU_MAX_HWEVENTS) {
99100
typer = kvm_vcpu_pmu_read_evtype_direct(counter);
100101
typer &= ~ARMV8_PMU_EXCLUDE_EL0;
101102
kvm_vcpu_pmu_write_evtype_direct(counter, typer);
@@ -110,7 +111,7 @@ static void kvm_vcpu_pmu_disable_el0(unsigned long events)
110111
u64 typer;
111112
u32 counter;
112113

113-
for_each_set_bit(counter, &events, 32) {
114+
for_each_set_bit(counter, &events, ARMPMU_MAX_HWEVENTS) {
114115
typer = kvm_vcpu_pmu_read_evtype_direct(counter);
115116
typer |= ARMV8_PMU_EXCLUDE_EL0;
116117
kvm_vcpu_pmu_write_evtype_direct(counter, typer);

include/kvm/arm_pmu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/perf_event.h>
1111
#include <linux/perf/arm_pmuv3.h>
1212

13+
#define KVM_ARMV8_PMU_MAX_COUNTERS 32
1314

1415
#if IS_ENABLED(CONFIG_HW_PERF_EVENTS) && IS_ENABLED(CONFIG_KVM)
1516
struct kvm_pmc {
@@ -25,7 +26,7 @@ struct kvm_pmu_events {
2526
struct kvm_pmu {
2627
struct irq_work overflow_work;
2728
struct kvm_pmu_events events;
28-
struct kvm_pmc pmc[ARMV8_PMU_MAX_COUNTERS];
29+
struct kvm_pmc pmc[KVM_ARMV8_PMU_MAX_COUNTERS];
2930
int irq_num;
3031
bool created;
3132
bool irq_level;

include/linux/perf/arm_pmuv3.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#define __PERF_ARM_PMUV3_H
88

99
#define ARMV8_PMU_MAX_GENERAL_COUNTERS 31
10-
#define ARMV8_PMU_MAX_COUNTERS 32
11-
1210
#define ARMV8_PMU_CYCLE_IDX 31
1311

1412

0 commit comments

Comments
 (0)