Re: [RFC 0/2] openrisc: Add support for KProbes

From: Google

Date: Wed Apr 15 2026 - 02:51:56 EST


Hi Sahil,

On Wed, 8 Apr 2026 00:26:48 +0530
Sahil Siddiq <sahilcdq0@xxxxxxxxx> wrote:

> Hi,
>
> This series adds basic support for KProbes on OpenRISC. There are
> a few changes that I would still like to add and test before this
> can be considered for merging. I was hoping to get some feedback on
> the changes made so far. The implementation in this series is based
> on KProbes for LoongArch, MIPS and RISC-V.

Thanks for porting!
Sashiko reviewed this series, can you check the comments?
Most comments (not all) look reasonable to me.

https://sashiko.dev/#/patchset/20260407185650.79816-1-sahilcdq0%40gmail.com

Generally, please make better use of macros rather than magic values
in your code to make it easier to understand.
Also, use GENMASK() and BIT() macro to define bitmasks and bit.

Thanks,

>
> The current state of the series allows traps to be inserted dynamically
> in the kernel. A KProbe can be inserted via a kernel module whose
> init/exit functions are used to register/unregister a KProbe. A pre-
> handler and post-handler can also be provisioned in the module, which
> are associated with the KProbe and triggered when the probe is hit. See
> the documentation on KProbes for a detailed explanation [1].
>
> The following are yet to be implemented for OpenRISC:
> 1. kretprobes
> 2. kprobe-based event tracing
> 3. ftrace, and kprobe features that depend on ftrace (particularly,
> dynamic tracing)
>
> I hope to submit a patch for kretprobes soon (possibly in a revision of
> this series).
>
> I wrote a couple of kernel modules to test these changes. They can be found
> here [2]. I also ran test_kprobes located at ./lib/tests/ against these
> changes [3]. The results are as shown below:
>
> /home # insmod test_kprobes.ko
> KTAP version 1
> 1..1
> KTAP version 1
> # Subtest: kprobes_test
> # module: test_kprobes
> 1..3
> ok 1 test_kprobe
> ok 2 test_kprobes
> ok 3 test_kprobe_missed
> # kprobes_test: pass:3 fail:0 skip:0 total:3
> # Totals: pass:3 fail:0 skip:0 total:3
> ok 1 kprobes_test
> /home #
>
> When compiling the kernel, the following options should be enabled:
> 1. CONFIG_HAVE_KPROBES=y
> 2. CONFIG_KPROBES=y
>
> Also ensure that CONFIG_KPROBE_EVENTS is disabled.
>
> To compile /lib/tests/test_kprobes.c, add the following to .config:
> 1. CONFIG_KUNIT=y
> 2. CONFIG_DEBUG_KERNEL=y
> 3. CONFIG_KPROBES_SANITY_TEST=m
>
> The first commit cleans up and reorganizes existing functions, fixes
> a few issues with instruction simulation, and introduces new structures
> and macros that will be used by KProbes and other tracing facilities
> in the future.
>
> The second commit adds support for KProbes. Currently, I have
> implemented this in such a way that KProbes can't be used to probe
> a few "blacklisted" instructions. Probes can't be inserted in a delay
> slot either (similar to MIPS). I have also added a few asm functions
> to the blacklist that I think should not be probed. For e.g., "memset"
> and "_trap_handler" have been blacklisted because probing them causes
> the kernel to hang. However, I am not sure if other functions in "entry.S"
> need to be added as well to the blacklist.
>
> Thanks,
> Sahil
>
> [1] https://www.kernel.org/doc/html/latest/trace/kprobes.html
> [2] https://github.com/valdaarhun/or-dev/tree/main/home
> [3] https://github.com/openrisc/linux/blob/for-next/lib/tests/test_kprobes.c
>
> Sahil Siddiq (2):
> openrisc: Add utilities and clean up simulation of instructions
> openrisc: Add KProbes
>
> arch/openrisc/Kconfig | 1 +
> arch/openrisc/configs/or1ksim_defconfig | 2 +
> arch/openrisc/configs/virt_defconfig | 2 +
> arch/openrisc/include/asm/asm.h | 22 ++
> arch/openrisc/include/asm/break.h | 19 ++
> arch/openrisc/include/asm/insn-def.h | 61 +++-
> arch/openrisc/include/asm/kprobes.h | 76 +++++
> arch/openrisc/include/asm/spr_defs.h | 1 +
> arch/openrisc/kernel/Makefile | 3 +-
> arch/openrisc/kernel/entry.S | 16 +
> arch/openrisc/kernel/insn.c | 74 +++++
> arch/openrisc/kernel/jump_label.c | 2 +-
> arch/openrisc/kernel/kprobes.c | 381 ++++++++++++++++++++++++
> arch/openrisc/kernel/traps.c | 67 ++---
> arch/openrisc/lib/memcpy.c | 2 +
> arch/openrisc/lib/memset.S | 4 +
> arch/openrisc/mm/fault.c | 5 +
> samples/kprobes/kprobe_example.c | 8 +
> 18 files changed, 701 insertions(+), 45 deletions(-)
> create mode 100644 arch/openrisc/include/asm/asm.h
> create mode 100644 arch/openrisc/include/asm/break.h
> create mode 100644 arch/openrisc/include/asm/kprobes.h
> create mode 100644 arch/openrisc/kernel/insn.c
> create mode 100644 arch/openrisc/kernel/kprobes.c
>
> --
> 2.53.0
>


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>