Skip to content

Commit 4c4a39d

Browse files
Suzuki K Poulosewildea01
authored andcommitted
arm64: Fix mismatched cache line size detection
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: <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Catalin Marinas <[email protected]> Reported-by: Will Deacon <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 5d16896 commit 4c4a39d

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

arch/arm64/include/asm/cache.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@
2121
#define CTR_L1IP_SHIFT 14
2222
#define CTR_L1IP_MASK 3
2323
#define CTR_DMINLINE_SHIFT 16
24+
#define CTR_IMINLINE_SHIFT 0
2425
#define CTR_ERG_SHIFT 20
2526
#define CTR_CWG_SHIFT 24
2627
#define CTR_CWG_MASK 15
2728
#define CTR_IDC_SHIFT 28
2829
#define CTR_DIC_SHIFT 29
2930

31+
#define CTR_CACHE_MINLINE_MASK \
32+
(0xf << CTR_DMINLINE_SHIFT | 0xf << CTR_IMINLINE_SHIFT)
33+
3034
#define CTR_L1IP(ctr) (((ctr) >> CTR_L1IP_SHIFT) & CTR_L1IP_MASK)
3135

3236
#define ICACHE_POLICY_VPIPT 0

arch/arm64/kernel/cpu_errata.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ static bool
6868
has_mismatched_cache_line_size(const struct arm64_cpu_capabilities *entry,
6969
int scope)
7070
{
71+
u64 mask = CTR_CACHE_MINLINE_MASK;
72+
7173
WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
72-
return (read_cpuid_cachetype() & arm64_ftr_reg_ctrel0.strict_mask) !=
73-
(arm64_ftr_reg_ctrel0.sys_val & arm64_ftr_reg_ctrel0.strict_mask);
74+
return (read_cpuid_cachetype() & mask) !=
75+
(arm64_ftr_reg_ctrel0.sys_val & mask);
7476
}
7577

7678
static void

arch/arm64/kernel/cpufeature.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static const struct arm64_ftr_bits ftr_ctr[] = {
214214
* If we have differing I-cache policies, report it as the weakest - VIPT.
215215
*/
216216
ARM64_FTR_BITS(FTR_VISIBLE, FTR_NONSTRICT, FTR_EXACT, 14, 2, ICACHE_POLICY_VIPT), /* L1Ip */
217-
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, 0, 4, 0), /* IminLine */
217+
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, CTR_IMINLINE_SHIFT, 4, 0),
218218
ARM64_FTR_END,
219219
};
220220

0 commit comments

Comments
 (0)