[RFC PATCH 05/14] KVM: arm64: Always allow fixed cycle counter
Oliver Upton
oliver.upton at linux.dev
Tue Dec 3 11:32:11 PST 2024
The fixed CPU cycle counter is mandatory for PMUv3, so it doesn't make a
lot of sense allowing userspace to filter it. Only apply the PMU event
filter to *programmed* event counters.
While at it, use the generic CPU_CYCLES perf event to back the cycle
counter, potentially allowing non-PMUv3 drivers to map the event onto
the underlying implementation.
Signed-off-by: Oliver Upton <oliver.upton at linux.dev>
---
arch/arm64/kvm/pmu-emul.c | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 809d65b912e8..3e7091e1a2e4 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -707,26 +707,27 @@ static void kvm_pmu_create_perf_event(struct kvm_pmc *pmc)
evtreg = kvm_pmc_read_evtreg(pmc);
kvm_pmu_stop_counter(pmc);
- if (pmc->idx == ARMV8_PMU_CYCLE_IDX)
+ if (pmc->idx == ARMV8_PMU_CYCLE_IDX) {
eventsel = ARMV8_PMUV3_PERFCTR_CPU_CYCLES;
- else
+ } else {
eventsel = evtreg & kvm_pmu_event_mask(vcpu->kvm);
- /*
- * Neither SW increment nor chained events need to be backed
- * by a perf event.
- */
- if (eventsel == ARMV8_PMUV3_PERFCTR_SW_INCR ||
- eventsel == ARMV8_PMUV3_PERFCTR_CHAIN)
- return;
+ /*
+ * If we have a filter in place and that the event isn't
+ * allowed, do not install a perf event either.
+ */
+ if (vcpu->kvm->arch.pmu_filter &&
+ !test_bit(eventsel, vcpu->kvm->arch.pmu_filter))
+ return;
- /*
- * If we have a filter in place and that the event isn't allowed, do
- * not install a perf event either.
- */
- if (vcpu->kvm->arch.pmu_filter &&
- !test_bit(eventsel, vcpu->kvm->arch.pmu_filter))
- return;
+ /*
+ * Neither SW increment nor chained events need to be backed
+ * by a perf event.
+ */
+ if (eventsel == ARMV8_PMUV3_PERFCTR_SW_INCR ||
+ eventsel == ARMV8_PMUV3_PERFCTR_CHAIN)
+ return;
+ }
memset(&attr, 0, sizeof(struct perf_event_attr));
attr.type = arm_pmu->pmu.type;
@@ -877,6 +878,8 @@ static u64 compute_pmceid0(struct arm_pmu *pmu)
/* always support CHAIN */
val |= BIT(ARMV8_PMUV3_PERFCTR_CHAIN);
+ /* always support CPU_CYCLES */
+ val |= BIT(ARMV8_PMUV3_PERFCTR_CPU_CYCLES);
return val;
}
--
2.39.5
More information about the linux-arm-kernel
mailing list