Skip to contentSkip to conversation

bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo

PATCH Superseded Tao Chen 4 participants 12 messages Jun 23, 2025 – Jun 24, 2025

Subsystems (5)
BPF Tracing BPF core BPF tracing +1 more subsystems

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Tao Chen

author
#0 lore raw

PATCH v5 1/3 bpf: Show precise link_type for {uprobe,kprobe}_multi fdinfo

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

---
 include/linux/trace_events.h | 10 ++++++++++
 kernel/bpf/syscall.c         |  9 ++++++++-
 kernel/trace/bpf_trace.c     | 28 ++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)

Change list:
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/[email protected]

v3 -> v4:
- use %pS to print func info.(Alexei)
v3:
https://lore.kernel.org/bpf/[email protected]

v2 -> v3:
- show info in one line for multi events.(Jiri)
v2:
https://lore.kernel.org/bpf/[email protected]

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/[email protected]

include/linux/trace_events.h +10 -0
index fa9cf4292df..951c91babbc 100644
@@ -780,6 +780,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
 			    unsigned long *missed);
 int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
 int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
+void bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
+void bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
 #else
 static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
 {
@@ -832,6 +834,14 @@ bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
 {
 	return -EOPNOTSUPP;
 }
+static inline void
+bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
+static inline void
+bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
 #endif
 
 enum {
kernel/bpf/syscall.c +8 -1
index 51ba1a7aa43..43b821b37bc 100644
@@ -3226,9 +3226,16 @@ static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp)
 	const struct bpf_prog *prog = link->prog;
 	enum bpf_link_type type = link->type;
 	char prog_tag[sizeof(prog->tag) * 2 + 1] = { };
+	char link_type[64] = {};
 
 	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)
+			bpf_kprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+		else if (link->type == BPF_LINK_TYPE_UPROBE_MULTI)
+			bpf_uprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+		else
+			strscpy(link_type, bpf_link_type_strs[type], sizeof(link_type));
+		seq_printf(m, "link_type:\t%s\n", link_type);
 	} else {
 		WARN_ONCE(1, "missing BPF_LINK_TYPE(...) for link type %u\n", type);
 		seq_printf(m, "link_type:\t<%u>\n", type);
kernel/trace/bpf_trace.c +28 -0
index 24b94870b50..8ecb1a9f85d 100644
@@ -3016,7 +3016,21 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	kvfree(cookies);
 	return err;
 }
+
+void bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type,
+				     int len)
+{
+	struct bpf_kprobe_multi_link *kmulti_link;
+
+	kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link);
+	strscpy(link_type, kmulti_link->flags == BPF_F_KPROBE_MULTI_RETURN ?
+				"kretprobe_multi" : "kprobe_multi", len);
+}
 #else /* !CONFIG_FPROBE */
+void bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type,
+				     int len)
+{
+}
 int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
 {
 	return -EOPNOTSUPP;
@@ -3407,7 +3421,21 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	path_put(&path);
 	return err;
 }
+
+void bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type,
+				     int len)
+{
+	struct bpf_uprobe_multi_link *umulti_link;
+
+	umulti_link = container_of(link, struct bpf_uprobe_multi_link, link);
+	strscpy(link_type, umulti_link->flags == BPF_F_UPROBE_MULTI_RETURN ?
+				"uretprobe_multi" : "uprobe_multi", len);
+}
 #else /* !CONFIG_UPROBES */
+void bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type,
+				     int len)
+{
+}
 int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
 {
 	return -EOPNOTSUPP;
Signature · 1 line
2.48.1
author
#1 lore raw

PATCH v5 2/3 bpf: Add show_fdinfo for uprobe_multi

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
---
 kernel/trace/bpf_trace.c | 44 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
kernel/trace/bpf_trace.c +44 -0
index 8ecb1a9f85d..90209dda819 100644
@@ -3171,10 +3171,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;
+
+	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,
+		   "uprobe_cnt:\t%u\n"
+		   "pid:\t%u\n"
+		   "path:\t%s\n",
+		   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,
Signature · 1 line
2.48.1
#2 lore raw

Re: [PATCH bpf-next v5 2/3] bpf: Add show_fdinfo for uprobe_multi

Quoted 44 lines · 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
---
 kernel/trace/bpf_trace.c | 44 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
kernel/trace/bpf_trace.c +16 -0
index 8ecb1a9f85d..90209dda819 100644
@@ -3171,10 +3171,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;
+
+       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);

kernel/trace/bpf_trace.c static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link, · line 3199

Quoted 10 lines
kernel/trace/bpf_trace.c +10 -0
+               return;
+       }
+
+       seq_printf(seq,
+                  "uprobe_cnt:\t%u\n"
+                  "pid:\t%u\n"
+                  "path:\t%s\n",
+                  umulti_link->cnt,
+                  umulti_link->task ? task_pid_nr_ns(umulti_link->task,
+                          task_active_pid_ns(current)) : 0,

nit: either keep stuff like this on single line, or if it's too long or awkward, add a local variable. Formatting it like this is very hard to follow and looks pretty ugly...

Quoted 28 lines
kernel/trace/bpf_trace.c +18 -1
+                  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

author
#3 lore raw

Re: [PATCH bpf-next v5 2/3] bpf: Add show_fdinfo for uprobe_multi

Quoted 51 lines · Andrii Nakryiko
Quoted 50 lines · 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
---
  kernel/trace/bpf_trace.c | 44 ++++++++++++++++++++++++++++++++++++++++
  1 file changed, 44 insertions(+)
kernel/trace/bpf_trace.c +22 -0
index 8ecb1a9f85d..90209dda819 100644
@@ -3171,10 +3171,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;
+
+       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,
+                  "uprobe_cnt:\t%u\n"
+                  "pid:\t%u\n"
Quoted 9 lines

kernel/trace/bpf_trace.c static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link, · line 3199

Quoted 4 lines
kernel/trace/bpf_trace.c +4 -0
+                  "path:\t%s\n",
+                  umulti_link->cnt,
+                  umulti_link->task ? task_pid_nr_ns(umulti_link->task,
+                          task_active_pid_ns(current)) : 0,

nit: either keep stuff like this on single line, or if it's too long or awkward, add a local variable. Formatting it like this is very hard to follow and looks pretty ugly...

will fix it in v6, thanks.

Quoted 28 lines
Quoted 28 lines
kernel/trace/bpf_trace.c +18 -1
+                  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

Signature · 2 lines
Best Regards
Tao Chen
author
#4 lore raw

PATCH v5 3/3 bpf: Add show_fdinfo for kprobe_multi

In reply to 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
---
 kernel/trace/bpf_trace.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
kernel/trace/bpf_trace.c +27 -0
index 90209dda819..957e5b319ef 100644
@@ -2623,10 +2623,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)
Signature · 1 line
2.48.1
#5 lore raw
In reply to Tao Chen
Quoted 91 lines · 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
---
 include/linux/trace_events.h | 10 ++++++++++
 kernel/bpf/syscall.c         |  9 ++++++++-
 kernel/trace/bpf_trace.c     | 28 ++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)

Change list:
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/[email protected]

v3 -> v4:
- use %pS to print func info.(Alexei)
v3:
https://lore.kernel.org/bpf/[email protected]

v2 -> v3:
- show info in one line for multi events.(Jiri)
v2:
https://lore.kernel.org/bpf/[email protected]

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/[email protected]

include/linux/trace_events.h +10 -0
index fa9cf4292df..951c91babbc 100644
@@ -780,6 +780,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
                            unsigned long *missed);
 int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
 int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
+void bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
+void bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
 #else
 static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
 {
@@ -832,6 +834,14 @@ bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
 {
        return -EOPNOTSUPP;
 }
+static inline void
+bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
+static inline void
+bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
 #endif
 
 enum {
kernel/bpf/syscall.c +1 -0
index 51ba1a7aa43..43b821b37bc 100644
@@ -3226,9 +3226,16 @@ static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp)
        const struct bpf_prog *prog = link->prog;
        enum bpf_link_type type = link->type;
        char prog_tag[sizeof(prog->tag) * 2 + 1] = { };
+       char link_type[64] = {};

kernel/bpf/syscall.c static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp) · line 3238

Quoted 10 lines
kernel/bpf/syscall.c +7 -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)
+                       bpf_kprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else if (link->type == BPF_LINK_TYPE_UPROBE_MULTI)
+                       bpf_uprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else
+                       strscpy(link_type, bpf_link_type_strs[type], sizeof(link_type));
+               seq_printf(m, "link_type:\t%s\n", link_type);

New callbacks just to print a string?
Let's find a different way.

How about moving 'flags' from bpf_[ku]probe_multi_link into bpf_link ? (There is a 7 byte hole there anyway)
and checking flags inline.

Jiri, Andrii,

better ideas?

#6 lore raw
Quoted 107 lines · Alexei Starovoitov
Quoted 91 lines · 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
---
 include/linux/trace_events.h | 10 ++++++++++
 kernel/bpf/syscall.c         |  9 ++++++++-
 kernel/trace/bpf_trace.c     | 28 ++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)

Change list:
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/[email protected]

v3 -> v4:
- use %pS to print func info.(Alexei)
v3:
https://lore.kernel.org/bpf/[email protected]

v2 -> v3:
- show info in one line for multi events.(Jiri)
v2:
https://lore.kernel.org/bpf/[email protected]

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/[email protected]

include/linux/trace_events.h +10 -0
index fa9cf4292df..951c91babbc 100644
@@ -780,6 +780,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
                            unsigned long *missed);
 int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
 int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
+void bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
+void bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
 #else
 static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
 {
@@ -832,6 +834,14 @@ bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
 {
        return -EOPNOTSUPP;
 }
+static inline void
+bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
+static inline void
+bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
 #endif
 
 enum {
kernel/bpf/syscall.c +1 -0
index 51ba1a7aa43..43b821b37bc 100644
@@ -3226,9 +3226,16 @@ static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp)
        const struct bpf_prog *prog = link->prog;
        enum bpf_link_type type = link->type;
        char prog_tag[sizeof(prog->tag) * 2 + 1] = { };
+       char link_type[64] = {};

kernel/bpf/syscall.c static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp) · line 3238

Quoted 10 lines
kernel/bpf/syscall.c +7 -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)
+                       bpf_kprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else if (link->type == BPF_LINK_TYPE_UPROBE_MULTI)
+                       bpf_uprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else
+                       strscpy(link_type, bpf_link_type_strs[type], sizeof(link_type));
+               seq_printf(m, "link_type:\t%s\n", link_type);

New callbacks just to print a string?
Let's find a different way.

Quoted 7 lines

How about moving 'flags' from bpf_[ku]probe_multi_link into bpf_link ? (There is a 7 byte hole there anyway)
and checking flags inline.

Jiri, Andrii,

better ideas?

We can just remember original attr->link_create.attach_type in bpf_link itself, and then have a small helper that will accept link type and attach type, and fill out link type representation based on those two. Internally we can do the special-casing of uprobe vs uretprobe and kprobe vs kretprobe transparently to all the other code. And use that here in show_fdinfo

#7 lore raw
Quoted 115 lines · Andrii Nakryiko
Quoted 113 lines · Alexei Starovoitov
Quoted 91 lines · 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
---
 include/linux/trace_events.h | 10 ++++++++++
 kernel/bpf/syscall.c         |  9 ++++++++-
 kernel/trace/bpf_trace.c     | 28 ++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)

Change list:
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/[email protected]

v3 -> v4:
- use %pS to print func info.(Alexei)
v3:
https://lore.kernel.org/bpf/[email protected]

v2 -> v3:
- show info in one line for multi events.(Jiri)
v2:
https://lore.kernel.org/bpf/[email protected]

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/[email protected]

include/linux/trace_events.h +10 -0
index fa9cf4292df..951c91babbc 100644
@@ -780,6 +780,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
                            unsigned long *missed);
 int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
 int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
+void bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
+void bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
 #else
 static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
 {
@@ -832,6 +834,14 @@ bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
 {
        return -EOPNOTSUPP;
 }
+static inline void
+bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
+static inline void
+bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
 #endif
 
 enum {
kernel/bpf/syscall.c +1 -0
index 51ba1a7aa43..43b821b37bc 100644
@@ -3226,9 +3226,16 @@ static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp)
        const struct bpf_prog *prog = link->prog;
        enum bpf_link_type type = link->type;
        char prog_tag[sizeof(prog->tag) * 2 + 1] = { };
+       char link_type[64] = {};

kernel/bpf/syscall.c static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp) · line 3238

Quoted 10 lines
kernel/bpf/syscall.c +7 -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)
+                       bpf_kprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else if (link->type == BPF_LINK_TYPE_UPROBE_MULTI)
+                       bpf_uprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else
+                       strscpy(link_type, bpf_link_type_strs[type], sizeof(link_type));
+               seq_printf(m, "link_type:\t%s\n", link_type);

New callbacks just to print a string?
Let's find a different way.

How about moving 'flags' from bpf_[ku]probe_multi_link into bpf_link ? (There is a 7 byte hole there anyway)
and checking flags inline.

Jiri, Andrii,

Quoted 8 lines
Quoted 1 line

better ideas?

We can just remember original attr->link_create.attach_type in bpf_link itself, and then have a small helper that will accept link type and attach type, and fill out link type representation based on those two. Internally we can do the special-casing of uprobe vs uretprobe and kprobe vs kretprobe transparently to all the other code. And use that here in show_fdinfo

but you'd still need the flags, no? to find out if it's return probe

I tried what Alexei suggested and it seems ok and simple enough

jirka

---

include/linux/bpf.h +1 -0
index 5dd556e89cce..287c956cdbd2 100644
@@ -1702,6 +1702,7 @@ struct bpf_link {
 	 * link's semantics is determined by target attach hook
 	 */
 	bool sleepable;
+	u32 flags;
 	/* rcu is used before freeing, work can be used to schedule that
 	 * RCU-based freeing before that, so they never overlap
 	 */
kernel/bpf/syscall.c +8 -1
index 56500381c28a..f1d9ee9717a1 100644
@@ -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);
kernel/trace/bpf_trace.c +4 -6
index 0a06ea6638fe..81d7a4e5ae15 100644
@@ -2466,7 +2466,6 @@ struct bpf_kprobe_multi_link {
 	u32 cnt;
 	u32 mods_cnt;
 	struct module **mods;
-	u32 flags;
 };
 
 struct bpf_kprobe_multi_run_ctx {
@@ -2586,7 +2585,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)
@@ -2976,7 +2975,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) {
 		/*
@@ -3045,7 +3044,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;
 };
@@ -3109,7 +3107,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;
 
@@ -3369,7 +3367,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);
author
#8 lore raw
Quoted 213 lines · Jiri Olsa
Quoted 115 lines · Andrii Nakryiko
Quoted 113 lines · Alexei Starovoitov
Quoted 91 lines · 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
---
  include/linux/trace_events.h | 10 ++++++++++
  kernel/bpf/syscall.c         |  9 ++++++++-
  kernel/trace/bpf_trace.c     | 28 ++++++++++++++++++++++++++++
  3 files changed, 46 insertions(+), 1 deletion(-)

Change list:

   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/[email protected]

   v3 -> v4:
     - use %pS to print func info.(Alexei)
   v3:
   https://lore.kernel.org/bpf/[email protected]

   v2 -> v3:
     - show info in one line for multi events.(Jiri)
   v2:
   https://lore.kernel.org/bpf/[email protected]

   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/[email protected]
include/linux/trace_events.h +10 -0
index fa9cf4292df..951c91babbc 100644
@@ -780,6 +780,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
                             unsigned long *missed);
  int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
  int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
+void bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
+void bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
  #else
  static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
  {
@@ -832,6 +834,14 @@ bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
  {
         return -EOPNOTSUPP;
  }
+static inline void
+bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
+static inline void
+bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
  #endif
 
  enum {
kernel/bpf/syscall.c +1 -0
index 51ba1a7aa43..43b821b37bc 100644
@@ -3226,9 +3226,16 @@ static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp)
         const struct bpf_prog *prog = link->prog;
         enum bpf_link_type type = link->type;
         char prog_tag[sizeof(prog->tag) * 2 + 1] = { };
+       char link_type[64] = {};

kernel/bpf/syscall.c static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp) · line 3238

Quoted 10 lines
kernel/bpf/syscall.c +7 -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)
+                       bpf_kprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else if (link->type == BPF_LINK_TYPE_UPROBE_MULTI)
+                       bpf_uprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else
+                       strscpy(link_type, bpf_link_type_strs[type], sizeof(link_type));
+               seq_printf(m, "link_type:\t%s\n", link_type);

New callbacks just to print a string?
Let's find a different way.

How about moving 'flags' from bpf_[ku]probe_multi_link into bpf_link ? (There is a 7 byte hole there anyway)
and checking flags inline.

Jiri, Andrii,

Quoted 8 lines
Quoted 1 line

better ideas?

We can just remember original attr->link_create.attach_type in bpf_link itself, and then have a small helper that will accept link type and attach type, and fill out link type representation based on those two. Internally we can do the special-casing of uprobe vs uretprobe and kprobe vs kretprobe transparently to all the other code. And use that here in show_fdinfo

but you'd still need the flags, no? to find out if it's return probe

I tried what Alexei suggested and it seems ok and simple enough

jirka

---

include/linux/bpf.h +1 -0
index 5dd556e89cce..287c956cdbd2 100644
@@ -1702,6 +1702,7 @@ struct bpf_link {
  	 * link's semantics is determined by target attach hook
  	 */
  	bool sleepable;
+	u32 flags;
  	/* rcu is used before freeing, work can be used to schedule that
  	 * RCU-based freeing before that, so they never overlap
  	 */
kernel/bpf/syscall.c +8 -1
index 56500381c28a..f1d9ee9717a1 100644
@@ -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);
kernel/trace/bpf_trace.c +3 -5
index 0a06ea6638fe..81d7a4e5ae15 100644
@@ -2466,7 +2466,6 @@ struct bpf_kprobe_multi_link {
  	u32 cnt;
  	u32 mods_cnt;
  	struct module **mods;
-	u32 flags;
  };
 
  struct bpf_kprobe_multi_run_ctx {
@@ -2586,7 +2585,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)
@@ -2976,7 +2975,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) {
  		/*
@@ -3045,7 +3044,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;
  };
@@ -3109,7 +3107,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;
 

kernel/trace/bpf_trace.c int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr · line 3373

Quoted 8 lines
kernel/trace/bpf_trace.c +1 -1
@@ -3369,7 +3367,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);

Hi, Jiri, Andrii,

Jiri's patch looks more simple, and i see other struct xx_links wrap bpf_link, which have attach_type field like:

struct sockmap_link {
        struct bpf_link link;
        struct bpf_map *map;
        enum bpf_attach_type attach_type;
};

If we create attach_type filed in bpf_link, maybe these struct xx_link should also be modified. BTW, as Jiri said, we still can not find return probe type from attach_type.

Signature · 2 lines
Best Regards
Tao Chen
#9 lore raw
Quoted 228 lines · Tao Chen
Quoted 213 lines · Jiri Olsa
Quoted 115 lines · Andrii Nakryiko
Quoted 113 lines · Alexei Starovoitov
Quoted 91 lines · 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
---
  include/linux/trace_events.h | 10 ++++++++++
  kernel/bpf/syscall.c         |  9 ++++++++-
  kernel/trace/bpf_trace.c     | 28 ++++++++++++++++++++++++++++
  3 files changed, 46 insertions(+), 1 deletion(-)

Change list:

   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/[email protected]

   v3 -> v4:
     - use %pS to print func info.(Alexei)
   v3:
   https://lore.kernel.org/bpf/[email protected]

   v2 -> v3:
     - show info in one line for multi events.(Jiri)
   v2:
   https://lore.kernel.org/bpf/[email protected]

   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/[email protected]
include/linux/trace_events.h +10 -0
index fa9cf4292df..951c91babbc 100644
@@ -780,6 +780,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
                             unsigned long *missed);
  int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
  int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
+void bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
+void bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
  #else
  static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
  {
@@ -832,6 +834,14 @@ bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
  {
         return -EOPNOTSUPP;
  }
+static inline void
+bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
+static inline void
+bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
  #endif
 
  enum {
kernel/bpf/syscall.c +1 -0
index 51ba1a7aa43..43b821b37bc 100644
@@ -3226,9 +3226,16 @@ static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp)
         const struct bpf_prog *prog = link->prog;
         enum bpf_link_type type = link->type;
         char prog_tag[sizeof(prog->tag) * 2 + 1] = { };
+       char link_type[64] = {};

kernel/bpf/syscall.c static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp) · line 3238

Quoted 10 lines
kernel/bpf/syscall.c +7 -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)
+                       bpf_kprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else if (link->type == BPF_LINK_TYPE_UPROBE_MULTI)
+                       bpf_uprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else
+                       strscpy(link_type, bpf_link_type_strs[type], sizeof(link_type));
+               seq_printf(m, "link_type:\t%s\n", link_type);

New callbacks just to print a string?
Let's find a different way.

How about moving 'flags' from bpf_[ku]probe_multi_link into bpf_link ? (There is a 7 byte hole there anyway)
and checking flags inline.

Jiri, Andrii,

Quoted 8 lines
Quoted 1 line

better ideas?

We can just remember original attr->link_create.attach_type in bpf_link itself, and then have a small helper that will accept link type and attach type, and fill out link type representation based on those two. Internally we can do the special-casing of uprobe vs uretprobe and kprobe vs kretprobe transparently to all the other code. And use that here in show_fdinfo

but you'd still need the flags, no? to find out if it's return probe

I tried what Alexei suggested and it seems ok and simple enough

jirka

---

include/linux/bpf.h +1 -0
index 5dd556e89cce..287c956cdbd2 100644
@@ -1702,6 +1702,7 @@ struct bpf_link {
       * link's semantics is determined by target attach hook
       */
      bool sleepable;
+     u32 flags;
      /* rcu is used before freeing, work can be used to schedule that
       * RCU-based freeing before that, so they never overlap
       */
kernel/bpf/syscall.c +8 -1
index 56500381c28a..f1d9ee9717a1 100644
@@ -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);
kernel/trace/bpf_trace.c +3 -5
index 0a06ea6638fe..81d7a4e5ae15 100644
@@ -2466,7 +2466,6 @@ struct bpf_kprobe_multi_link {
      u32 cnt;
      u32 mods_cnt;
      struct module **mods;
-     u32 flags;
  };
 
  struct bpf_kprobe_multi_run_ctx {
@@ -2586,7 +2585,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)
@@ -2976,7 +2975,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) {
              /*
@@ -3045,7 +3044,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;
  };
@@ -3109,7 +3107,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;
 

kernel/trace/bpf_trace.c int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr · line 3373

Quoted 8 lines
kernel/trace/bpf_trace.c +1 -1
@@ -3369,7 +3367,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);

Hi, Jiri, Andrii,

Jiri's patch looks more simple, and i see other struct xx_links wrap bpf_link, which have attach_type field like:

Quoted 8 lines
struct sockmap_link {
         struct bpf_link link;
         struct bpf_map *map;
         enum bpf_attach_type attach_type;
};

If we create attach_type filed in bpf_link, maybe these struct xx_link should also be modified. BTW, as Jiri said, we still can not find return probe type from attach_type.

You are right, I somehow was under impression that ret vs non-retprobe comes from attach type as well.

Ok, moving flags into common bpf_link struct sounds good to me. I'd still move attach_type into bpf_link, together with flags, for generality (and update all those links that already include attach_type as you mentioned). We can make it a single-byte field to not increase bpf_link size unnecessarily (by using bitfield size).

Quoted 4 lines

--
Best Regards
Tao Chen

author
#10 lore raw
Quoted 238 lines · Andrii Nakryiko
Quoted 228 lines · Tao Chen
Quoted 213 lines · Jiri Olsa
Quoted 115 lines · Andrii Nakryiko
Quoted 113 lines · Alexei Starovoitov
Quoted 91 lines · 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
---
   include/linux/trace_events.h | 10 ++++++++++
   kernel/bpf/syscall.c         |  9 ++++++++-
   kernel/trace/bpf_trace.c     | 28 ++++++++++++++++++++++++++++
   3 files changed, 46 insertions(+), 1 deletion(-)

Change list:

    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/[email protected]

    v3 -> v4:
      - use %pS to print func info.(Alexei)
    v3:
    https://lore.kernel.org/bpf/[email protected]

    v2 -> v3:
      - show info in one line for multi events.(Jiri)
    v2:
    https://lore.kernel.org/bpf/[email protected]

    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/[email protected]
include/linux/trace_events.h +10 -0
index fa9cf4292df..951c91babbc 100644
@@ -780,6 +780,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
                              unsigned long *missed);
   int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
   int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
+void bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
+void bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
   #else
   static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
   {
@@ -832,6 +834,14 @@ bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
   {
          return -EOPNOTSUPP;
   }
+static inline void
+bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
+static inline void
+bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
   #endif
 
   enum {
kernel/bpf/syscall.c +1 -0
index 51ba1a7aa43..43b821b37bc 100644
@@ -3226,9 +3226,16 @@ static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp)
          const struct bpf_prog *prog = link->prog;
          enum bpf_link_type type = link->type;
          char prog_tag[sizeof(prog->tag) * 2 + 1] = { };
+       char link_type[64] = {};

kernel/bpf/syscall.c static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp) · line 3238

Quoted 10 lines
kernel/bpf/syscall.c +7 -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)
+                       bpf_kprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else if (link->type == BPF_LINK_TYPE_UPROBE_MULTI)
+                       bpf_uprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else
+                       strscpy(link_type, bpf_link_type_strs[type], sizeof(link_type));
+               seq_printf(m, "link_type:\t%s\n", link_type);

New callbacks just to print a string?
Let's find a different way.

How about moving 'flags' from bpf_[ku]probe_multi_link into bpf_link ? (There is a 7 byte hole there anyway)
and checking flags inline.

Jiri, Andrii,

Quoted 8 lines
Quoted 1 line

better ideas?

We can just remember original attr->link_create.attach_type in bpf_link itself, and then have a small helper that will accept link type and attach type, and fill out link type representation based on those two. Internally we can do the special-casing of uprobe vs uretprobe and kprobe vs kretprobe transparently to all the other code. And use that here in show_fdinfo

but you'd still need the flags, no? to find out if it's return probe

I tried what Alexei suggested and it seems ok and simple enough

jirka

---

include/linux/bpf.h +1 -0
index 5dd556e89cce..287c956cdbd2 100644
@@ -1702,6 +1702,7 @@ struct bpf_link {
        * link's semantics is determined by target attach hook
        */
       bool sleepable;
+     u32 flags;
       /* rcu is used before freeing, work can be used to schedule that
        * RCU-based freeing before that, so they never overlap
        */
kernel/bpf/syscall.c +8 -1
index 56500381c28a..f1d9ee9717a1 100644
@@ -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);
kernel/trace/bpf_trace.c +3 -5
index 0a06ea6638fe..81d7a4e5ae15 100644
@@ -2466,7 +2466,6 @@ struct bpf_kprobe_multi_link {
       u32 cnt;
       u32 mods_cnt;
       struct module **mods;
-     u32 flags;
   };
 
   struct bpf_kprobe_multi_run_ctx {
@@ -2586,7 +2585,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)
@@ -2976,7 +2975,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) {
               /*
@@ -3045,7 +3044,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;
   };
@@ -3109,7 +3107,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;
 

kernel/trace/bpf_trace.c int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr · line 3373

Quoted 8 lines
kernel/trace/bpf_trace.c +1 -1
@@ -3369,7 +3367,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);

Hi, Jiri, Andrii,

Jiri's patch looks more simple, and i see other struct xx_links wrap bpf_link, which have attach_type field like:

Quoted 8 lines
struct sockmap_link {
          struct bpf_link link;
          struct bpf_map *map;
          enum bpf_attach_type attach_type;
};

If we create attach_type filed in bpf_link, maybe these struct xx_link should also be modified. BTW, as Jiri said, we still can not find return probe type from attach_type.

Quoted 9 lines

You are right, I somehow was under impression that ret vs non-retprobe comes from attach type as well.

Ok, moving flags into common bpf_link struct sounds good to me. I'd still move attach_type into bpf_link, together with flags, for generality (and update all those links that already include attach_type as you mentioned). We can make it a single-byte field to not increase bpf_link size unnecessarily (by using bitfield size).

Well,can we complete this in two steps?

1. Create a common field in bpf_link used for flags or attach_type, and realise the precise link_type feature as Jiri and Alexei said, the review of this part has been revised almost completely.

2. Move the attach_type from struct bpf_xx_link into bpf_link, this will involve a lot of changes, i will send a separate patchset to finish it.

Quoted 4 lines
Quoted 4 lines

--
Best Regards
Tao Chen

Signature · 2 lines
Best Regards
Tao Chen
#11 lore raw
Quoted 243 lines · Tao Chen
Quoted 241 lines · Andrii Nakryiko
Quoted 228 lines · Tao Chen
Quoted 213 lines · Jiri Olsa
Quoted 115 lines · Andrii Nakryiko
Quoted 113 lines · Alexei Starovoitov
Quoted 91 lines · 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
---
   include/linux/trace_events.h | 10 ++++++++++
   kernel/bpf/syscall.c         |  9 ++++++++-
   kernel/trace/bpf_trace.c     | 28 ++++++++++++++++++++++++++++
   3 files changed, 46 insertions(+), 1 deletion(-)

Change list:

    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/[email protected]

    v3 -> v4:
      - use %pS to print func info.(Alexei)
    v3:
    https://lore.kernel.org/bpf/[email protected]

    v2 -> v3:
      - show info in one line for multi events.(Jiri)
    v2:
    https://lore.kernel.org/bpf/[email protected]

    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/[email protected]
include/linux/trace_events.h +10 -0
index fa9cf4292df..951c91babbc 100644
@@ -780,6 +780,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
                              unsigned long *missed);
   int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
   int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
+void bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
+void bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len);
   #else
   static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
   {
@@ -832,6 +834,14 @@ bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
   {
          return -EOPNOTSUPP;
   }
+static inline void
+bpf_kprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
+static inline void
+bpf_uprobe_multi_link_type_show(const struct bpf_link *link, char *link_type, int len)
+{
+}
   #endif
 
   enum {
kernel/bpf/syscall.c +1 -0
index 51ba1a7aa43..43b821b37bc 100644
@@ -3226,9 +3226,16 @@ static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp)
          const struct bpf_prog *prog = link->prog;
          enum bpf_link_type type = link->type;
          char prog_tag[sizeof(prog->tag) * 2 + 1] = { };
+       char link_type[64] = {};

kernel/bpf/syscall.c static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp) · line 3238

Quoted 10 lines
kernel/bpf/syscall.c +7 -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)
+                       bpf_kprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else if (link->type == BPF_LINK_TYPE_UPROBE_MULTI)
+                       bpf_uprobe_multi_link_type_show(link, link_type, sizeof(link_type));
+               else
+                       strscpy(link_type, bpf_link_type_strs[type], sizeof(link_type));
+               seq_printf(m, "link_type:\t%s\n", link_type);

New callbacks just to print a string?
Let's find a different way.

How about moving 'flags' from bpf_[ku]probe_multi_link into bpf_link ? (There is a 7 byte hole there anyway)
and checking flags inline.

Jiri, Andrii,

Quoted 8 lines
Quoted 1 line

better ideas?

We can just remember original attr->link_create.attach_type in bpf_link itself, and then have a small helper that will accept link type and attach type, and fill out link type representation based on those two. Internally we can do the special-casing of uprobe vs uretprobe and kprobe vs kretprobe transparently to all the other code. And use that here in show_fdinfo

but you'd still need the flags, no? to find out if it's return probe

I tried what Alexei suggested and it seems ok and simple enough

jirka

---

include/linux/bpf.h +1 -0
index 5dd556e89cce..287c956cdbd2 100644
@@ -1702,6 +1702,7 @@ struct bpf_link {
        * link's semantics is determined by target attach hook
        */
       bool sleepable;
+     u32 flags;
       /* rcu is used before freeing, work can be used to schedule that
        * RCU-based freeing before that, so they never overlap
        */
kernel/bpf/syscall.c +8 -1
index 56500381c28a..f1d9ee9717a1 100644
@@ -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);
kernel/trace/bpf_trace.c +3 -5
index 0a06ea6638fe..81d7a4e5ae15 100644
@@ -2466,7 +2466,6 @@ struct bpf_kprobe_multi_link {
       u32 cnt;
       u32 mods_cnt;
       struct module **mods;
-     u32 flags;
   };
 
   struct bpf_kprobe_multi_run_ctx {
@@ -2586,7 +2585,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)
@@ -2976,7 +2975,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) {
               /*
@@ -3045,7 +3044,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;
   };
@@ -3109,7 +3107,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;
 

kernel/trace/bpf_trace.c int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr · line 3373

Quoted 8 lines
kernel/trace/bpf_trace.c +1 -1
@@ -3369,7 +3367,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);

Hi, Jiri, Andrii,

Jiri's patch looks more simple, and i see other struct xx_links wrap bpf_link, which have attach_type field like:

Quoted 8 lines
struct sockmap_link {
          struct bpf_link link;
          struct bpf_map *map;
          enum bpf_attach_type attach_type;
};

If we create attach_type filed in bpf_link, maybe these struct xx_link should also be modified. BTW, as Jiri said, we still can not find return probe type from attach_type.

You are right, I somehow was under impression that ret vs non-retprobe comes from attach type as well.

Quoted 9 lines
Quoted 6 lines

Ok, moving flags into common bpf_link struct sounds good to me. I'd still move attach_type into bpf_link, together with flags, for generality (and update all those links that already include attach_type as you mentioned). We can make it a single-byte field to not increase bpf_link size unnecessarily (by using bitfield size).

Well,can we complete this in two steps?

sure, of course

Quoted 16 lines

1. Create a common field in bpf_link used for flags or attach_type, and realise the precise link_type feature as Jiri and Alexei said, the review of this part has been revised almost completely.

2. Move the attach_type from struct bpf_xx_link into bpf_link, this will involve a lot of changes, i will send a separate patchset to finish it.

Quoted 4 lines
Quoted 4 lines

--
Best Regards
Tao Chen

--
Best Regards
Tao Chen