linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 1/2] bpf: Add show_fdinfo for uprobe_multi
@ 2025-06-16 13:02 Tao Chen
  2025-06-16 13:02 ` [PATCH bpf-next v3 2/2] bpf: Add show_fdinfo for kprobe_multi Tao Chen
  0 siblings, 1 reply; 4+ messages in thread
From: Tao Chen @ 2025-06-16 13:02 UTC (permalink / raw)
  To: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, jolsa, mattbobrowski,
	rostedt, mhiramat, mathieu.desnoyers
  Cc: bpf, linux-kernel, linux-trace-kernel, Tao Chen

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@linux.dev>
---
 kernel/trace/bpf_trace.c | 47 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

Change list:
  v2 -> v3:
    - show info in one line for multi events.(Jiri)
  v2:
  https://lore.kernel.org/bpf/20250615150514.418581-1-chen.dylane@linux.dev 

  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@linux.dev

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH bpf-next v3 2/2] bpf: Add show_fdinfo for kprobe_multi
  2025-06-16 13:02 [PATCH bpf-next v3 1/2] bpf: Add show_fdinfo for uprobe_multi Tao Chen
@ 2025-06-16 13:02 ` Tao Chen
  2025-06-19  1:46   ` Alexei Starovoitov
  0 siblings, 1 reply; 4+ messages in thread
From: Tao Chen @ 2025-06-16 13:02 UTC (permalink / raw)
  To: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, jolsa, mattbobrowski,
	rostedt, mhiramat, mathieu.desnoyers
  Cc: bpf, linux-kernel, linux-trace-kernel, Tao Chen

Show kprobe_multi link info with fdinfo, the info as follows:

link_type:	kprobe_multi
link_id:	1
prog_tag:	a15b7646cb7f3322
prog_id:	21
type:	kprobe_multi
kprobe_cnt:	8
missed:	0
cookie           func
1                bpf_fentry_test1
7                bpf_fentry_test2
2                bpf_fentry_test3
3                bpf_fentry_test4
4                bpf_fentry_test5
5                bpf_fentry_test6
6                bpf_fentry_test7
8                bpf_fentry_test8

Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
 kernel/trace/bpf_trace.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 2d422f897ac..fcf19e233b5 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2623,10 +2623,42 @@ static int bpf_kprobe_multi_link_fill_link_info(const struct bpf_link *link,
 	return err;
 }
 
+#ifdef CONFIG_PROC_FS
+static void bpf_kprobe_multi_show_fdinfo(const struct bpf_link *link,
+					 struct seq_file *seq)
+{
+	struct bpf_kprobe_multi_link *kmulti_link;
+	char sym[KSYM_NAME_LEN];
+
+	kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link);
+
+	seq_printf(seq,
+		   "type:\t%s\n"
+		   "kprobe_cnt:\t%u\n"
+		   "missed:\t%lu\n",
+		   kmulti_link->flags == BPF_F_KPROBE_MULTI_RETURN ? "kretprobe_multi" :
+					 "kprobe_multi",
+		   kmulti_link->cnt,
+		   kmulti_link->fp.nmissed);
+
+	seq_printf(seq, "%-16s %-16s\n", "cookie", "func");
+	for (int i = 0; i < kmulti_link->cnt; i++) {
+		sprint_symbol_no_offset(sym, kmulti_link->addrs[i]);
+		seq_printf(seq,
+			   "%-16llu %-16s\n",
+			   kmulti_link->cookies[i],
+			   sym);
+	}
+}
+#endif
+
 static const struct bpf_link_ops bpf_kprobe_multi_link_lops = {
 	.release = bpf_kprobe_multi_link_release,
 	.dealloc_deferred = bpf_kprobe_multi_link_dealloc,
 	.fill_link_info = bpf_kprobe_multi_link_fill_link_info,
+#ifdef CONFIG_PROC_FS
+	.show_fdinfo = bpf_kprobe_multi_show_fdinfo,
+#endif
 };
 
 static void bpf_kprobe_multi_cookie_swap(void *a, void *b, int size, const void *priv)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next v3 2/2] bpf: Add show_fdinfo for kprobe_multi
  2025-06-16 13:02 ` [PATCH bpf-next v3 2/2] bpf: Add show_fdinfo for kprobe_multi Tao Chen
@ 2025-06-19  1:46   ` Alexei Starovoitov
  2025-06-19  3:08     ` Tao Chen
  0 siblings, 1 reply; 4+ messages in thread
From: Alexei Starovoitov @ 2025-06-19  1:46 UTC (permalink / raw)
  To: Tao Chen
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Matt Bobrowski,
	Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, bpf, LKML,
	linux-trace-kernel

On Mon, Jun 16, 2025 at 6:03 AM Tao Chen <chen.dylane@linux.dev> wrote:
>
> Show kprobe_multi link info with fdinfo, the info as follows:
>
> link_type:      kprobe_multi
> link_id:        1
> prog_tag:       a15b7646cb7f3322
> prog_id:        21
> type:   kprobe_multi
> kprobe_cnt:     8
> missed: 0
> cookie           func
> 1                bpf_fentry_test1
> 7                bpf_fentry_test2
> 2                bpf_fentry_test3
> 3                bpf_fentry_test4
> 4                bpf_fentry_test5
> 5                bpf_fentry_test6
> 6                bpf_fentry_test7
> 8                bpf_fentry_test8
>
> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
> ---
>  kernel/trace/bpf_trace.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 2d422f897ac..fcf19e233b5 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -2623,10 +2623,42 @@ static int bpf_kprobe_multi_link_fill_link_info(const struct bpf_link *link,
>         return err;
>  }
>
> +#ifdef CONFIG_PROC_FS
> +static void bpf_kprobe_multi_show_fdinfo(const struct bpf_link *link,
> +                                        struct seq_file *seq)
> +{
> +       struct bpf_kprobe_multi_link *kmulti_link;
> +       char sym[KSYM_NAME_LEN];
> +
> +       kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link);
> +
> +       seq_printf(seq,
> +                  "type:\t%s\n"
> +                  "kprobe_cnt:\t%u\n"
> +                  "missed:\t%lu\n",
> +                  kmulti_link->flags == BPF_F_KPROBE_MULTI_RETURN ? "kretprobe_multi" :
> +                                        "kprobe_multi",
> +                  kmulti_link->cnt,
> +                  kmulti_link->fp.nmissed);
> +
> +       seq_printf(seq, "%-16s %-16s\n", "cookie", "func");
> +       for (int i = 0; i < kmulti_link->cnt; i++) {
> +               sprint_symbol_no_offset(sym, kmulti_link->addrs[i]);
> +               seq_printf(seq,
> +                          "%-16llu %-16s\n",
> +                          kmulti_link->cookies[i],
> +                          sym);

Why call sprint_symbol_no_offset() directly ?
%pB is fine.
+off doesn't disclose anything.

pw-bot: cr

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next v3 2/2] bpf: Add show_fdinfo for kprobe_multi
  2025-06-19  1:46   ` Alexei Starovoitov
@ 2025-06-19  3:08     ` Tao Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Tao Chen @ 2025-06-19  3:08 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Matt Bobrowski,
	Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, bpf, LKML,
	linux-trace-kernel

在 2025/6/19 09:46, Alexei Starovoitov 写道:
> On Mon, Jun 16, 2025 at 6:03 AM Tao Chen <chen.dylane@linux.dev> wrote:
>>
>> Show kprobe_multi link info with fdinfo, the info as follows:
>>
>> link_type:      kprobe_multi
>> link_id:        1
>> prog_tag:       a15b7646cb7f3322
>> prog_id:        21
>> type:   kprobe_multi
>> kprobe_cnt:     8
>> missed: 0
>> cookie           func
>> 1                bpf_fentry_test1
>> 7                bpf_fentry_test2
>> 2                bpf_fentry_test3
>> 3                bpf_fentry_test4
>> 4                bpf_fentry_test5
>> 5                bpf_fentry_test6
>> 6                bpf_fentry_test7
>> 8                bpf_fentry_test8
>>
>> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
>> ---
>>   kernel/trace/bpf_trace.c | 32 ++++++++++++++++++++++++++++++++
>>   1 file changed, 32 insertions(+)
>>
>> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
>> index 2d422f897ac..fcf19e233b5 100644
>> --- a/kernel/trace/bpf_trace.c
>> +++ b/kernel/trace/bpf_trace.c
>> @@ -2623,10 +2623,42 @@ static int bpf_kprobe_multi_link_fill_link_info(const struct bpf_link *link,
>>          return err;
>>   }
>>
>> +#ifdef CONFIG_PROC_FS
>> +static void bpf_kprobe_multi_show_fdinfo(const struct bpf_link *link,
>> +                                        struct seq_file *seq)
>> +{
>> +       struct bpf_kprobe_multi_link *kmulti_link;
>> +       char sym[KSYM_NAME_LEN];
>> +
>> +       kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link);
>> +
>> +       seq_printf(seq,
>> +                  "type:\t%s\n"
>> +                  "kprobe_cnt:\t%u\n"
>> +                  "missed:\t%lu\n",
>> +                  kmulti_link->flags == BPF_F_KPROBE_MULTI_RETURN ? "kretprobe_multi" :
>> +                                        "kprobe_multi",
>> +                  kmulti_link->cnt,
>> +                  kmulti_link->fp.nmissed);
>> +
>> +       seq_printf(seq, "%-16s %-16s\n", "cookie", "func");
>> +       for (int i = 0; i < kmulti_link->cnt; i++) {
>> +               sprint_symbol_no_offset(sym, kmulti_link->addrs[i]);
>> +               seq_printf(seq,
>> +                          "%-16llu %-16s\n",
>> +                          kmulti_link->cookies[i],
>> +                          sym);
> 
> Why call sprint_symbol_no_offset() directly ?
> %pB is fine.
> +off doesn't disclose anything.
> 
> pw-bot: cr

My problem, sorry for that, i had some issues with using printk to show 
func name directly before. Actually, i used it incorrectly. How about 
%pS, it looks more accurate. Thanks!

%pB format
cookie           func
8                __pfx_bpf_fentry_test1+0x10/0x10
2                __pfx_bpf_fentry_test2+0x10/0x10
7                __pfx_bpf_fentry_test3+0x10/0x10

%pS format
cookie           func
8                bpf_fentry_test1+0x0/0x20
2                bpf_fentry_test2+0x0/0x20
7                bpf_fentry_test3+0x0/0x20

-- 
Best Regards
Tao Chen

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-19  3:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-16 13:02 [PATCH bpf-next v3 1/2] bpf: Add show_fdinfo for uprobe_multi Tao Chen
2025-06-16 13:02 ` [PATCH bpf-next v3 2/2] bpf: Add show_fdinfo for kprobe_multi Tao Chen
2025-06-19  1:46   ` Alexei Starovoitov
2025-06-19  3:08     ` Tao Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).