On 24/3/26 16:18, Jiri Olsa wrote:
> Adding tracing_multi link fdinfo support with following output:
>
> pos:0
> flags: 0200
> mnt_id: 19
> ino:3091
> link_type: tracing_multi
> link_id:382
Would better to add attach_type?
attach_type:[fentry,fexit,fsession]_multi
Thanks,
Leon
> prog_tag: 62073a1123f07ef7
> prog_id:715
> cnt:10
> cookie BTF-id func
> 891203 bpf_fentry_test1+0x4/0x10
> 991205 bpf_fentry_test2+0x4/0x10
> 791206 bpf_fentry_test3+0x4/0x20
> 591207 bpf_fentry_test4+0x4/0x20
> 491208 bpf_fentry_test5+0x4/0x20
> 291209 bpf_fentry_test6+0x4/0x20
> 391210 bpf_fentry_test7+0x4/0x10
> 191211 bpf_fentry_test8+0x4/0x10
> 10 91212 bpf_fentry_test9+0x4/0x10
> 691204 bpf_fentry_test10+0x4/0x10
>
> Signed-off-by: Jiri Olsa
> ---
> kernel/trace/bpf_trace.c | 26 ++
> 1 file changed, 26 insertions(+)
>
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 761501ce3a5f..41b691e83dc4 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -3618,9 +3618,35 @@ static void bpf_tracing_multi_link_dealloc(struct
> bpf_link *link)
> kvfree(tr_link);
> }
>
> +#ifdef CONFIG_PROC_FS
> +static void bpf_tracing_multi_show_fdinfo(const struct bpf_link *link,
> + struct seq_file *seq)
> +{
> + struct bpf_tracing_multi_link *tr_link =
> + container_of(link, struct bpf_tracing_multi_link, link);
> + bool has_cookies = !!tr_link->cookies;
> +
> + seq_printf(seq, "cnt:\t%u\n", tr_link->nodes_cnt);
> +
> + seq_printf(seq, "%s\t %s\t %s\n", "cookie", "BTF-id", "func");
> + for (int i = 0; i < tr_link->nodes_cnt; i++) {
> + struct bpf_tracing_multi_node *mnode = &tr_link->nodes[i];
> + u32 btf_id;
> +
> + bpf_trampoline_unpack_key(mnode->trampoline->key, NULL,
> &btf_id);
> + seq_printf(seq, "%llu\t %u\t %pS\n",
> +has_cookies ? tr_link->cookies[i] : 0,
> +btf_id, (void *) mnode->trampoline->ip);
> + }
> +}
> +#endif
> +
> static const struct bpf_link_ops bpf_tracing_multi_link_lops = {
> .release = bpf_tracing_multi_link_release,
> .dealloc_deferred = bpf_tracing_multi_link_dealloc,
> +#ifdef CONFIG_PROC_FS
> + .show_fdinfo = bpf_tracing_multi_show_fdinfo,
> +#endif
> };
>
> int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr
> *attr)