Skip to content

Commit 7d1d19a

Browse files
bjorn-rivospalmer-dabbelt
authored andcommitted
riscv: uprobes: Add missing fence.i after building the XOL buffer
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: 7478408 ("riscv: Add uprobes supported") Signed-off-by: Björn Töpel <bjorn@rivosinc.com> Link: https://lore.kernel.org/r/20250419111402.1660267-2-bjorn@kernel.org Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 121f343 commit 7d1d19a

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

arch/riscv/kernel/probes/uprobes.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
167167
/* Initialize the slot */
168168
void *kaddr = kmap_atomic(page);
169169
void *dst = kaddr + (vaddr & ~PAGE_MASK);
170+
unsigned long start = (unsigned long)dst;
170171

171172
memcpy(dst, src, len);
172173

@@ -176,13 +177,6 @@ void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
176177
*(uprobe_opcode_t *)dst = __BUG_INSN_32;
177178
}
178179

180+
flush_icache_range(start, start + len);
179181
kunmap_atomic(kaddr);
180-
181-
/*
182-
* We probably need flush_icache_user_page() but it needs vma.
183-
* This should work on most of architectures by default. If
184-
* architecture needs to do something different it can define
185-
* its own version of the function.
186-
*/
187-
flush_dcache_page(page);
188182
}

0 commit comments

Comments
 (0)