From: Sahil <sahilcdq0@gmail.com>
To: Stafford Horne <shorne@gmail.com>
Cc: jonas@southpole.se, stefan.kristiansson@saunalahti.fi,
naveen@kernel.org, davem@davemloft.net, mhiramat@kernel.org,
pjw@kernel.org, wangruikang@iscas.ac.cn, namcao@linutronix.de,
kees@kernel.org, linux-openrisc@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 4/4] openrisc: Add Kretprobes
Date: Fri, 13 Nov 2026 22:46:45 +0530 [thread overview]
Message-ID: <3a931844-7b7f-4408-8d92-d0604ca7d51d@gmail.com> (raw)
In-Reply-To: <avArkiSOmUfSrmYF@antec>
On 11/8/26 1:28 PM, Stafford Horne wrote:
> On Tue, Oct 27, 2026 at 01:42:40AM +0530, Sahil Siddiq wrote:
>> Add Kretprobes support for OpenRISC. Kretprobes allow a probe to be
>> fired when a function returns. They are built on top of the generic
>> rethook framework and also require the KProbe mechanism introduced
>> in the previous commit. This work is primarily based on similar work
>> done for RISC-V.
>>
>> Kretprobes work by inserting a KProbe at a function's entry point.
>> When the function begins to execute, the KProbe is fired and its
>> pre-handler replaces the function's return address with that of the
>> rethook trampoline. The trampoline in turn calls the kretprobe handler.
>> Control is returned to the original caller following this.
>>
>> Signed-off-by: Sahil Siddiq <sahilcdq0@gmail.com>
>> ---
>> Changes v2 -> v3:
>> - arch/openrisc/kernel/rethook_trampoline.S:
>> (save_all_base_regs): Save SR and SP registers
>> (restore_all_base_regs): Restore SR register
>>
>> Changes v1 -> v2: New commit
>>
>> [...]
>> +#include <linux/kprobes.h>
>> +#include <linux/rethook.h>
>> +#include "rethook.h"
>> +
>> +unsigned long arch_rethook_trampoline_callback(struct pt_regs *regs)
>> +{
>> + return rethook_trampoline_handler(regs, regs->gpr2);
>> +}
>> +NOKPROBE_SYMBOL(arch_rethook_trampoline_callback)
>> +
>> +void arch_rethook_prepare(struct rethook_node *rhn, struct pt_regs *regs, bool mcount)
>> +{
>> + /* Store original return address and frame pointer */
>> + rhn->ret_addr = regs->gpr9;
>> + rhn->frame = regs->gpr2;
>> +
>> + /* Set return address to trampoline */
>> + regs->gpr9 = (unsigned long)arch_rethook_trampoline;
>
> Though this will work, in the kernel code we prefer to regs->gpr[n] syntax
> for accessing gprs. So to be consistent could you use that? i.e. regs->gpr[9];
Sure, I'll change this.
>> +}
>> +NOKPROBE_SYMBOL(arch_rethook_prepare)
>> diff --git a/arch/openrisc/kernel/rethook.h b/arch/openrisc/kernel/rethook.h
>> new file mode 100644
>> index 000000000000..332306a5c380
>> --- /dev/null
>> +++ b/arch/openrisc/kernel/rethook.h
>> @@ -0,0 +1,8 @@
>> +/* SPDX-License-Identifier: GPL-2.0-or-later */
>> +#ifndef __OPENRISC_RETHOOK_H
>> +#define __OPENRISC_RETHOOK_H
>> +
>> +unsigned long arch_rethook_trampoline_callback(struct pt_regs *regs);
>> +void arch_rethook_prepare(struct rethook_node *rhn, struct pt_regs *regs, bool mcount);
>> +
>> +#endif
>> diff --git a/arch/openrisc/kernel/rethook_trampoline.S b/arch/openrisc/kernel/rethook_trampoline.S
>> new file mode 100644
>> index 000000000000..5e8fd5a65222
>> --- /dev/null
>> +++ b/arch/openrisc/kernel/rethook_trampoline.S
>> [...]
>> +SYM_CODE_START(arch_rethook_trampoline)
>> + /* Allocate enough space on stack for pt_regs */
>> + l.addi r1,r1,-PT_SIZE
>> + save_all_base_regs
>> +
>> + l.addi r3,r1,0 /* pt_regs */
>> + l.jal arch_rethook_trampoline_callback
>> + l.nop
>
> Could you indent the delay slot? For example:
>
> l.jal ...
> l.nop
>
>> +
>> + /* use the result as the return-address */
>> + l.addi r9,r11,0
>> +
>> + restore_all_base_regs
>> + l.addi r1,r1,PT_SIZE
>> +
>> + l.jr r9
>> + l.nop
>
> Indent here too.
Sure, I'll format these as well.
>> +SYM_CODE_END(arch_rethook_trampoline)
>
> Thanks,
>
> -Stafford
Thanks,
Sahil
prev parent reply other threads:[~2026-11-13 17:16 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260930202744.50489-1-sahilcdq0@gmail.com>
2026-10-26 20:12 ` [PATCH v3 0/4] openrisc: Add support for KProbes and Kretprobes Sahil Siddiq
2026-11-13 9:04 ` Masami Hiramatsu (Google)
2026-11-13 17:22 ` Sahil
2026-10-26 20:12 ` [PATCH v3 1/4] openrisc: Add utilities and clean up simulation of instructions Sahil Siddiq
2026-11-07 6:45 ` Stafford Horne
2026-11-13 17:11 ` Sahil
2026-11-15 1:13 ` Stafford Horne
2026-10-26 20:12 ` [PATCH v3 2/4] openrisc: Add KProbes Sahil Siddiq
2026-10-26 20:26 ` Sahil
2026-10-26 20:35 ` sashiko-bot
2026-11-08 7:46 ` Stafford Horne
2026-11-13 17:13 ` Sahil
2026-11-15 1:44 ` Stafford Horne
2026-10-26 20:12 ` [PATCH v3 3/4] openrisc: Add unit tests for KProbes on branch instructions Sahil Siddiq
2026-10-26 20:26 ` sashiko-bot
2026-11-08 8:03 ` Stafford Horne
2026-11-13 17:15 ` Sahil
2026-11-15 1:52 ` Stafford Horne
2026-10-26 20:12 ` [PATCH v3 4/4] openrisc: Add Kretprobes Sahil Siddiq
2026-10-26 20:28 ` sashiko-bot
2026-11-08 7:58 ` Stafford Horne
2026-11-13 17:16 ` Sahil [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3a931844-7b7f-4408-8d92-d0604ca7d51d@gmail.com \
--to=sahilcdq0@gmail.com \
--cc=davem@davemloft.net \
--cc=jonas@southpole.se \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-openrisc@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=namcao@linutronix.de \
--cc=naveen@kernel.org \
--cc=pjw@kernel.org \
--cc=shorne@gmail.com \
--cc=stefan.kristiansson@saunalahti.fi \
--cc=wangruikang@iscas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.