Skip to content

Commit 63328bb

Browse files
etsalAlexei Starovoitov
authored andcommitted
bpf: Add bpf_stream_print_stack stack dumping kfunc
Add a new kfunc called bpf_stream_print_stack to be used by programs that need to print out their current BPF stack. The kfunc is essentially a wrapper around the existing bpf_stream_dump_stack functionality used to generate stack traces for error events like may_goto violations and BPF-side arena page faults. Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20260203180424.14057-2-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent f941479 commit 63328bb

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

kernel/bpf/helpers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4562,6 +4562,7 @@ BTF_ID_FLAGS(func, bpf_strncasestr);
45624562
BTF_ID_FLAGS(func, bpf_cgroup_read_xattr, KF_RCU)
45634563
#endif
45644564
BTF_ID_FLAGS(func, bpf_stream_vprintk, KF_IMPLICIT_ARGS)
4565+
BTF_ID_FLAGS(func, bpf_stream_print_stack, KF_IMPLICIT_ARGS)
45654566
BTF_ID_FLAGS(func, bpf_task_work_schedule_signal, KF_IMPLICIT_ARGS)
45664567
BTF_ID_FLAGS(func, bpf_task_work_schedule_resume, KF_IMPLICIT_ARGS)
45674568
BTF_ID_FLAGS(func, bpf_dynptr_from_file)

kernel/bpf/stream.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,25 @@ __bpf_kfunc int bpf_stream_vprintk(int stream_id, const char *fmt__str, const vo
245245
return ret;
246246
}
247247

248+
/* Directly trigger a stack dump from the program. */
249+
__bpf_kfunc int bpf_stream_print_stack(int stream_id, struct bpf_prog_aux *aux)
250+
{
251+
struct bpf_stream_stage ss;
252+
struct bpf_prog *prog;
253+
254+
/* Make sure the stream ID is valid. */
255+
if (!bpf_stream_get(stream_id, aux))
256+
return -ENOENT;
257+
258+
prog = aux->main_prog_aux->prog;
259+
260+
bpf_stream_stage(ss, prog, stream_id, ({
261+
bpf_stream_dump_stack(ss);
262+
}));
263+
264+
return 0;
265+
}
266+
248267
__bpf_kfunc_end_defs();
249268

250269
/* Added kfunc to common_btf_ids */

0 commit comments

Comments
 (0)