Skip to content

Commit a98c810

Browse files
ouptonjannau
authored andcommitted
KVM: arm64: Move PMUVer filtering into KVM code
The supported guest PMU version on a particular platform is ultimately a KVM decision. Move PMUVer filtering into KVM code. Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 48eaf64 commit a98c810

2 files changed

Lines changed: 9 additions & 29 deletions

File tree

arch/arm64/include/asm/cpufeature.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -524,29 +524,6 @@ cpuid_feature_extract_unsigned_field(u64 features, int field)
524524
return cpuid_feature_extract_unsigned_field_width(features, field, 4);
525525
}
526526

527-
/*
528-
* Fields that identify the version of the Performance Monitors Extension do
529-
* not follow the standard ID scheme. See ARM DDI 0487E.a page D13-2825,
530-
* "Alternative ID scheme used for the Performance Monitors Extension version".
531-
*/
532-
static inline u64 __attribute_const__
533-
cpuid_feature_cap_perfmon_field(u64 features, int field, u64 cap)
534-
{
535-
u64 val = cpuid_feature_extract_unsigned_field(features, field);
536-
u64 mask = GENMASK_ULL(field + 3, field);
537-
538-
/* Treat IMPLEMENTATION DEFINED functionality as unimplemented */
539-
if (val == ID_AA64DFR0_EL1_PMUVer_IMP_DEF)
540-
val = 0;
541-
542-
if (val > cap) {
543-
features &= ~mask;
544-
features |= (cap << field) & mask;
545-
}
546-
547-
return features;
548-
}
549-
550527
static inline u64 arm64_ftr_mask(const struct arm64_ftr_bits *ftrp)
551528
{
552529
return (u64)GENMASK(ftrp->shift + ftrp->width - 1, ftrp->shift);

arch/arm64/kvm/pmu-emul.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,13 +1153,16 @@ int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
11531153

11541154
u8 kvm_arm_pmu_get_pmuver_limit(void)
11551155
{
1156-
u64 tmp;
1156+
unsigned int pmuver;
11571157

1158-
tmp = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1);
1159-
tmp = cpuid_feature_cap_perfmon_field(tmp,
1160-
ID_AA64DFR0_EL1_PMUVer_SHIFT,
1161-
ID_AA64DFR0_EL1_PMUVer_V3P5);
1162-
return FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMUVer), tmp);
1158+
pmuver = SYS_FIELD_GET(ID_AA64DFR0_EL1, PMUVer,
1159+
read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1));
1160+
1161+
/* Treat IMPLEMENTATION DEFINED functionality as unimplemented */
1162+
if (pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF)
1163+
return 0;
1164+
1165+
return min(pmuver, ID_AA64DFR0_EL1_PMUVer_V3P5);
11631166
}
11641167

11651168
/**

0 commit comments

Comments
 (0)