]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: Add show_fdinfo for uprobe_multi
authorTao Chen <chen.dylane@linux.dev>
Wed, 2 Jul 2025 15:39:57 +0000 (23:39 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 4 Jul 2025 02:29:42 +0000 (19:29 -0700)
Show uprobe_multi link info with fdinfo, the info as follows:

link_type: uprobe_multi
link_id: 9
prog_tag: e729f789e34a8eca
prog_id: 39
uprobe_cnt: 3
pid: 0
path: /home/dylane/bpf/tools/testing/selftests/bpf/test_progs
cookie  offset  ref_ctr_offset
3  0xa69f13  0x0
1  0xa69f1e  0x0
2  0xa69f29  0x0

Signed-off-by: Tao Chen <chen.dylane@linux.dev>
Link: https://lore.kernel.org/r/20250702153958.639852-2-chen.dylane@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/trace/bpf_trace.c

index 81d7a4e5ae1540efd41c6d71b01d578b4e2c416f..b2737642c42a4194232182af3d6c052f612ad583 100644 (file)
@@ -3152,10 +3152,54 @@ 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;
+       pid_t pid;
+
+       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;
+       }
+
+       pid = umulti_link->task ?
+             task_pid_nr_ns(umulti_link->task, task_active_pid_ns(current)) : 0;
+       seq_printf(seq,
+                  "uprobe_cnt:\t%u\n"
+                  "pid:\t%u\n"
+                  "path:\t%s\n",
+                  umulti_link->cnt, pid, p);
+
+       seq_printf(seq, "%s\t %s\t %s\n", "cookie", "offset", "ref_ctr_offset");
+       for (int i = 0; i < umulti_link->cnt; i++) {
+               seq_printf(seq,
+                          "%llu\t %#llx\t %#lx\n",
+                          umulti_link->uprobes[i].cookie,
+                          umulti_link->uprobes[i].offset,
+                          umulti_link->uprobes[i].ref_ctr_offset);
+       }
+
+       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,