]> www.infradead.org Git - users/hch/misc.git/commitdiff
KVM: arm64: Provide 1 event counter on IMPDEF hardware
authorOliver Upton <oliver.upton@linux.dev>
Wed, 5 Mar 2025 20:30:21 +0000 (12:30 -0800)
committerOliver Upton <oliver.upton@linux.dev>
Tue, 11 Mar 2025 19:54:30 +0000 (12:54 -0700)
PMUv3 requires that all programmable event counters are capable of
counting any event. The Apple M* PMU is quite a bit different, and
events have affinities for particular PMCs.

Expose 1 event counter on IMPDEF hardware, allowing the guest to do
something useful with its PMU while also upholding the requirements of
the architecture.

Tested-by: Janne Grunau <j@jannau.net>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20250305203021.428366-1-oliver.upton@linux.dev
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
arch/arm64/kvm/pmu-emul.c

index 5f4e9be8aa8bfe723d33e02d7ef5253feaf94277..51fb47e0bf893a31a108452aeb186700fa8dc6c7 100644 (file)
@@ -1038,6 +1038,13 @@ u8 kvm_arm_pmu_get_max_counters(struct kvm *kvm)
 {
        struct arm_pmu *arm_pmu = kvm->arch.arm_pmu;
 
+       /*
+        * PMUv3 requires that all event counters are capable of counting any
+        * event, though the same may not be true of non-PMUv3 hardware.
+        */
+       if (cpus_have_final_cap(ARM64_WORKAROUND_PMUV3_IMPDEF_TRAPS))
+               return 1;
+
        /*
         * The arm_pmu->cntr_mask considers the fixed counter(s) as well.
         * Ignore those and return only the general-purpose counters.