From: Pu Lehui <pulehui@huawei.com>
To: "Björn Töpel" <bjorn@kernel.org>,
"Varun R Mallya" <varunrmallya@gmail.com>,
pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, memxor@gmail.com
Cc: <alex@ghiti.fr>, <martin.lau@linux.dev>, <song@kernel.org>,
<yonghong.song@linux.dev>, <jolsa@kernel.org>,
<emil@etsalapatis.com>, <puranjay@kernel.org>, <shuah@kernel.org>,
<linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
<bpf@vger.kernel.org>, <linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH bpf-next v2 1/3] riscv: stacktrace: Implement arch_bpf_stack_walk() for BPF
Date: Mon, 29 Jun 2026 10:45:36 +0800 [thread overview]
Message-ID: <912fa271-7358-46b6-ad19-8a2a25b7d34a@huawei.com> (raw)
In-Reply-To: <87ik72y3sr.fsf@all.your.base.are.belong.to.us>
On 2026/6/29 1:26, Björn Töpel wrote:
> Varun!
>
> Thanks for spending time on getting RV eBPF more feature complete! Sorry
> for the slow replies.
>
> Varun R Mallya <varunrmallya@gmail.com> writes:
>
>> This will be used by bpf_throw() to unwind till the program marked as
>> exception boundary and run the callback with the stack of the main
>> program.
>> This is required for supporting BPF exceptions on RISC-V.
>> This depends on the frame pointer unwinder, so it is only built under
>> CONFIG_FRAME_POINTER, else falls back to the weak no-op.
>>
>> Signed-off-by: Varun R Mallya <varunrmallya@gmail.com>
>> Reviewed-by: Pu Lehui <pulehui@huawei.com>
>> ---
>> arch/riscv/kernel/stacktrace.c | 31 +++++++++++++++++++++++++++++++
>> 1 file changed, 31 insertions(+)
>>
>> diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
>> index c7555447149b..64929381bb30 100644
>> --- a/arch/riscv/kernel/stacktrace.c
>> +++ b/arch/riscv/kernel/stacktrace.c
>> @@ -5,6 +5,7 @@
>> */
>>
>> #include <linux/export.h>
>> +#include <linux/filter.h>
>> #include <linux/kallsyms.h>
>> #include <linux/sched.h>
>> #include <linux/sched/debug.h>
>> @@ -102,6 +103,36 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
>> }
>> }
>>
>> +void notrace arch_bpf_stack_walk(bool (*consume_fn)(void *cookie, u64 ip, u64 sp, u64 bp),
>> + void *cookie)
>> +{
>> + unsigned long fp, sp, pc;
>> + int graph_idx = 0;
>> +
>> + fp = (unsigned long)__builtin_frame_address(0);
>> + sp = current_stack_pointer;
>> + pc = (unsigned long)arch_bpf_stack_walk;
>> +
>> + for (;;) {
>> + struct stackframe *frame;
>> +
>> + if (unlikely(!__kernel_text_address(pc)))
>> + break;
>> + /* pc belongs to the function whose frame pointer is fp */
>> + if (!consume_fn(cookie, pc, sp, fp))
>> + break;
>> + if (unlikely(!fp_is_valid(fp, sp)))
>> + break;
>> +
>> + frame = (struct stackframe *)fp - 1;
>> + sp = fp;
>> + fp = READ_ONCE_TASK_STACK(current, frame->fp);
>> + pc = READ_ONCE_TASK_STACK(current, frame->ra);
>> + pc = ftrace_graph_ret_addr(current, &graph_idx, pc,
>> + &frame->ra);
>> + }
>> +}
>
> We don't need more stack unwinders. Can you see if you can extend
> walk_stackframe() with "cookie" to match BPF's needs? Have a look at
> what arm64 does.
>
> Sashiko had a good point about ftrace_graph_ret_addr() -- now what about
> kretprobe? Do we need to take that in consideration as well?
IIUC, arch_bpf_stack_walk only unwind for bpf prog stack, maybe we could
not need to handle kretprobe.
>
>
> Thanks,
> Björn
next prev parent reply other threads:[~2026-06-29 2:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-28 8:17 [PATCH bpf-next v2 0/3] Add BPF Exceptions support for RISC-V Varun R Mallya
2026-06-28 8:17 ` [PATCH bpf-next v2 1/3] riscv: stacktrace: Implement arch_bpf_stack_walk() for BPF Varun R Mallya
2026-06-28 17:26 ` Björn Töpel
2026-06-29 2:45 ` Pu Lehui [this message]
2026-06-28 8:17 ` [PATCH bpf-next v2 2/3] riscv, bpf: Add support for BPF exceptions Varun R Mallya
2026-06-28 17:50 ` Björn Töpel
2026-06-29 3:01 ` Pu Lehui
2026-06-28 8:17 ` [PATCH bpf-next v2 3/3] riscv, bpf: Remove BPF exceptions from BPF CI denylist Varun R Mallya
2026-06-28 18:00 ` Björn Töpel
2026-07-06 8:55 ` Varun R Mallya
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=912fa271-7358-46b6-ad19-8a2a25b7d34a@huawei.com \
--to=pulehui@huawei.com \
--cc=alex@ghiti.fr \
--cc=andrii@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=puranjay@kernel.org \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=varunrmallya@gmail.com \
--cc=yonghong.song@linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®