Skip to content

Commit 6f32be7

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 28aa197 commit 6f32be7

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
@@ -525,29 +525,6 @@ cpuid_feature_extract_unsigned_field(u64 features, int field)
525525
return cpuid_feature_extract_unsigned_field_width(features, field, 4);
526526
}
527527

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

12391239
u8 kvm_arm_pmu_get_pmuver_limit(void)
12401240
{
1241-
u64 tmp;
1241+
unsigned int pmuver;
12421242

1243-
tmp = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1);
1244-
tmp = cpuid_feature_cap_perfmon_field(tmp,
1245-
ID_AA64DFR0_EL1_PMUVer_SHIFT,
1246-
ID_AA64DFR0_EL1_PMUVer_V3P5);
1247-
return FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMUVer), tmp);
1243+
pmuver = SYS_FIELD_GET(ID_AA64DFR0_EL1, PMUVer,
1244+
read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1));
1245+
1246+
/* Treat IMPLEMENTATION DEFINED functionality as unimplemented */
1247+
if (pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF)
1248+
return 0;
1249+
1250+
return min(pmuver, ID_AA64DFR0_EL1_PMUVer_V3P5);
12481251
}
12491252

12501253
/**

0 commit comments

Comments
 (0)