diff options
author | Mark Rutland <mark.rutland@arm.com> | 2017-02-23 11:03:17 -0500 |
---|---|---|
committer | Will Deacon <will.deacon@arm.com> | 2017-02-24 06:14:12 -0500 |
commit | 638f863dbbc8da16834ee0acc6ac10754f79c486 (patch) | |
tree | 0cedb24f37dbbd00fd95d55d8ac6f1b0e2f85ed9 | |
parent | d81bbe6d882461dec4b71dbe2aa85565fcca4187 (diff) |
arm64/cpufeature: check correct field width when updating sys_val
When we're updating a register's sys_val, we use arm64_ftr_value() to
find the new field value. We use cpuid_feature_extract_field() to find
the new value, but this implicitly assumes a 4-bit field, so we may
extract more bits than we mean to for fields like CTR_EL0.L1ip.
This affects update_cpu_ftr_reg(), where we may extract erroneous values
for ftr_cur and ftr_new. Depending on the additional bits extracted in
either case, we may erroneously detect that the value is mismatched, and
we'll try to compute a new safe value.
Dependent on these extra bits and feature type, arm64_ftr_safe_value()
may pessimistically select the always-safe value, or may erroneously
choose either the extracted cur or new value as the safe option. The
extra bits will subsequently be masked out in arm64_ftr_set_value(), so
we may choose a higher value, yet write back a lower one.
Fix this by passing the width down explicitly in arm64_ftr_value(), so
we always extract the correct amount.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r-- | arch/arm64/include/asm/cpufeature.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 4ce82ed3e7c3..05310ad8c5ab 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h | |||
@@ -184,16 +184,22 @@ static inline u64 arm64_ftr_reg_user_value(const struct arm64_ftr_reg *reg) | |||
184 | } | 184 | } |
185 | 185 | ||
186 | static inline int __attribute_const__ | 186 | static inline int __attribute_const__ |
187 | cpuid_feature_extract_field(u64 features, int field, bool sign) | 187 | cpuid_feature_extract_field_width(u64 features, int field, int width, bool sign) |
188 | { | 188 | { |
189 | return (sign) ? | 189 | return (sign) ? |
190 | cpuid_feature_extract_signed_field(features, field) : | 190 | cpuid_feature_extract_signed_field_width(features, field, width) : |
191 | cpuid_feature_extract_unsigned_field(features, field); | 191 | cpuid_feature_extract_unsigned_field_width(features, field, width); |
192 | } | ||
193 | |||
194 | static inline int __attribute_const__ | ||
195 | cpuid_feature_extract_field(u64 features, int field, bool sign) | ||
196 | { | ||
197 | return cpuid_feature_extract_field_width(features, field, 4, sign); | ||
192 | } | 198 | } |
193 | 199 | ||
194 | static inline s64 arm64_ftr_value(const struct arm64_ftr_bits *ftrp, u64 val) | 200 | static inline s64 arm64_ftr_value(const struct arm64_ftr_bits *ftrp, u64 val) |
195 | { | 201 | { |
196 | return (s64)cpuid_feature_extract_field(val, ftrp->shift, ftrp->sign); | 202 | return (s64)cpuid_feature_extract_field_width(val, ftrp->shift, ftrp->width, ftrp->sign); |
197 | } | 203 | } |
198 | 204 | ||
199 | static inline bool id_aa64mmfr0_mixed_endian_el0(u64 mmfr0) | 205 | static inline bool id_aa64mmfr0_mixed_endian_el0(u64 mmfr0) |