On Mon, Jun 23, 2025 at 08:12:46PM -0700, Kumar Kartikeya Dwivedi wrote: SNIP > diff --git a/kernel/bpf/stream.c b/kernel/bpf/stream.c > index 75ceb6379368..5fb11202ab9c 100644 > --- a/kernel/bpf/stream.c > +++ b/kernel/bpf/stream.c > @@ -2,6 +2,7 @@ > /* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */ > > #include <linux/bpf.h> > +#include <linux/filter.h> > #include <linux/bpf_mem_alloc.h> > #include <linux/percpu.h> > #include <linux/refcount.h> > @@ -483,3 +484,46 @@ bool bpf_prog_stream_error_limit(struct bpf_prog *prog) > { > return atomic_fetch_add(1, &prog->aux->stream_error_cnt) >= BPF_PROG_STREAM_ERROR_CNT; > } > + > +struct dump_stack_ctx { > + struct bpf_stream_stage *ss; > + int err; > +}; > + > +static bool dump_stack_cb(void *cookie, u64 ip, u64 sp, u64 bp) > +{ > + struct dump_stack_ctx *ctxp = cookie; > + const char *file = "", *line = ""; > + struct bpf_prog *prog; > + int num, ret; > + > + if (is_bpf_text_address(ip)) { > + rcu_read_lock(); > + prog = bpf_prog_ksym_find(ip); > + rcu_read_unlock(); do you need to check prog != NULL ? also is_bpf_text_address calls bpf_ksym_find and bpf_prog_ksym_find calls it again, I think it'd be better just to call bpf_prog_ksym_find from here jirka > + ret = bpf_prog_get_file_line(prog, ip, &file, &line, &num); > + if (ret < 0) > + goto end; > + ctxp->err = bpf_stream_stage_printk(ctxp->ss, "%pS\n %s @ %s:%d\n", > + (void *)ip, line, file, num); > + return !ctxp->err; > + } > +end: > + ctxp->err = bpf_stream_stage_printk(ctxp->ss, "%pS\n", (void *)ip); > + return !ctxp->err; > +} > + > +int bpf_stream_stage_dump_stack(struct bpf_stream_stage *ss) > +{ > + struct dump_stack_ctx ctx = { .ss = ss }; > + int ret; > + > + ret = bpf_stream_stage_printk(ss, "CPU: %d UID: %d PID: %d Comm: %s\n", > + raw_smp_processor_id(), __kuid_val(current_real_cred()->euid), > + current->pid, current->comm); > + ret = ret ?: bpf_stream_stage_printk(ss, "Call trace:\n"); > + if (!ret) > + arch_bpf_stack_walk(dump_stack_cb, &ctx); > + ret = ret ?: ctx.err; > + return ret ?: bpf_stream_stage_printk(ss, "\n"); > +} > -- > 2.47.1 > >