Skip to content

Commit 6ae4b6e

Browse files
Shanker DonthineniPhilip Elcan
authored andcommitted
arm64: Add support for new control bits CTR_EL0.DIC and CTR_EL0.IDC
The DCache clean & ICache invalidation requirements for instructions to be data coherence are discoverable through new fields in CTR_EL0. The following two control bits DIC and IDC were defined for this purpose. No need to perform point of unification cache maintenance operations from software on systems where CPU caches are transparent. This patch optimize the three functions __flush_cache_user_range(), clean_dcache_area_pou() and invalidate_icache_range() if the hardware reports CTR_EL0.IDC and/or CTR_EL0.IDC. Basically it skips the two instructions 'DC CVAU' and 'IC IVAU', and the associated loop logic in order to avoid the unnecessary overhead. CTR_EL0.DIC: Instruction cache invalidation requirements for instruction to data coherence. The meaning of this bit[29]. 0: Instruction cache invalidation to the point of unification is required for instruction to data coherence. 1: Instruction cache cleaning to the point of unification is not required for instruction to data coherence. CTR_EL0.IDC: Data cache clean requirements for instruction to data coherence. The meaning of this bit[28]. 0: Data cache clean to the point of unification is required for instruction to data coherence, unless CLIDR_EL1.LoC == 0b000 or (CLIDR_EL1.LoUIS == 0b000 && CLIDR_EL1.LoUU == 0b000). 1: Data cache clean to the point of unification is not required for instruction to data coherence. Co-authored-by: Philip Elcan <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Signed-off-by: Shanker Donthineni <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent ca79acc commit 6ae4b6e

File tree

5 files changed

+60
-8
lines changed

5 files changed

+60
-8
lines changed

arch/arm64/include/asm/cache.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020

2121
#define CTR_L1IP_SHIFT 14
2222
#define CTR_L1IP_MASK 3
23+
#define CTR_DMINLINE_SHIFT 16
24+
#define CTR_ERG_SHIFT 20
2325
#define CTR_CWG_SHIFT 24
2426
#define CTR_CWG_MASK 15
27+
#define CTR_IDC_SHIFT 28
28+
#define CTR_DIC_SHIFT 29
2529

2630
#define CTR_L1IP(ctr) (((ctr) >> CTR_L1IP_SHIFT) & CTR_L1IP_MASK)
2731

arch/arm64/include/asm/cacheflush.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ extern void flush_dcache_page(struct page *);
133133

134134
static inline void __flush_icache_all(void)
135135
{
136+
if (cpus_have_const_cap(ARM64_HAS_CACHE_DIC))
137+
return;
138+
136139
asm("ic ialluis");
137140
dsb(ish);
138141
}

arch/arm64/include/asm/cpucaps.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
#define ARM64_HARDEN_BP_POST_GUEST_EXIT 25
4747
#define ARM64_HAS_RAS_EXTN 26
4848
#define ARM64_WORKAROUND_843419 27
49+
#define ARM64_HAS_CACHE_IDC 28
50+
#define ARM64_HAS_CACHE_DIC 29
4951

50-
#define ARM64_NCAPS 28
52+
#define ARM64_NCAPS 30
5153

5254
#endif /* __ASM_CPUCAPS_H */

arch/arm64/kernel/cpufeature.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ static const struct arm64_ftr_bits ftr_id_aa64mmfr2[] = {
199199
};
200200

201201
static const struct arm64_ftr_bits ftr_ctr[] = {
202-
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_EXACT, 31, 1, 1), /* RES1 */
203-
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, 29, 1, 1), /* DIC */
204-
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, 28, 1, 1), /* IDC */
205-
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_HIGHER_SAFE, 24, 4, 0), /* CWG */
206-
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_HIGHER_SAFE, 20, 4, 0), /* ERG */
207-
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, 16, 4, 1), /* DminLine */
202+
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_EXACT, 31, 1, 1), /* RES1 */
203+
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, CTR_DIC_SHIFT, 1, 1),
204+
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, CTR_IDC_SHIFT, 1, 1),
205+
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_HIGHER_SAFE, CTR_CWG_SHIFT, 4, 0),
206+
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_HIGHER_SAFE, CTR_ERG_SHIFT, 4, 0),
207+
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, CTR_DMINLINE_SHIFT, 4, 1),
208208
/*
209209
* Linux can handle differing I-cache policies. Userspace JITs will
210210
* make use of *minLine.
@@ -852,6 +852,18 @@ static bool has_no_fpsimd(const struct arm64_cpu_capabilities *entry, int __unus
852852
ID_AA64PFR0_FP_SHIFT) < 0;
853853
}
854854

855+
static bool has_cache_idc(const struct arm64_cpu_capabilities *entry,
856+
int __unused)
857+
{
858+
return read_sanitised_ftr_reg(SYS_CTR_EL0) & BIT(CTR_IDC_SHIFT);
859+
}
860+
861+
static bool has_cache_dic(const struct arm64_cpu_capabilities *entry,
862+
int __unused)
863+
{
864+
return read_sanitised_ftr_reg(SYS_CTR_EL0) & BIT(CTR_DIC_SHIFT);
865+
}
866+
855867
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
856868
static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */
857869

@@ -1088,6 +1100,18 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
10881100
.enable = cpu_clear_disr,
10891101
},
10901102
#endif /* CONFIG_ARM64_RAS_EXTN */
1103+
{
1104+
.desc = "Data cache clean to the PoU not required for I/D coherence",
1105+
.capability = ARM64_HAS_CACHE_IDC,
1106+
.def_scope = SCOPE_SYSTEM,
1107+
.matches = has_cache_idc,
1108+
},
1109+
{
1110+
.desc = "Instruction cache invalidation not required for I/D coherence",
1111+
.capability = ARM64_HAS_CACHE_DIC,
1112+
.def_scope = SCOPE_SYSTEM,
1113+
.matches = has_cache_dic,
1114+
},
10911115
{},
10921116
};
10931117

arch/arm64/mm/cache.S

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ ENTRY(flush_icache_range)
5050
*/
5151
ENTRY(__flush_cache_user_range)
5252
uaccess_ttbr0_enable x2, x3, x4
53+
alternative_if ARM64_HAS_CACHE_IDC
54+
dsb ishst
55+
b 7f
56+
alternative_else_nop_endif
5357
dcache_line_size x2, x3
5458
sub x3, x2, #1
5559
bic x4, x0, x3
@@ -60,8 +64,13 @@ user_alt 9f, "dc cvau, x4", "dc civac, x4", ARM64_WORKAROUND_CLEAN_CACHE
6064
b.lo 1b
6165
dsb ish
6266

67+
7:
68+
alternative_if ARM64_HAS_CACHE_DIC
69+
isb
70+
b 8f
71+
alternative_else_nop_endif
6372
invalidate_icache_by_line x0, x1, x2, x3, 9f
64-
mov x0, #0
73+
8: mov x0, #0
6574
1:
6675
uaccess_ttbr0_disable x1, x2
6776
ret
@@ -80,6 +89,12 @@ ENDPROC(__flush_cache_user_range)
8089
* - end - virtual end address of region
8190
*/
8291
ENTRY(invalidate_icache_range)
92+
alternative_if ARM64_HAS_CACHE_DIC
93+
mov x0, xzr
94+
isb
95+
ret
96+
alternative_else_nop_endif
97+
8398
uaccess_ttbr0_enable x2, x3, x4
8499

85100
invalidate_icache_by_line x0, x1, x2, x3, 2f
@@ -116,6 +131,10 @@ ENDPIPROC(__flush_dcache_area)
116131
* - size - size in question
117132
*/
118133
ENTRY(__clean_dcache_area_pou)
134+
alternative_if ARM64_HAS_CACHE_IDC
135+
dsb ishst
136+
ret
137+
alternative_else_nop_endif
119138
dcache_by_line_op cvau, ish, x0, x1, x2, x3
120139
ret
121140
ENDPROC(__clean_dcache_area_pou)

0 commit comments

Comments
 (0)