Skip to content

Commit 0a28714

Browse files
Ashok Kumarwildea01
authored andcommitted
arm64: Use PoU cache instr for I/D coherency
In systems with three levels of cache(PoU at L1 and PoC at L3), PoC cache flush instructions flushes L2 and L3 caches which could affect performance. For cache flushes for I and D coherency, PoU should suffice. So changing all I and D coherency related cache flushes to PoU. Introduced a new __clean_dcache_area_pou API for dcache flush till PoU and provided a common macro for __flush_dcache_area and __clean_dcache_area_pou. Also, now in __sync_icache_dcache, icache invalidation for non-aliasing VIPT icache is done only for that particular page instead of the earlier __flush_icache_all. Reviewed-by: Catalin Marinas <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Signed-off-by: Ashok Kumar <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent e6b1185 commit 0a28714

File tree

4 files changed

+58
-26
lines changed

4 files changed

+58
-26
lines changed

arch/arm64/include/asm/cacheflush.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
6969
extern void flush_icache_range(unsigned long start, unsigned long end);
7070
extern void __flush_dcache_area(void *addr, size_t len);
71+
extern void __clean_dcache_area_pou(void *addr, size_t len);
7172
extern long __flush_cache_user_range(unsigned long start, unsigned long end);
7273

7374
static inline void flush_cache_mm(struct mm_struct *mm)

arch/arm64/mm/cache.S

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,31 @@ ENDPROC(__flush_cache_user_range)
8181
/*
8282
* __flush_dcache_area(kaddr, size)
8383
*
84-
* Ensure that the data held in the page kaddr is written back to the
85-
* page in question.
84+
* Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
85+
* are cleaned and invalidated to the PoC.
8686
*
8787
* - kaddr - kernel address
8888
* - size - size in question
8989
*/
9090
ENTRY(__flush_dcache_area)
91-
dcache_line_size x2, x3
92-
add x1, x0, x1
93-
sub x3, x2, #1
94-
bic x0, x0, x3
95-
1: dc civac, x0 // clean & invalidate D line / unified line
96-
add x0, x0, x2
97-
cmp x0, x1
98-
b.lo 1b
99-
dsb sy
91+
dcache_by_line_op civac, sy, x0, x1, x2, x3
10092
ret
10193
ENDPIPROC(__flush_dcache_area)
10294

95+
/*
96+
* __clean_dcache_area_pou(kaddr, size)
97+
*
98+
* Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
99+
* are cleaned to the PoU.
100+
*
101+
* - kaddr - kernel address
102+
* - size - size in question
103+
*/
104+
ENTRY(__clean_dcache_area_pou)
105+
dcache_by_line_op cvau, ish, x0, x1, x2, x3
106+
ret
107+
ENDPROC(__clean_dcache_area_pou)
108+
103109
/*
104110
* __inval_cache_range(start, end)
105111
* - start - start address of region

arch/arm64/mm/flush.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,24 @@ void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
3434
__flush_icache_all();
3535
}
3636

37+
static void sync_icache_aliases(void *kaddr, unsigned long len)
38+
{
39+
unsigned long addr = (unsigned long)kaddr;
40+
41+
if (icache_is_aliasing()) {
42+
__clean_dcache_area_pou(kaddr, len);
43+
__flush_icache_all();
44+
} else {
45+
flush_icache_range(addr, addr + len);
46+
}
47+
}
48+
3749
static void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
3850
unsigned long uaddr, void *kaddr,
3951
unsigned long len)
4052
{
41-
if (vma->vm_flags & VM_EXEC) {
42-
unsigned long addr = (unsigned long)kaddr;
43-
if (icache_is_aliasing()) {
44-
__flush_dcache_area(kaddr, len);
45-
__flush_icache_all();
46-
} else {
47-
flush_icache_range(addr, addr + len);
48-
}
49-
}
53+
if (vma->vm_flags & VM_EXEC)
54+
sync_icache_aliases(kaddr, len);
5055
}
5156

5257
/*
@@ -74,13 +79,11 @@ void __sync_icache_dcache(pte_t pte, unsigned long addr)
7479
if (!page_mapping(page))
7580
return;
7681

77-
if (!test_and_set_bit(PG_dcache_clean, &page->flags)) {
78-
__flush_dcache_area(page_address(page),
79-
PAGE_SIZE << compound_order(page));
82+
if (!test_and_set_bit(PG_dcache_clean, &page->flags))
83+
sync_icache_aliases(page_address(page),
84+
PAGE_SIZE << compound_order(page));
85+
else if (icache_is_aivivt())
8086
__flush_icache_all();
81-
} else if (icache_is_aivivt()) {
82-
__flush_icache_all();
83-
}
8487
}
8588

8689
/*

arch/arm64/mm/proc-macros.S

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,25 @@
6262
bfi \valreg, \tmpreg, #TCR_T0SZ_OFFSET, #TCR_TxSZ_WIDTH
6363
#endif
6464
.endm
65+
66+
/*
67+
* Macro to perform a data cache maintenance for the interval
68+
* [kaddr, kaddr + size)
69+
*
70+
* op: operation passed to dc instruction
71+
* domain: domain used in dsb instruciton
72+
* kaddr: starting virtual address of the region
73+
* size: size of the region
74+
* Corrupts: kaddr, size, tmp1, tmp2
75+
*/
76+
.macro dcache_by_line_op op, domain, kaddr, size, tmp1, tmp2
77+
dcache_line_size \tmp1, \tmp2
78+
add \size, \kaddr, \size
79+
sub \tmp2, \tmp1, #1
80+
bic \kaddr, \kaddr, \tmp2
81+
9998: dc \op, \kaddr
82+
add \kaddr, \kaddr, \tmp1
83+
cmp \kaddr, \size
84+
b.lo 9998b
85+
dsb \domain
86+
.endm

0 commit comments

Comments
 (0)