* [PATCH fixes v2 1/2] riscv: Replace function-like macro by static inline function
@ 2025-04-19 11:13 Björn Töpel
2025-04-19 11:14 ` [PATCH fixes v2 2/2] riscv: uprobes: Add missing fence.i after building the XOL buffer Björn Töpel
2025-04-24 20:32 ` [PATCH fixes v2 1/2] riscv: Replace function-like macro by static inline function patchwork-bot+linux-riscv
0 siblings, 2 replies; 3+ messages in thread
From: Björn Töpel @ 2025-04-19 11:13 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Alexandre Ghiti, linux-riscv,
Guo Ren, Samuel Holland
Cc: Björn Töpel, Masami Hiramatsu, Oleg Nesterov,
Peter Zijlstra, linux-kernel, linux-trace-kernel
From: Björn Töpel <bjorn@rivosinc.com>
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.
Fixes: 08f051eda33b ("RISC-V: Flush I$ when making a dirty page executable")
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
---
arch/riscv/include/asm/cacheflush.h | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h
index 8de73f91bfa3..b59ffeb668d6 100644
--- a/arch/riscv/include/asm/cacheflush.h
+++ b/arch/riscv/include/asm/cacheflush.h
@@ -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
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH fixes v2 2/2] riscv: uprobes: Add missing fence.i after building the XOL buffer
2025-04-19 11:13 [PATCH fixes v2 1/2] riscv: Replace function-like macro by static inline function Björn Töpel
@ 2025-04-19 11:14 ` Björn Töpel
2025-04-24 20:32 ` [PATCH fixes v2 1/2] riscv: Replace function-like macro by static inline function patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: Björn Töpel @ 2025-04-19 11:14 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Alexandre Ghiti, linux-riscv,
Guo Ren, Samuel Holland
Cc: Björn Töpel, Masami Hiramatsu, Oleg Nesterov,
Peter Zijlstra, linux-kernel, linux-trace-kernel
From: Björn Töpel <bjorn@rivosinc.com>
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.
Reviewed-by: Guo Ren <guoren@kernel.org>
Fixes: 74784081aac8 ("riscv: Add uprobes supported")
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
---
v2: Correct flush range (Samuel)
---
arch/riscv/kernel/probes/uprobes.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/arch/riscv/kernel/probes/uprobes.c b/arch/riscv/kernel/probes/uprobes.c
index 4b3dc8beaf77..cc15f7ca6cc1 100644
--- a/arch/riscv/kernel/probes/uprobes.c
+++ b/arch/riscv/kernel/probes/uprobes.c
@@ -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);
}
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH fixes v2 1/2] riscv: Replace function-like macro by static inline function
2025-04-19 11:13 [PATCH fixes v2 1/2] riscv: Replace function-like macro by static inline function Björn Töpel
2025-04-19 11:14 ` [PATCH fixes v2 2/2] riscv: uprobes: Add missing fence.i after building the XOL buffer Björn Töpel
@ 2025-04-24 20:32 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+linux-riscv @ 2025-04-24 20:32 UTC (permalink / raw)
To: =?utf-8?b?QmrDtnJuIFTDtnBlbCA8Ympvcm5Aa2VybmVsLm9yZz4=?=
Cc: linux-riscv, paul.walmsley, palmer, alex, guoren, samuel.holland,
bjorn, mhiramat, oleg, peterz, linux-kernel, linux-trace-kernel
Hello:
This series was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:
On Sat, 19 Apr 2025 13:13:59 +0200 you wrote:
> From: Björn Töpel <bjorn@rivosinc.com>
>
> 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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-24 20:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-19 11:13 [PATCH fixes v2 1/2] riscv: Replace function-like macro by static inline function Björn Töpel
2025-04-19 11:14 ` [PATCH fixes v2 2/2] riscv: uprobes: Add missing fence.i after building the XOL buffer Björn Töpel
2025-04-24 20:32 ` [PATCH fixes v2 1/2] riscv: Replace function-like macro by static inline function patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).