From: Leon Hwang <leon.hwang@linux.dev>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Quentin Monnet <qmo@kernel.org>, Shuah Khan <shuah@kernel.org>,
Leon Hwang <leon.hwang@linux.dev>,
Mykyta Yatsenko <yatsenko@meta.com>,
Avinash Duduskar <avinash.duduskar@gmail.com>,
Anton Protopopov <a.s.protopopov@gmail.com>,
Amery Hung <ameryhung@gmail.com>, Jordan Rife <jordan@jrife.io>,
Rong Tao <rongtao@cestc.cn>, Eyal Birger <eyal.birger@gmail.com>,
Pu Lehui <pulehui@huawei.com>,
Jingguo Tan <tanjingguo@huawei.com>, Lin Ma <malin89@huawei.com>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: [PATCH bpf-next v2 14/21] bpf: Add tracing_multi link info support for bpf progs
Date: Mon, 12 Oct 2026 23:40:16 +0800 [thread overview]
Message-ID: <20261012154024.29423-15-leon.hwang@linux.dev> (raw)
In-Reply-To: <20261012154024.29423-1-leon.hwang@linux.dev>
Show bpf prog info in the link info.
$ bpftool link
9: tracing_multi prog 25
attach_type trace_fsession_multi btf_obj_id 1 count 2
prog_id func_btf_id addr cookie func [module]
21 4 ffffffffc080064c 16706819 target_1 [bpf]
22 5 ffffffffc08006d4 16706819 target_2 [bpf]
pids test_progs(98)
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
include/uapi/linux/bpf.h | 7 +++-
kernel/trace/bpf_trace.c | 26 ++++++++++----
tools/bpf/bpftool/link.c | 63 +++++++++++++++++++++++++++-------
tools/include/uapi/linux/bpf.h | 7 +++-
4 files changed, 82 insertions(+), 21 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 94302a3b680c..df66206af3cf 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -6891,6 +6891,10 @@ struct bpf_btf_info {
__u32 kernel_btf;
} __attribute__((aligned(8)));
+enum {
+ BPF_F_TRACING_MULTI_TGT_PROGS = (1U << 0),
+};
+
struct bpf_link_info {
__u32 type;
__u32 id;
@@ -6976,10 +6980,11 @@ struct bpf_link_info {
__u32 attach_type;
__u32 count; /* in/out: tracing_multi target count */
__u32 btf_obj_id;
- __u32 :32;
+ __u32 flags;
__aligned_u64 ids;
__aligned_u64 addrs;
__aligned_u64 cookies;
+ __aligned_u64 func_btf_ids;
} tracing_multi;
struct {
__u32 type; /* enum bpf_perf_event_type */
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 8b1a52350cfd..39c911917ae2 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3709,15 +3709,16 @@ static void bpf_tracing_multi_link_dealloc(struct bpf_link *link)
static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,
struct bpf_link_info *info)
{
+ u32 __user *fids = u64_to_user_ptr(info->tracing_multi.func_btf_ids);
u64 __user *ucookies = u64_to_user_ptr(info->tracing_multi.cookies);
u64 __user *uaddrs = u64_to_user_ptr(info->tracing_multi.addrs);
u32 __user *uids = u64_to_user_ptr(info->tracing_multi.ids);
struct bpf_tracing_multi_link *tr_link;
u32 ucount = info->tracing_multi.count;
- bool has_cookies, show_addrs;
+ bool has_cookies, show_addrs, has_progs;
int err = 0;
- if ((uids || ucookies || uaddrs) && !ucount)
+ if ((uids || ucookies || uaddrs || fids) && !ucount)
return -EINVAL;
tr_link = container_of(link, struct bpf_tracing_multi_link, link);
@@ -3725,9 +3726,13 @@ static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,
info->tracing_multi.attach_type = tr_link->link.attach_type;
info->tracing_multi.count = tr_link->nodes_cnt;
info->tracing_multi.btf_obj_id = btf_obj_id(tr_link->link.prog->aux->attach_btf);
+ has_progs = !!tr_link->tgt_progs;
+ info->tracing_multi.flags = has_progs ? BPF_F_TRACING_MULTI_TGT_PROGS : 0;
- if (!uids && !ucookies && !uaddrs)
+ if (!uids && !ucookies && !uaddrs && !fids)
return 0;
+ if (has_progs != !!fids)
+ return -EINVAL;
if (ucount < tr_link->nodes_cnt)
err = -ENOSPC;
@@ -3739,20 +3744,27 @@ static int bpf_tracing_multi_link_fill_link_info(const struct bpf_link *link,
for (int i = 0; i < ucount; i++) {
struct bpf_tracing_multi_node *mnode = &tr_link->nodes[i];
+ u32 prog_id, btf_id;
u64 addr, cookie;
- u32 id;
- bpf_trampoline_unpack_key(mnode->trampoline->key, NULL, &id);
+ bpf_trampoline_unpack_key(mnode->trampoline->key, &prog_id, &btf_id);
- addr = show_addrs ? mnode->trampoline->ip : 0;
+ if (!show_addrs)
+ addr = 0;
+ else if (has_progs)
+ addr = (u64) mnode->trampoline->func.addr;
+ else
+ addr = mnode->trampoline->ip;
cookie = has_cookies ? tr_link->cookies[i] : 0;
- if (uids && put_user(id, uids + i))
+ if (uids && put_user(has_progs ? prog_id : btf_id, uids + i))
return -EFAULT;
if (uaddrs && put_user(addr, uaddrs + i))
return -EFAULT;
if (ucookies && put_user(cookie, ucookies + i))
return -EFAULT;
+ if (has_progs && put_user((u32) mnode->trampoline->key, fids + i))
+ return -EFAULT;
cond_resched();
}
diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index 5cffa2d283b4..da7e430b14c8 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -422,12 +422,31 @@ show_uprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
jsonw_end_array(json_wtr);
}
+#define BPF_PROG_PREFIX "bpf_prog_"
+#define BPF_PROG_PREFIX_LEN (sizeof(BPF_PROG_PREFIX) - 1)
+
+static const char *
+sym_name_trim_prefix(struct kernel_sym *sym, bool is_prog)
+{
+ int prefix_len;
+
+ if (!is_prog)
+ return sym->name;
+
+ /* Ref kernel/bpf/core.c::bpf_prog_ksym_set_name() */
+ prefix_len = BPF_PROG_PREFIX_LEN;
+ prefix_len += BPF_TAG_SIZE * 2;
+ if (sym->name[prefix_len] != '\0')
+ prefix_len += 1; /* skip the '_' */
+ return sym->name + prefix_len;
+}
+
static void
show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
{
- bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol;
+ bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol, tgt_progs;
__u64 *addrs, *cookies;
- __u32 i, *ids;
+ __u32 i, *ids, *fids;
if (!dd.sym_count)
kernel_syms_load(&dd);
@@ -443,6 +462,8 @@ show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
ids = u64_to_u32_arr(info->tracing_multi.ids);
addrs = u64_to_arr(info->tracing_multi.addrs);
cookies = u64_to_arr(info->tracing_multi.cookies);
+ fids = u64_to_u32_arr(info->tracing_multi.func_btf_ids);
+ tgt_progs = info->tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS;
for (i = 0; i < info->tracing_multi.count; i++) {
struct kernel_sym *sym;
@@ -451,10 +472,12 @@ show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
sym = show_symbol ? find_kernel_sym_by_addr(addr, is_ibt_enabled) : NULL;
jsonw_start_object(wtr);
- jsonw_uint_field(wtr, "id", ids[i]);
+ jsonw_uint_field(wtr, tgt_progs ? "prog_id" : "id", ids[i]);
+ if (tgt_progs)
+ jsonw_uint_field(wtr, "func_btf_id", fids[i]);
jsonw_uint_field(wtr, "addr", addr);
if (sym) {
- jsonw_string_field(wtr, "func", sym->name);
+ jsonw_string_field(wtr, "func", sym_name_trim_prefix(sym, tgt_progs));
if (sym->module[0] == '\0') {
jsonw_name(wtr, "module");
jsonw_null(wtr);
@@ -903,9 +926,9 @@ static void show_uprobe_multi_plain(struct bpf_link_info *info)
static void show_tracing_multi_plain(struct bpf_link_info *info)
{
- bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol;
+ bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol, tgt_progs;
__u64 *addrs, *cookies;
- __u32 i, *ids;
+ __u32 i, *ids, *fids;
if (!info->tracing_multi.count)
return;
@@ -919,12 +942,18 @@ static void show_tracing_multi_plain(struct bpf_link_info *info)
printf("btf_obj_id %u ", info->tracing_multi.btf_obj_id);
printf("count %u ", info->tracing_multi.count);
- printf("\n\t%-16s %-16s %-16s %s",
- "btf_id", "addr", "cookie", "func [module]");
+ tgt_progs = info->tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS;
+ if (tgt_progs)
+ printf("\n\t%-16s %-16s %-16s %-16s %s",
+ "prog_id", "func_btf_id", "addr", "cookie", "func [module]");
+ else
+ printf("\n\t%-16s %-16s %-16s %s",
+ "btf_id", "addr", "cookie", "func [module]");
ids = u64_to_u32_arr(info->tracing_multi.ids);
addrs = u64_to_arr(info->tracing_multi.addrs);
cookies = u64_to_arr(info->tracing_multi.cookies);
+ fids = u64_to_u32_arr(info->tracing_multi.func_btf_ids);
for (i = 0; i < info->tracing_multi.count; i++) {
__u64 addr = addrs[i];
@@ -932,9 +961,13 @@ static void show_tracing_multi_plain(struct bpf_link_info *info)
sym = show_symbol ? find_kernel_sym_by_addr(addr, is_ibt_enabled) : NULL;
- printf("\n\t%-16u %016llx %-16llu", ids[i], addr, cookies[i]);
+ if (tgt_progs)
+ printf("\n\t%-16u %-16u %016llx %-16llu",
+ ids[i], fids[i], addr, cookies[i]);
+ else
+ printf("\n\t%-16u %016llx %-16llu", ids[i], addr, cookies[i]);
if (sym) {
- printf(" %s", sym->name);
+ printf(" %s", sym_name_trim_prefix(sym, tgt_progs));
if (sym->module[0] != '\0')
printf(" [%s]", sym->module);
}
@@ -1140,7 +1173,7 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
static int do_show_link(int fd)
{
__u64 *ref_ctr_offsets = NULL, *offsets = NULL, *cookies = NULL;
- __u32 *ids = NULL;
+ __u32 *ids = NULL, *func_btf_ids = NULL;
struct bpf_link_info info;
__u32 len = sizeof(info);
char path_buf[PATH_MAX];
@@ -1229,12 +1262,16 @@ static int do_show_link(int fd)
if (info.type == BPF_LINK_TYPE_TRACING_MULTI && !info.tracing_multi.ids) {
count = info.tracing_multi.count;
if (count) {
+ bool tgt_progs = info.tracing_multi.flags & BPF_F_TRACING_MULTI_TGT_PROGS;
+
ids = calloc(count, sizeof(__u32));
addrs = calloc(count, sizeof(__u64));
cookies = calloc(count, sizeof(__u64));
- if (!ids || !addrs || !cookies) {
+ func_btf_ids = tgt_progs ? calloc(count, sizeof(__u32)) : NULL;
+ if (!ids || !addrs || !cookies || (tgt_progs && !func_btf_ids)) {
p_err("mem alloc failed");
close(fd);
+ free(func_btf_ids);
free(cookies);
free(addrs);
free(ids);
@@ -1243,6 +1280,7 @@ static int do_show_link(int fd)
info.tracing_multi.ids = ptr_to_u64(ids);
info.tracing_multi.addrs = ptr_to_u64(addrs);
info.tracing_multi.cookies = ptr_to_u64(cookies);
+ info.tracing_multi.func_btf_ids = ptr_to_u64(func_btf_ids);
goto again;
}
}
@@ -1282,6 +1320,7 @@ static int do_show_link(int fd)
show_link_close_plain(fd, &info);
free(ref_ctr_offsets);
+ free(func_btf_ids);
free(cookies);
free(offsets);
free(addrs);
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 94302a3b680c..60998ea1381c 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -6817,6 +6817,10 @@ struct sk_reuseport_md {
#define BPF_TAG_SIZE 8
+enum {
+ BPF_F_TRACING_MULTI_TGT_PROGS = (1U << 0),
+};
+
struct bpf_prog_info {
__u32 type;
__u32 id;
@@ -6976,10 +6980,11 @@ struct bpf_link_info {
__u32 attach_type;
__u32 count; /* in/out: tracing_multi target count */
__u32 btf_obj_id;
- __u32 :32;
+ __u32 flags;
__aligned_u64 ids;
__aligned_u64 addrs;
__aligned_u64 cookies;
+ __aligned_u64 func_btf_ids;
} tracing_multi;
struct {
__u32 type; /* enum bpf_perf_event_type */
--
2.55.0
next prev parent reply other threads:[~2026-10-12 15:44 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 15:40 [PATCH bpf-next v2 00/21] bpf: Add tracing_multi link support for bpf progs Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 01/21] bpf: Initialize ftrace_managed in bpf_trampoline_get() Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 02/21] bpf: Drop unnecessary ftrace_location() in register/unregister/modify_fentry_multi() Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 03/21] bpf, x86: Factor out bpf_arch_text_poke_prepare_insns() helper on x86_64 Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 04/21] bpf, x86: Factor out bpf_arch_text_poke_check_ip() " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 05/21] bpf, x86: Introduce bpf_arch_text_poke_batch() " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 06/21] bpf: Add bpf_text_poke_batch() helper in trampoline Leon Hwang
2026-10-12 16:11 ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 07/21] bpf: Check tgt_prog before is_tracing_multi_id() in verifier Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 08/21] bpf: Move helpers out of CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS guard in trampoline Leon Hwang
2026-10-12 16:11 ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 09/21] bpf: Add bpf_trampoline_multi_prog_attach/detach() Leon Hwang
2026-10-12 16:16 ` sashiko-bot
2026-10-12 16:33 ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 10/21] bpf: Shrink CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS guard scope for bpf_tracing_multi_attach() Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 11/21] bpf: Add tracing_multi link support for bpf progs Leon Hwang
2026-10-12 16:33 ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 12/21] libbpf: " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 13/21] bpf: Add tracing_multi link fdinfo " Leon Hwang
2026-10-12 15:40 ` Leon Hwang [this message]
2026-10-12 16:33 ` [PATCH bpf-next v2 14/21] bpf: Add tracing_multi link info " bot+bpf-ci
2026-10-12 16:36 ` sashiko-bot
2026-10-12 15:40 ` [PATCH bpf-next v2 15/21] selftests/bpf: Add tracing_multi bpf prog attach test Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 16/21] selftests/bpf: Add tracing_multi bpf prog attach failure tests Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 17/21] selftests/bpf: Add tracing_multi bpf prog cookie test Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 18/21] selftests/bpf: Add tracing_multi bpf prog rollback test Leon Hwang
2026-10-12 16:46 ` sashiko-bot
2026-10-12 15:40 ` [PATCH bpf-next v2 19/21] selftests/bpf: Add tracing_multi bpf prog link info test Leon Hwang
2026-10-12 16:11 ` bot+bpf-ci
2026-10-12 16:43 ` sashiko-bot
2026-10-12 15:40 ` [PATCH bpf-next v2 20/21] selftests/bpf: Test tailcall with fentry.multi Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 21/21] selftests/bpf: Benchmark tracing_multi bpf progs attachment Leon Hwang
2026-10-12 16:33 ` bot+bpf-ci
2026-10-12 16:52 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261012154024.29423-15-leon.hwang@linux.dev \
--to=leon.hwang@linux.dev \
--cc=a.s.protopopov@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=avinash.duduskar@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=eyal.birger@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=jordan@jrife.io \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=malin89@huawei.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=pulehui@huawei.com \
--cc=qmo@kernel.org \
--cc=rongtao@cestc.cn \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=tanjingguo@huawei.com \
--cc=yatsenko@meta.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.