Skip to content

Commit 5629031

Browse files
committed
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. Tested-by: Janne Grunau <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 3d6d917 commit 5629031

File tree

2 files changed

+9
-29
lines changed

2 files changed

+9
-29
lines changed

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
@@ -1226,13 +1226,16 @@ int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
12261226

12271227
u8 kvm_arm_pmu_get_pmuver_limit(void)
12281228
{
1229-
u64 tmp;
1229+
unsigned int pmuver;
12301230

1231-
tmp = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1);
1232-
tmp = cpuid_feature_cap_perfmon_field(tmp,
1233-
ID_AA64DFR0_EL1_PMUVer_SHIFT,
1234-
ID_AA64DFR0_EL1_PMUVer_V3P5);
1235-
return FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMUVer), tmp);
1231+
pmuver = SYS_FIELD_GET(ID_AA64DFR0_EL1, PMUVer,
1232+
read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1));
1233+
1234+
/* Treat IMPLEMENTATION DEFINED functionality as unimplemented */
1235+
if (pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF)
1236+
return 0;
1237+
1238+
return min(pmuver, ID_AA64DFR0_EL1_PMUVer_V3P5);
12361239
}
12371240

12381241
/**

0 commit comments

Comments
 (0)