* [PATCH bpf-next v6 1/3] bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo
@ 2025-06-27 8:22 Tao Chen
2025-06-27 8:22 ` [PATCH bpf-next v6 2/3] bpf: Add show_fdinfo for uprobe_multi Tao Chen
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Tao Chen @ 2025-06-27 8:22 UTC (permalink / raw)
To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, kpsingh, sdf, haoluo, jolsa, mattbobrowski,
rostedt, mhiramat, mathieu.desnoyers
Cc: bpf, linux-kernel, linux-trace-kernel, Tao Chen
Alexei suggested, 'link_type' can be more precise and differentiate
for human in fdinfo. In fact BPF_LINK_TYPE_KPROBE_MULTI includes
kretprobe_multi type, the same as BPF_LINK_TYPE_UPROBE_MULTI, so we
can show it more concretely.
link_type: kprobe_multi
link_id: 1
prog_tag: d2b307e915f0dd37
...
link_type: kretprobe_multi
link_id: 2
prog_tag: ab9ea0545870781d
...
link_type: uprobe_multi
link_id: 9
prog_tag: e729f789e34a8eca
...
link_type: uretprobe_multi
link_id: 10
prog_tag: 7db356c03e61a4d4
As Andrii suggested attach_type can be recorded in bpf_link, there is
still a 6 byte hole in bpf_link, we can fill the hole with attach_type
soon.
Co-authored-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
include/linux/bpf.h | 1 +
kernel/bpf/syscall.c | 9 ++++++++-
kernel/trace/bpf_trace.c | 10 ++++------
3 files changed, 13 insertions(+), 7 deletions(-)
Change list:
v5 -> v6:
- Move flags into bpf_link to get retprobe info
directly.(Alexei, Jiri)
v5:
https://lore.kernel.org/bpf/20250623134342.227347-1-chen.dylane@linux.dev
v4 -> v5:
- Add patch1 to show precise link_type for
{uprobe,kprobe}_multi.(Alexei)
- patch2,3 just remove type field, which will be showed in
link_type
v4:
https://lore.kernel.org/bpf/20250619034257.70520-1-chen.dylane@linux.dev
v3 -> v4:
- use %pS to print func info.(Alexei)
v3:
https://lore.kernel.org/bpf/20250616130233.451439-1-chen.dylane@linux.dev
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/include/linux/bpf.h b/include/linux/bpf.h
index 5b25d278409..3d8fecc9b17 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1702,6 +1702,7 @@ struct bpf_link {
* link's semantics is determined by target attach hook
*/
bool sleepable;
+ u32 flags :8;
/* rcu is used before freeing, work can be used to schedule that
* RCU-based freeing before that, so they never overlap
*/
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 51ba1a7aa43..e6eea594f1c 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3228,7 +3228,14 @@ static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp)
char prog_tag[sizeof(prog->tag) * 2 + 1] = { };
if (type < ARRAY_SIZE(bpf_link_type_strs) && bpf_link_type_strs[type]) {
- seq_printf(m, "link_type:\t%s\n", bpf_link_type_strs[type]);
+ if (link->type == BPF_LINK_TYPE_KPROBE_MULTI)
+ seq_printf(m, "link_type:\t%s\n", link->flags == BPF_F_KPROBE_MULTI_RETURN ?
+ "kretprobe_multi" : "kprobe_multi");
+ else if (link->type == BPF_LINK_TYPE_UPROBE_MULTI)
+ seq_printf(m, "link_type:\t%s\n", link->flags == BPF_F_UPROBE_MULTI_RETURN ?
+ "uretprobe_multi" : "uprobe_multi");
+ else
+ seq_printf(m, "link_type:\t%s\n", bpf_link_type_strs[type]);
} else {
WARN_ONCE(1, "missing BPF_LINK_TYPE(...) for link type %u\n", type);
seq_printf(m, "link_type:\t<%u>\n", type);
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 24b94870b50..85f07f662fe 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2469,7 +2469,6 @@ struct bpf_kprobe_multi_link {
u32 cnt;
u32 mods_cnt;
struct module **mods;
- u32 flags;
};
struct bpf_kprobe_multi_run_ctx {
@@ -2589,7 +2588,7 @@ static int bpf_kprobe_multi_link_fill_link_info(const struct bpf_link *link,
kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link);
info->kprobe_multi.count = kmulti_link->cnt;
- info->kprobe_multi.flags = kmulti_link->flags;
+ info->kprobe_multi.flags = kmulti_link->link.flags;
info->kprobe_multi.missed = kmulti_link->fp.nmissed;
if (!uaddrs)
@@ -2979,7 +2978,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
link->addrs = addrs;
link->cookies = cookies;
link->cnt = cnt;
- link->flags = flags;
+ link->link.flags = flags;
if (cookies) {
/*
@@ -3048,7 +3047,6 @@ struct bpf_uprobe_multi_link {
struct path path;
struct bpf_link link;
u32 cnt;
- u32 flags;
struct bpf_uprobe *uprobes;
struct task_struct *task;
};
@@ -3112,7 +3110,7 @@ static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link,
umulti_link = container_of(link, struct bpf_uprobe_multi_link, link);
info->uprobe_multi.count = umulti_link->cnt;
- info->uprobe_multi.flags = umulti_link->flags;
+ info->uprobe_multi.flags = umulti_link->link.flags;
info->uprobe_multi.pid = umulti_link->task ?
task_pid_nr_ns(umulti_link->task, task_active_pid_ns(current)) : 0;
@@ -3372,7 +3370,7 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
link->uprobes = uprobes;
link->path = path;
link->task = task;
- link->flags = flags;
+ link->link.flags = flags;
bpf_link_init(&link->link, BPF_LINK_TYPE_UPROBE_MULTI,
&bpf_uprobe_multi_link_lops, prog);
--
2.48.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH bpf-next v6 2/3] bpf: Add show_fdinfo for uprobe_multi
2025-06-27 8:22 [PATCH bpf-next v6 1/3] bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo Tao Chen
@ 2025-06-27 8:22 ` Tao Chen
2025-06-27 8:22 ` [PATCH bpf-next v6 3/3] bpf: Add show_fdinfo for kprobe_multi Tao Chen
2025-07-01 20:39 ` [PATCH bpf-next v6 1/3] bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo Alexei Starovoitov
2 siblings, 0 replies; 7+ messages in thread
From: Tao Chen @ 2025-06-27 8:22 UTC (permalink / raw)
To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, 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: 10
prog_tag: 7db356c03e61a4d4
prog_id: 42
uprobe_cnt: 3
pid: 0
path: /home/dylane/bpf/tools/testing/selftests/bpf/test_progs
offset ref_ctr_offset cookie
0xa69f13 0x0 2
0xa69f1e 0x0 3
0xa69f29 0x0 1
Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
kernel/trace/bpf_trace.c | 44 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 85f07f662fe..1c75f9c6c66 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3155,10 +3155,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, "%-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] 7+ messages in thread
* [PATCH bpf-next v6 3/3] bpf: Add show_fdinfo for kprobe_multi
2025-06-27 8:22 [PATCH bpf-next v6 1/3] bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo Tao Chen
2025-06-27 8:22 ` [PATCH bpf-next v6 2/3] bpf: Add show_fdinfo for uprobe_multi Tao Chen
@ 2025-06-27 8:22 ` Tao Chen
2025-07-01 20:37 ` Andrii Nakryiko
2025-07-01 20:39 ` [PATCH bpf-next v6 1/3] bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo Alexei Starovoitov
2 siblings, 1 reply; 7+ messages in thread
From: Tao Chen @ 2025-06-27 8:22 UTC (permalink / raw)
To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, 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: 33be53a4fd673e1d
prog_id: 21
kprobe_cnt: 8
missed: 0
cookie func
1 bpf_fentry_test1+0x0/0x20
7 bpf_fentry_test2+0x0/0x20
2 bpf_fentry_test3+0x0/0x20
3 bpf_fentry_test4+0x0/0x20
4 bpf_fentry_test5+0x0/0x20
5 bpf_fentry_test6+0x0/0x20
6 bpf_fentry_test7+0x0/0x20
8 bpf_fentry_test8+0x0/0x10
Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
kernel/trace/bpf_trace.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 1c75f9c6c66..e8f070504c4 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2622,10 +2622,37 @@ 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;
+
+ kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link);
+
+ seq_printf(seq,
+ "kprobe_cnt:\t%u\n"
+ "missed:\t%lu\n",
+ kmulti_link->cnt,
+ kmulti_link->fp.nmissed);
+
+ seq_printf(seq, "%-16s %-16s\n", "cookie", "func");
+ for (int i = 0; i < kmulti_link->cnt; i++) {
+ seq_printf(seq,
+ "%-16llu %-16pS\n",
+ kmulti_link->cookies[i],
+ (void *)kmulti_link->addrs[i]);
+ }
+}
+#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] 7+ messages in thread
* Re: [PATCH bpf-next v6 3/3] bpf: Add show_fdinfo for kprobe_multi
2025-06-27 8:22 ` [PATCH bpf-next v6 3/3] bpf: Add show_fdinfo for kprobe_multi Tao Chen
@ 2025-07-01 20:37 ` Andrii Nakryiko
2025-07-02 2:48 ` Tao Chen
0 siblings, 1 reply; 7+ messages in thread
From: Andrii Nakryiko @ 2025-07-01 20:37 UTC (permalink / raw)
To: Tao Chen
Cc: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, kpsingh, sdf, haoluo, jolsa, mattbobrowski,
rostedt, mhiramat, mathieu.desnoyers, bpf, linux-kernel,
linux-trace-kernel
On Fri, Jun 27, 2025 at 1:23 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: 33be53a4fd673e1d
> prog_id: 21
> kprobe_cnt: 8
> missed: 0
> cookie func
> 1 bpf_fentry_test1+0x0/0x20
> 7 bpf_fentry_test2+0x0/0x20
> 2 bpf_fentry_test3+0x0/0x20
> 3 bpf_fentry_test4+0x0/0x20
> 4 bpf_fentry_test5+0x0/0x20
> 5 bpf_fentry_test6+0x0/0x20
> 6 bpf_fentry_test7+0x0/0x20
> 8 bpf_fentry_test8+0x0/0x10
two nits:
1) order of cookie. For uprobes you have cookie at the end, here in
the front. Given variable-sized func name, I'd move cookie to the
front for uprobes for consistency.
2) field sizing for cookie (16) is a) not sufficient for maximum
possible u64 (20 digits) and b) very wasteful in common case of small
numbers. So use tab instead of fixed-sized column? And why 16
character sizing for the func column? Just to have more spaces
emitted?
Other than that the series looks good to me.
pw-bot: cr
>
> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
> ---
> kernel/trace/bpf_trace.c | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 1c75f9c6c66..e8f070504c4 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -2622,10 +2622,37 @@ 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;
> +
> + kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link);
> +
> + seq_printf(seq,
> + "kprobe_cnt:\t%u\n"
> + "missed:\t%lu\n",
> + kmulti_link->cnt,
> + kmulti_link->fp.nmissed);
> +
> + seq_printf(seq, "%-16s %-16s\n", "cookie", "func");
> + for (int i = 0; i < kmulti_link->cnt; i++) {
> + seq_printf(seq,
> + "%-16llu %-16pS\n",
> + kmulti_link->cookies[i],
> + (void *)kmulti_link->addrs[i]);
> + }
> +}
> +#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 [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next v6 1/3] bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo
2025-06-27 8:22 [PATCH bpf-next v6 1/3] bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo Tao Chen
2025-06-27 8:22 ` [PATCH bpf-next v6 2/3] bpf: Add show_fdinfo for uprobe_multi Tao Chen
2025-06-27 8:22 ` [PATCH bpf-next v6 3/3] bpf: Add show_fdinfo for kprobe_multi Tao Chen
@ 2025-07-01 20:39 ` Alexei Starovoitov
2025-07-02 2:14 ` Tao Chen
2 siblings, 1 reply; 7+ messages in thread
From: Alexei Starovoitov @ 2025-07-01 20:39 UTC (permalink / raw)
To: Tao Chen
Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
Andrii Nakryiko, Martin KaFai Lau, Eduard, Song Liu,
Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Matt Bobrowski, Steven Rostedt, Masami Hiramatsu,
Mathieu Desnoyers, bpf, LKML, linux-trace-kernel
On Fri, Jun 27, 2025 at 1:23 AM Tao Chen <chen.dylane@linux.dev> wrote:
>
> Alexei suggested, 'link_type' can be more precise and differentiate
> for human in fdinfo. In fact BPF_LINK_TYPE_KPROBE_MULTI includes
> kretprobe_multi type, the same as BPF_LINK_TYPE_UPROBE_MULTI, so we
> can show it more concretely.
>
> link_type: kprobe_multi
> link_id: 1
> prog_tag: d2b307e915f0dd37
> ...
> link_type: kretprobe_multi
> link_id: 2
> prog_tag: ab9ea0545870781d
> ...
> link_type: uprobe_multi
> link_id: 9
> prog_tag: e729f789e34a8eca
> ...
> link_type: uretprobe_multi
> link_id: 10
> prog_tag: 7db356c03e61a4d4
>
> As Andrii suggested attach_type can be recorded in bpf_link, there is
> still a 6 byte hole in bpf_link, we can fill the hole with attach_type
> soon.
>
> Co-authored-by: Jiri Olsa <jolsa@kernel.org>
> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
> ---
> include/linux/bpf.h | 1 +
> kernel/bpf/syscall.c | 9 ++++++++-
> kernel/trace/bpf_trace.c | 10 ++++------
> 3 files changed, 13 insertions(+), 7 deletions(-)
>
> Change list:
> v5 -> v6:
> - Move flags into bpf_link to get retprobe info
> directly.(Alexei, Jiri)
> v5:
> https://lore.kernel.org/bpf/20250623134342.227347-1-chen.dylane@linux.dev
>
> v4 -> v5:
> - Add patch1 to show precise link_type for
> {uprobe,kprobe}_multi.(Alexei)
> - patch2,3 just remove type field, which will be showed in
> link_type
> v4:
> https://lore.kernel.org/bpf/20250619034257.70520-1-chen.dylane@linux.dev
>
> v3 -> v4:
> - use %pS to print func info.(Alexei)
> v3:
> https://lore.kernel.org/bpf/20250616130233.451439-1-chen.dylane@linux.dev
>
> 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/include/linux/bpf.h b/include/linux/bpf.h
> index 5b25d278409..3d8fecc9b17 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1702,6 +1702,7 @@ struct bpf_link {
> * link's semantics is determined by target attach hook
> */
> bool sleepable;
> + u32 flags :8;
There is a 7-byte hole here.
Let's use 'u32 flags' right now and optimize later if necessary.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next v6 1/3] bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo
2025-07-01 20:39 ` [PATCH bpf-next v6 1/3] bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo Alexei Starovoitov
@ 2025-07-02 2:14 ` Tao Chen
0 siblings, 0 replies; 7+ messages in thread
From: Tao Chen @ 2025-07-02 2:14 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
Andrii Nakryiko, Martin KaFai Lau, Eduard, Song Liu,
Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Matt Bobrowski, Steven Rostedt, Masami Hiramatsu,
Mathieu Desnoyers, bpf, LKML, linux-trace-kernel
在 2025/7/2 04:39, Alexei Starovoitov 写道:
> On Fri, Jun 27, 2025 at 1:23 AM Tao Chen <chen.dylane@linux.dev> wrote:
>>
>> Alexei suggested, 'link_type' can be more precise and differentiate
>> for human in fdinfo. In fact BPF_LINK_TYPE_KPROBE_MULTI includes
>> kretprobe_multi type, the same as BPF_LINK_TYPE_UPROBE_MULTI, so we
>> can show it more concretely.
>>
>> link_type: kprobe_multi
>> link_id: 1
>> prog_tag: d2b307e915f0dd37
>> ...
>> link_type: kretprobe_multi
>> link_id: 2
>> prog_tag: ab9ea0545870781d
>> ...
>> link_type: uprobe_multi
>> link_id: 9
>> prog_tag: e729f789e34a8eca
>> ...
>> link_type: uretprobe_multi
>> link_id: 10
>> prog_tag: 7db356c03e61a4d4
>>
>> As Andrii suggested attach_type can be recorded in bpf_link, there is
>> still a 6 byte hole in bpf_link, we can fill the hole with attach_type
>> soon.
>>
>> Co-authored-by: Jiri Olsa <jolsa@kernel.org>
>> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
>> ---
>> include/linux/bpf.h | 1 +
>> kernel/bpf/syscall.c | 9 ++++++++-
>> kernel/trace/bpf_trace.c | 10 ++++------
>> 3 files changed, 13 insertions(+), 7 deletions(-)
>>
>> Change list:
>> v5 -> v6:
>> - Move flags into bpf_link to get retprobe info
>> directly.(Alexei, Jiri)
>> v5:
>> https://lore.kernel.org/bpf/20250623134342.227347-1-chen.dylane@linux.dev
>>
>> v4 -> v5:
>> - Add patch1 to show precise link_type for
>> {uprobe,kprobe}_multi.(Alexei)
>> - patch2,3 just remove type field, which will be showed in
>> link_type
>> v4:
>> https://lore.kernel.org/bpf/20250619034257.70520-1-chen.dylane@linux.dev
>>
>> v3 -> v4:
>> - use %pS to print func info.(Alexei)
>> v3:
>> https://lore.kernel.org/bpf/20250616130233.451439-1-chen.dylane@linux.dev
>>
>> 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/include/linux/bpf.h b/include/linux/bpf.h
>> index 5b25d278409..3d8fecc9b17 100644
>> --- a/include/linux/bpf.h
>> +++ b/include/linux/bpf.h
>> @@ -1702,6 +1702,7 @@ struct bpf_link {
>> * link's semantics is determined by target attach hook
>> */
>> bool sleepable;
>> + u32 flags :8;
>
> There is a 7-byte hole here.
> Let's use 'u32 flags' right now and optimize later if necessary.
Ok, will change it in v7.
--
Best Regards
Tao Chen
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next v6 3/3] bpf: Add show_fdinfo for kprobe_multi
2025-07-01 20:37 ` Andrii Nakryiko
@ 2025-07-02 2:48 ` Tao Chen
0 siblings, 0 replies; 7+ messages in thread
From: Tao Chen @ 2025-07-02 2:48 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, kpsingh, sdf, haoluo, jolsa, mattbobrowski,
rostedt, mhiramat, mathieu.desnoyers, bpf, linux-kernel,
linux-trace-kernel
在 2025/7/2 04:37, Andrii Nakryiko 写道:
> On Fri, Jun 27, 2025 at 1:23 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: 33be53a4fd673e1d
>> prog_id: 21
>> kprobe_cnt: 8
>> missed: 0
>> cookie func
>> 1 bpf_fentry_test1+0x0/0x20
>> 7 bpf_fentry_test2+0x0/0x20
>> 2 bpf_fentry_test3+0x0/0x20
>> 3 bpf_fentry_test4+0x0/0x20
>> 4 bpf_fentry_test5+0x0/0x20
>> 5 bpf_fentry_test6+0x0/0x20
>> 6 bpf_fentry_test7+0x0/0x20
>> 8 bpf_fentry_test8+0x0/0x10
>
> two nits:
>
> 1) order of cookie. For uprobes you have cookie at the end, here in
> the front. Given variable-sized func name, I'd move cookie to the
> front for uprobes for consistency.
>
Ok, will change it in v7.
> 2) field sizing for cookie (16) is a) not sufficient for maximum
> possible u64 (20 digits) and b) very wasteful in common case of small
> numbers. So use tab instead of fixed-sized column? And why 16
> character sizing for the func column? Just to have more spaces
> emitted?
>
I just referred to the implementation in bpftool/link.c, i will use tab
format in v7. "16 character sizing for the func" just keeps consistency
with cookie, " %s" for func name maybe better.
>
> Other than that the series looks good to me.
>
> pw-bot: cr
>
>
>>
>> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
>> ---
>> kernel/trace/bpf_trace.c | 27 +++++++++++++++++++++++++++
>> 1 file changed, 27 insertions(+)
>>
>> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
>> index 1c75f9c6c66..e8f070504c4 100644
>> --- a/kernel/trace/bpf_trace.c
>> +++ b/kernel/trace/bpf_trace.c
>> @@ -2622,10 +2622,37 @@ 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;
>> +
>> + kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link);
>> +
>> + seq_printf(seq,
>> + "kprobe_cnt:\t%u\n"
>> + "missed:\t%lu\n",
>> + kmulti_link->cnt,
>> + kmulti_link->fp.nmissed);
>> +
>> + seq_printf(seq, "%-16s %-16s\n", "cookie", "func");
>> + for (int i = 0; i < kmulti_link->cnt; i++) {
>> + seq_printf(seq,
>> + "%-16llu %-16pS\n",
>> + kmulti_link->cookies[i],
>> + (void *)kmulti_link->addrs[i]);
>> + }
>> +}
>> +#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
>>
--
Best Regards
Tao Chen
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-07-02 2:49 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-27 8:22 [PATCH bpf-next v6 1/3] bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo Tao Chen
2025-06-27 8:22 ` [PATCH bpf-next v6 2/3] bpf: Add show_fdinfo for uprobe_multi Tao Chen
2025-06-27 8:22 ` [PATCH bpf-next v6 3/3] bpf: Add show_fdinfo for kprobe_multi Tao Chen
2025-07-01 20:37 ` Andrii Nakryiko
2025-07-02 2:48 ` Tao Chen
2025-07-01 20:39 ` [PATCH bpf-next v6 1/3] bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo Alexei Starovoitov
2025-07-02 2:14 ` 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).