Skip to content

Commit a683009

Browse files
Suzuki K Poulosegregkh
authored andcommitted
arm64: Fix mismatched cache line size detection
commit 4c4a39d upstream. If there is a mismatch in the I/D min line size, we must always use the system wide safe value both in applications and in the kernel, while performing cache operations. However, we have been checking more bits than just the min line sizes, which triggers false negatives. We may need to trap the user accesses in such cases, but not necessarily patch the kernel. This patch fixes the check to do the right thing as advertised. A new capability will be added to check mismatches in other fields and ensure we trap the CTR accesses. Fixes: be68a8a ("arm64: cpufeature: Fix CTR_EL0 field definitions") Cc: <stable@vger.kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Reported-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d92fa5e commit a683009

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

arch/arm64/include/asm/cachetype.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
#define CTR_L1IP_MASK 3
2323
#define CTR_CWG_SHIFT 24
2424
#define CTR_CWG_MASK 15
25+
#define CTR_DMINLINE_SHIFT 16
26+
#define CTR_IMINLINE_SHIFT 0
27+
28+
#define CTR_CACHE_MINLINE_MASK \
29+
((0xf << CTR_DMINLINE_SHIFT) | (0xf << CTR_IMINLINE_SHIFT))
2530

2631
#define ICACHE_POLICY_RESERVED 0
2732
#define ICACHE_POLICY_AIVIVT 1

arch/arm64/kernel/cpu_errata.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include <linux/types.h>
20+
#include <asm/cachetype.h>
2021
#include <asm/cpu.h>
2122
#include <asm/cputype.h>
2223
#include <asm/cpufeature.h>
@@ -34,9 +35,11 @@ static bool
3435
has_mismatched_cache_line_size(const struct arm64_cpu_capabilities *entry,
3536
int scope)
3637
{
38+
u64 mask = CTR_CACHE_MINLINE_MASK;
39+
3740
WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
38-
return (read_cpuid_cachetype() & arm64_ftr_reg_ctrel0.strict_mask) !=
39-
(arm64_ftr_reg_ctrel0.sys_val & arm64_ftr_reg_ctrel0.strict_mask);
41+
return (read_cpuid_cachetype() & mask) !=
42+
(arm64_ftr_reg_ctrel0.sys_val & mask);
4043
}
4144

4245
static int cpu_enable_trap_ctr_access(void *__unused)

arch/arm64/kernel/cpufeature.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ static const struct arm64_ftr_bits ftr_ctr[] = {
152152
ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 28, 3, 0),
153153
ARM64_FTR_BITS(FTR_STRICT, FTR_HIGHER_SAFE, 24, 4, 0), /* CWG */
154154
ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 20, 4, 0), /* ERG */
155-
ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 16, 4, 1), /* DminLine */
155+
ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, CTR_DMINLINE_SHIFT, 4, 1),
156156
/*
157157
* Linux can handle differing I-cache policies. Userspace JITs will
158158
* make use of *minLine.
159159
* If we have differing I-cache policies, report it as the weakest - AIVIVT.
160160
*/
161161
ARM64_FTR_BITS(FTR_NONSTRICT, FTR_EXACT, 14, 2, ICACHE_POLICY_AIVIVT), /* L1Ip */
162162
ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 4, 10, 0), /* RAZ */
163-
ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 0, 4, 0), /* IminLine */
163+
ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, CTR_IMINLINE_SHIFT, 4, 0),
164164
ARM64_FTR_END,
165165
};
166166

0 commit comments

Comments
 (0)