From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Leon Hwang" <leon.hwang@linux.dev>, <bpf@vger.kernel.org>
Cc: "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>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Masami Hiramatsu" <mhiramat@kernel.org>,
"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
"KP Singh" <kpsingh@kernel.org>,
"Matt Bobrowski" <matt@bobrowski.net>,
"Shuah Khan" <shuah@kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-trace-kernel@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <netdev@vger.kernel.org>
Subject: Re: [PATCH bpf-next v2 2/9] bpf: Add log support for tracing_multi link_create
Date: Tue, 17 Nov 2026 05:24:34 +0000 [thread overview]
Message-ID: <DMX8HR7NDP9V.CDDWGLZ98C0K@gmail.com> (raw)
In-Reply-To: <20261114150610.84507-3-leon.hwang@linux.dev>
On Sat, Nov 14, 2026 at 07:06 AM Leon Hwang <leon.hwang@linux.dev> wrote:
> - if (!cnt || !uids)
> + if (!cnt) {
> + bpf_log(log, "tracing_multi.cnt cannot be zero.\n");
> return -EINVAL;
The user sees cnt == 0 in his own code.
He can't see which of up to 1 << 20 ids the kernel refuses.
That part stays silent:
bpf_tracing_multi_attach()
check_dup_ids() -EINVAL
bpf_trampoline_multi_attach()
bpf_check_attach_btf_id_multi() -EINVAL, -ENOENT, -EOPNOTSUPP
btf_attach_func_proto(NULL, btf, btf_id)
btf_distill_func_proto(NULL, btf, t, tname, &tgt_info->fmodel)
The last two have messages. They get NULL.
That loop runs before trampoline_lock_all(), so bpf_log() is fine there.
can we pass the log down and name the id ?
> + if (cnt > MAX_TRACING_MULTI_CNT) {
> + bpf_log(log, "tracing_multi.cnt is too large.\n");
> return -E2BIG;
that's not a helpful message. -E2BIG says the same.
> + if (attr->link_create.flags) {
> + bpf_log(log, "Invalid flags.\n");
> return -EINVAL;
Each value but zero is refused. "flags must be zero." would make it clear.
> -int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
> +int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,
> + struct bpf_verifier_log *log)
> {
> return -EOPNOTSUPP;
The stub has the log now and knows the reason.
Consider something like:
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index c3f6364..efff0fa 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1646,7 +1646,8 @@ void bpf_trampoline_put(struct bpf_trampoline *tr);
int arch_prepare_bpf_dispatcher(void *image, void *buf, s64 *funcs, int num_funcs);
int bpf_trampoline_multi_attach(struct bpf_prog *prog, u32 *ids,
- struct bpf_tracing_multi_link *link);
+ struct bpf_tracing_multi_link *link,
+ struct bpf_verifier_log *log);
void bpf_trampoline_multi_detach(struct bpf_prog *prog,
struct bpf_tracing_multi_link *link);
void bpf_trampoline_set_flags(struct bpf_trampoline *tr, u32 flags);
@@ -1764,7 +1765,8 @@ static inline bool bpf_prog_has_trampoline(const struct bpf_prog *prog)
return false;
}
static inline int bpf_trampoline_multi_attach(struct bpf_prog *prog, u32 *ids,
- struct bpf_tracing_multi_link *link)
+ struct bpf_tracing_multi_link *link,
+ struct bpf_verifier_log *log)
{
return -ENOTSUPP;
}
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 716330b..bf2aef5 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -2183,7 +2183,8 @@ int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
struct bpf_insn *insn_buf, int insn_idx, int *cnt);
/* Functions exported from verifier.c, used by trampoline.c */
-int bpf_check_attach_btf_id_multi(struct btf *btf, struct bpf_prog *prog, u32 btf_id,
+int bpf_check_attach_btf_id_multi(struct bpf_verifier_log *log, struct btf *btf,
+ struct bpf_prog *prog, u32 btf_id,
struct bpf_attach_target_info *tgt_info);
/* Functions in fixups.c, called from bpf_check() */
diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
index 21d4608..93fead8 100644
--- a/kernel/bpf/trampoline.c
+++ b/kernel/bpf/trampoline.c
@@ -1724,7 +1724,8 @@ static void bpf_trampoline_multi_attach_rollback(struct bpf_trampoline *tr)
for_each_mnode_cnt(mnode, link, link->nodes_cnt)
int bpf_trampoline_multi_attach(struct bpf_prog *prog, u32 *ids,
- struct bpf_tracing_multi_link *link)
+ struct bpf_tracing_multi_link *link,
+ struct bpf_verifier_log *log)
{
struct bpf_tracing_multi_data *data = &link->data;
struct bpf_attach_target_info tgt_info = {};
@@ -1737,9 +1738,11 @@ int bpf_trampoline_multi_attach(struct bpf_prog *prog, u32 *ids,
for_each_mnode(mnode, link) {
rollback_cnt = i;
- err = bpf_check_attach_btf_id_multi(btf, prog, ids[i], &tgt_info);
- if (err)
+ err = bpf_check_attach_btf_id_multi(log, btf, prog, ids[i], &tgt_info);
+ if (err) {
+ bpf_log(log, "Cannot attach to btf_id %u.\n", ids[i]);
goto rollback_put;
+ }
key = bpf_trampoline_compute_key(NULL, btf, ids[i]);
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index ce11e78..ce7f530 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -24420,7 +24422,8 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
return 0;
}
-int bpf_check_attach_btf_id_multi(struct btf *btf, struct bpf_prog *prog, u32 btf_id,
+int bpf_check_attach_btf_id_multi(struct bpf_verifier_log *log, struct btf *btf,
+ struct bpf_prog *prog, u32 btf_id,
struct bpf_attach_target_info *tgt_info)
{
const struct btf_type *t;
@@ -24447,10 +24450,10 @@ int bpf_check_attach_btf_id_multi(struct btf *btf, struct bpf_prog *prog, u32 bt
tname = btf_name_by_offset(btf, t->name_off);
if (!tname)
return -EINVAL;
- t = btf_attach_func_proto(NULL, btf, btf_id);
+ t = btf_attach_func_proto(log, btf, btf_id);
if (!t || !btf_type_is_func_proto(t))
return -EINVAL;
- err = btf_distill_func_proto(NULL, btf, t, tname, &tgt_info->fmodel);
+ err = btf_distill_func_proto(log, btf, t, tname, &tgt_info->fmodel);
if (err < 0)
return err;
if (tgt_info->fmodel.ret_size > 8 &&
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index a3964d7..a7954e0 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3890,7 +3890,7 @@ static void ids_swap_r(void *a, void *b, int size __maybe_unused,
swap(*id_a, *id_b);
}
-static int check_dup_ids(u32 *ids, u64 *cookies, u32 cnt)
+static int check_dup_ids(u32 *ids, u64 *cookies, u32 cnt, struct bpf_verifier_log *log)
{
void *data[2] = { ids, cookies };
int err = 0;
@@ -3904,6 +3904,7 @@ static int check_dup_ids(u32 *ids, u64 *cookies, u32 cnt)
for (int i = 1; i < cnt; i++) {
if (ids[i] == ids[i - 1]) {
+ bpf_log(log, "btf_id %u is in tracing_multi.ids twice.\n", ids[i]);
err = -EINVAL;
break;
}
@@ -3935,15 +3936,16 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,
return -EINVAL;
}
if (cnt > MAX_TRACING_MULTI_CNT) {
- bpf_log(log, "tracing_multi.cnt is too large.\n");
+ bpf_log(log, "tracing_multi.cnt %u is above the limit %u.\n",
+ cnt, MAX_TRACING_MULTI_CNT);
return -E2BIG;
}
if (attr->link_create.flags) {
- bpf_log(log, "Invalid flags.\n");
+ bpf_log(log, "flags must be zero.\n");
return -EINVAL;
}
if (attr->link_create.target_fd) {
- bpf_log(log, "Invalid target_fd.\n");
+ bpf_log(log, "target_fd must be zero.\n");
return -EINVAL;
}
@@ -3969,7 +3971,7 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,
}
}
- err = check_dup_ids(ids, cookies, cnt);
+ err = check_dup_ids(ids, cookies, cnt, log);
if (err)
goto error;
@@ -3998,7 +4000,7 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,
link->cookies = cookies;
link->fexits = fexits;
- err = bpf_trampoline_multi_attach(prog, ids, link);
+ err = bpf_trampoline_multi_attach(prog, ids, link, log);
kvfree(ids);
if (err) {
bpf_link_cleanup(&link_primer);
@@ -4019,6 +4021,7 @@ error:
int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,
struct bpf_verifier_log *log)
{
+ bpf_log(log, "This kernel does not support tracing_multi.\n");
return -EOPNOTSUPP;
}
next prev parent reply other threads:[~2026-11-17 5:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 15:06 [PATCH bpf-next v2 0/9] bpf: Add log support for tracing link_create Leon Hwang
2026-11-14 15:06 ` [PATCH bpf-next v2 1/9] " Leon Hwang
2026-11-17 5:22 ` Alexei Starovoitov
2026-11-14 15:06 ` [PATCH bpf-next v2 2/9] bpf: Add log support for tracing_multi link_create Leon Hwang
2026-11-17 5:24 ` Alexei Starovoitov [this message]
2026-11-14 15:06 ` [PATCH bpf-next v2 3/9] bpf: Add log support for iter link_create Leon Hwang
2026-11-14 15:06 ` [PATCH bpf-next v2 4/9] bpf: Add log support for cgroup prog link_create Leon Hwang
2026-11-14 15:06 ` [PATCH bpf-next v2 5/9] libbpf: Add log_opts support for BPF_TRACE_ITER Leon Hwang
2026-11-14 15:06 ` [PATCH bpf-next v2 6/9] selftests/bpf: Verify tracing link_create logs Leon Hwang
2026-11-14 15:06 ` [PATCH bpf-next v2 7/9] selftests/bpf: Verify tracing_multi " Leon Hwang
2026-11-14 15:06 ` [PATCH bpf-next v2 8/9] selftests/bpf: Verify iter " Leon Hwang
2026-11-14 15:16 ` sashiko-bot
2026-11-16 7:30 ` Leon Hwang
2026-11-14 15:06 ` [PATCH bpf-next v2 9/9] selftests/bpf: Verify cgroup prog " Leon Hwang
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=DMX8HR7NDP9V.CDDWGLZ98C0K@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=leon.hwang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=matt@bobrowski.net \
--cc=memxor@gmail.com \
--cc=mhiramat@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox