]> Git Repo - J-linux.git/commitdiff
RISC-V: only flush icache when it has VM_EXEC set
authorYangyu Chen <[email protected]>
Tue, 9 Jan 2024 18:48:59 +0000 (02:48 +0800)
committerPalmer Dabbelt <[email protected]>
Wed, 27 Mar 2024 14:29:27 +0000 (07:29 -0700)
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]>
arch/riscv/include/asm/cacheflush.h

index a129dac4521d35d69af22f713f5cdad27edf7f86..dd8d07146116c8c4629c850b71049053094a92d8 100644 (file)
@@ -33,8 +33,11 @@ static inline void flush_dcache_page(struct page *page)
  * so instead we just flush the whole thing.
  */
 #define flush_icache_range(start, end) flush_icache_all()
-#define flush_icache_user_page(vma, pg, addr, len) \
-       flush_icache_mm(vma->vm_mm, 0)
+#define flush_icache_user_page(vma, pg, addr, len)     \
+do {                                                   \
+       if (vma->vm_flags & VM_EXEC)                    \
+               flush_icache_mm(vma->vm_mm, 0);         \
+} while (0)
 
 #ifdef CONFIG_64BIT
 #define flush_cache_vmap(start, end)           flush_tlb_kernel_range(start, end)
This page took 0.053821 seconds and 4 git commands to generate.