Skip to content

Commit 542124f

Browse files
cyyselfpalmer-dabbelt
authored andcommitted
RISC-V: only flush icache when it has VM_EXEC set
As I-Cache flush on current RISC-V needs to send IPIs to every CPU cores in the system is very costly, limiting flush_icache_mm to be called only when vma->vm_flags has VM_EXEC can help minimize the frequency of these operations. It improves performance and reduces disturbances when copy_from_user_page is needed such as profiling with perf. For I-D coherence concerns, it will not fail if such a page adds VM_EXEC flags in the future since we have checked it in the __set_pte_at function. Signed-off-by: Yangyu Chen <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 84c3a07 commit 542124f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arch/riscv/include/asm/cacheflush.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ static inline void flush_dcache_page(struct page *page)
3333
* so instead we just flush the whole thing.
3434
*/
3535
#define flush_icache_range(start, end) flush_icache_all()
36-
#define flush_icache_user_page(vma, pg, addr, len) \
37-
flush_icache_mm(vma->vm_mm, 0)
36+
#define flush_icache_user_page(vma, pg, addr, len) \
37+
do { \
38+
if (vma->vm_flags & VM_EXEC) \
39+
flush_icache_mm(vma->vm_mm, 0); \
40+
} while (0)
3841

3942
#ifdef CONFIG_64BIT
4043
#define flush_cache_vmap(start, end) flush_tlb_kernel_range(start, end)

0 commit comments

Comments
 (0)