riscv: Replace function-like macro by static inline function
PATCH v2 1/2 riscv: Replace function-like macro by static inline function
From: Björn Töpel <[email protected]>
The flush_icache_range() function is implemented as a "function-like macro with unused parameters", which can result in "unused variables" warnings.
Replace the macro with a static inline function, as advised by Documentation/process/coding-style.rst.
--- arch/riscv/include/asm/cacheflush.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
arch/riscv/include/asm/cacheflush.h +10 -5
@@ -34,11 +34,6 @@ static inline void flush_dcache_page(struct page *page)flush_dcache_folio (page_folio (page)); } -/* -* RISC-V doesn't have an instruction to flush parts of the instruction cache, -* 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) \ do { \ if (vma->vm_flags & VM_EXEC) \
@@ -78,6 +73,16 @@ void flush_icache_mm(struct mm_struct *mm, bool local);#endif /* CONFIG_SMP */ +/* +* RISC-V doesn't have an instruction to flush parts of the instruction cache, +* so instead we just flush the whole thing. +*/ +#define flush_icache_range flush_icache_range +static inline void flush_icache_range (unsigned long start,unsigned long end) +{ +flush_icache_all (); +} +extern unsigned int riscv_cbom_block_size;extern unsigned int riscv_cboz_block_size;void riscv_init_cbo_blocksizes (void );
base-commit: 8560697b23dc2f405cb463af2b17256a9888129d
Signature · 1 line
2.45.2
PATCH v2 2/2 riscv: uprobes: Add missing fence.i after building the XOL buffer
From: Björn Töpel <[email protected]>
The XOL (execute out-of-line) buffer is used to single-step the replaced instruction(s) for uprobes. The RISC-V port was missing a proper fence.i (i$ flushing) after constructing the XOL buffer, which can result in incorrect execution of stale/broken instructions.
This was found running the BPF selftests "test_progs:uprobe_autoattach, attach_probe" on the Spacemit K1/X60, where the uprobes tests randomly blew up.
---
v2: Correct flush range (Samuel)
--- arch/riscv/kernel/probes/uprobes.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
arch/riscv/kernel/probes/uprobes.c +2 -8
@@ -167,6 +167,7 @@ void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,/* Initialize the slot */ void *kaddr =kmap_atomic (page);void *dst = kaddr + (vaddr & ~PAGE_MASK ); +unsigned long start = (unsigned long )dst;memcpy (dst, src, len);
@@ -176,13 +177,6 @@ void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr, *(uprobe_opcode_t *)dst = __BUG_INSN_32; } +flush_icache_range (start, start + len);kunmap_atomic (kaddr); - -/* -* We probably need flush_icache_user_page() but it needs vma. -* This should work on most of architectures by default. If -* architecture needs to do something different it can define -* its own version of the function. -*/ -flush_dcache_page (page); }
Signature · 1 line
2.45.2
This series was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:
Hello:
This series was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:
Quoted 10 lines · On Sat, 19 Apr 2025 13:13:59 +0200 you wrote:
From: Björn Töpel <[email protected]>
The
flush_icache_range()function is implemented as a "function-like macro with unused parameters", which can result in "unused variables" warnings.Replace the macro with a static inline function, as advised by
Documentation/process/coding-style.rst.[...]
Here is the summary with links:
- [fixes,v2,1/2] riscv: Replace function-like macro by static inline function
https://git.kernel.org/riscv/c/121f34341d39 - [fixes,v2,2/2] riscv: uprobes: Add missing fence.i after building the XOL buffer https://git.kernel.org/riscv/c/7d1d19a11cfb
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html