Show uprobe_multi link info with fdinfo, the info as follows: link_type: uprobe_multi link_id: 9 prog_tag: e729f789e34a8eca prog_id: 39 type: uprobe_multi uprobe_cnt: 3 pid: 0 path: /home/dylane/bpf/tools/testing/selftests/bpf/test_progs offset ref_ctr_offset cookie 0xa69f13 0x0 3 0xa69f1e 0x0 1 0xa69f29 0x0 2 Signed-off-by: Tao Chen <chen.dylane@xxxxxxxxx> --- kernel/trace/bpf_trace.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) Change list: v3 -> v4: - use %pS to print func info.(Alexei) v3: https://lore.kernel.org/bpf/20250616130233.451439-1-chen.dylane@xxxxxxxxx v2 -> v3: - show info in one line for multi events.(Jiri) v2: https://lore.kernel.org/bpf/20250615150514.418581-1-chen.dylane@xxxxxxxxx v1 -> v2: - replace 'func_cnt' with 'uprobe_cnt'.(Andrii) - print func name is more readable and security for kprobe_multi.(Alexei) v1: https://lore.kernel.org/bpf/20250612115556.295103-1-chen.dylane@xxxxxxxxx diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 24b94870b50..2d422f897ac 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -3157,10 +3157,57 @@ static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link, return err; } +#ifdef CONFIG_PROC_FS +static void bpf_uprobe_multi_show_fdinfo(const struct bpf_link *link, + struct seq_file *seq) +{ + struct bpf_uprobe_multi_link *umulti_link; + char *p, *buf; + + umulti_link = container_of(link, struct bpf_uprobe_multi_link, link); + + buf = kmalloc(PATH_MAX, GFP_KERNEL); + if (!buf) + return; + + p = d_path(&umulti_link->path, buf, PATH_MAX); + if (IS_ERR(p)) { + kfree(buf); + return; + } + + seq_printf(seq, + "type:\t%s\n" + "uprobe_cnt:\t%u\n" + "pid:\t%u\n" + "path:\t%s\n", + umulti_link->flags == BPF_F_UPROBE_MULTI_RETURN ? + "uretprobe_multi" : "uprobe_multi", + umulti_link->cnt, + umulti_link->task ? task_pid_nr_ns(umulti_link->task, + task_active_pid_ns(current)) : 0, + p); + + seq_printf(seq, "%-16s %-16s %-16s\n", "offset", "ref_ctr_offset", "cookie"); + for (int i = 0; i < umulti_link->cnt; i++) { + seq_printf(seq, + "%#-16llx %#-16lx %-16llu\n", + umulti_link->uprobes[i].offset, + umulti_link->uprobes[i].ref_ctr_offset, + umulti_link->uprobes[i].cookie); + } + + kfree(buf); +} +#endif + static const struct bpf_link_ops bpf_uprobe_multi_link_lops = { .release = bpf_uprobe_multi_link_release, .dealloc_deferred = bpf_uprobe_multi_link_dealloc, .fill_link_info = bpf_uprobe_multi_link_fill_link_info, +#ifdef CONFIG_PROC_FS + .show_fdinfo = bpf_uprobe_multi_show_fdinfo, +#endif }; static int uprobe_prog_run(struct bpf_uprobe *uprobe, -- 2.48.1