@@ -672,8 +672,7 @@ void kvm_host_pmu_init(struct arm_pmu *pmu)
{
struct arm_pmu_entry *entry;
- if (pmu->pmuver == ID_AA64DFR0_EL1_PMUVer_NI ||
- pmu->pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF)
+ if (!pmu_v3_is_supported(pmu->pmuver))
return;
mutex_lock(&arm_pmus_lock);
@@ -1408,7 +1408,7 @@ static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu,
if ((pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF && pmuver > host_pmuver))
return -EINVAL;
- valid_pmu = (pmuver != 0 && pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF);
+ valid_pmu = pmu_v3_is_supported(pmuver);
/* Make sure view register and PMU support do match */
if (kvm_vcpu_has_pmu(vcpu) != valid_pmu)
@@ -12,6 +12,14 @@
#define ARMV8_PMU_CYCLE_IDX (ARMV8_PMU_MAX_COUNTERS - 1)
+static inline bool pmu_v3_is_supported(int pmuver)
+{
+ WARN_ON_ONCE(pmuver & ~GENMASK_ULL(ARM64_FEATURE_FIELD_BITS - 1, 0));
+
+ return (pmuver != ID_AA64DFR0_EL1_PMUVer_NI) &&
+ (pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF);
+}
+
#ifdef CONFIG_HW_PERF_EVENTS
struct kvm_pmc {
Introduce pmu_v3_is_supported() helper to check if the given PMUVer supports PMUv3, and use it instead of open coding it. Signed-off-by: Reiji Watanabe <reijiw@google.com> --- arch/arm64/kvm/pmu-emul.c | 3 +-- arch/arm64/kvm/sys_regs.c | 2 +- include/kvm/arm_pmu.h | 8 ++++++++ 3 files changed, 10 insertions(+), 3 deletions(-)