mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>
Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Quentin Monnet <qmo@kernel.org>,
	Alan Maguire <almagui@kernel.org>
Subject: [PATCH RFC bpf-next 17/31] bpf: Add log messages for kprobe multi inline attach
Date: Wed,  2 Dec 2026 13:30:21 +0100	[thread overview]
Message-ID: <20261202123035.10335-18-jolsa@kernel.org> (raw)
In-Reply-To: <20261202123035.10335-1-jolsa@kernel.org>

The attach of kprobe multi link with BPF_F_KPROBE_MULTI_INLINE flag
fails for several reasons with the same error.

Pass the link_create log to bpf_kprobe_multi_link_attach and use it
to explain the failure, including the function and the inlined
instance that can't be attached.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 include/linux/trace_events.h |  7 +++-
 kernel/bpf/syscall.c         |  2 +-
 kernel/trace/bpf_trace.c     | 78 ++++++++++++++++++++++++++++--------
 3 files changed, 68 insertions(+), 19 deletions(-)

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index dff8a209875c..a6bd86be8ef5 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -15,6 +15,7 @@ struct array_buffer;
 struct tracer;
 struct dentry;
 struct bpf_prog;
+struct bpf_verifier_log;
 union bpf_attr;
 struct bpf_verifier_log;
 
@@ -795,7 +796,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
 			    u32 *fd_type, const char **buf,
 			    u64 *probe_offset, u64 *probe_addr,
 			    unsigned long *missed);
-int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
+int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog,
+				 struct bpf_verifier_log *log);
 int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
 int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,
 			     struct bpf_verifier_log *log);
@@ -847,7 +849,8 @@ static inline int bpf_get_perf_event_info(const struct perf_event *event,
 	return -EOPNOTSUPP;
 }
 static inline int
-bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
+bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog,
+			     struct bpf_verifier_log *log)
 {
 	return -EOPNOTSUPP;
 }
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 0bdb4288beb2..28797c5fd9d2 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -6017,7 +6017,7 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_a
 			ret = bpf_perf_link_attach(attr, prog);
 		else if (attr->link_create.attach_type == BPF_TRACE_KPROBE_MULTI ||
 			 attr->link_create.attach_type == BPF_TRACE_KPROBE_SESSION)
-			ret = bpf_kprobe_multi_link_attach(attr, prog);
+			ret = bpf_kprobe_multi_link_attach(attr, prog, log);
 		else if (attr->link_create.attach_type == BPF_TRACE_UPROBE_MULTI ||
 			 attr->link_create.attach_type == BPF_TRACE_UPROBE_SESSION)
 			ret = bpf_uprobe_multi_link_attach(attr, prog);
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index af7d258d7357..7c0a22971d7a 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3149,6 +3149,7 @@ struct inline_lookup {
 	u64 *cookies;
 	u8 *args_cnt;
 	u32 syms_cnt;
+	struct bpf_verifier_log *log;
 
 	/* Output */
 	struct inline_sites *inlines;
@@ -3168,8 +3169,11 @@ static int inline_lookup_add(struct inline_lookup *lookup, const struct btf *btf
 	struct inline_site *sites;
 	u32 cap;
 
-	if (lookup->cnt == MAX_KPROBE_MULTI_CNT)
+	if (lookup->cnt == MAX_KPROBE_MULTI_CNT) {
+		bpf_log(lookup->log, "Number of inlined instances is above the limit %u.\n",
+			MAX_KPROBE_MULTI_CNT);
 		return -E2BIG;
+	}
 
 	if (lookup->cnt == lookup->cap) {
 		cap = max(16, lookup->cap * 2);
@@ -3354,6 +3358,7 @@ static bool inline_site_traceable(unsigned long addr)
 static int inline_lookup_symbols(struct inline_lookup *lookup)
 {
 	struct inline_sites *inlines = lookup->inlines;
+	struct bpf_verifier_log *log = lookup->log;
 	unsigned long *addrs = lookup->addrs;
 	u32 i, j, k, n, cnt = lookup->syms_cnt;
 	u64 *cookies = lookup->cookies;
@@ -3363,13 +3368,17 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
 	s32 id;
 
 	btf = bpf_get_btf_vmlinux_inline();
-	if (IS_ERR_OR_NULL(btf))
+	if (IS_ERR_OR_NULL(btf)) {
+		bpf_log(log, "Kernel inline BTF is not available.\n");
 		return -EOPNOTSUPP;
+	}
 
 	/* The offsets of inline.text locations are relative to .text section. */
 	id = btf_find_by_name_kind(btf, "inline.text", BTF_KIND_LOCSEC);
-	if (id < 0)
+	if (id < 0) {
+		bpf_log(log, "Kernel inline BTF has no inline.text section.\n");
 		return -EOPNOTSUPP;
+	}
 
 	err = inline_lookup_modules(lookup);
 	if (err)
@@ -3405,6 +3414,8 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
 		if (!addrs[i]) {
 			if (k < n && sites[k].sym_idx == i)
 				continue;
+			bpf_log(log, "Function %s has no entry and no inlined instance.\n",
+				lookup->syms[i]);
 			err = -ESRCH;
 			goto error;
 		}
@@ -3430,8 +3441,10 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
  * Register inlined instances of the @link and skip the ones that fail.
  * Fail if function has no entry and none of its instances registered,
  * with @strict fail on the first instance that fails to register.
+ * The instance that failed is returned in *@failed.
  */
-static int inline_sites_register(struct bpf_kprobe_multi_link *link, bool strict)
+static int inline_sites_register(struct bpf_kprobe_multi_link *link, bool strict,
+				 struct inline_site **failed)
 {
 	struct inline_sites *inlines = &link->inlines;
 	struct inline_site *site, *first = NULL;
@@ -3457,8 +3470,10 @@ static int inline_sites_register(struct bpf_kprobe_multi_link *link, bool strict
 		err = site->traceable ? register_kprobe(&site->kp) : -EINVAL;
 		if (err == -ENOMEM)
 			goto error;
-		if (err && strict)
+		if (err && strict) {
+			*failed = site;
 			goto error;
+		}
 		if (err) {
 			first_err = first_err ?: err;
 		} else {
@@ -3470,6 +3485,7 @@ static int inline_sites_register(struct bpf_kprobe_multi_link *link, bool strict
 		if (i + 1 < inlines->sites_cnt && site[1].sym_idx == site->sym_idx)
 			continue;
 		if (!attached) {
+			*failed = first;
 			err = first_err;
 			goto error;
 		}
@@ -3490,9 +3506,12 @@ static int inline_sites_register(struct bpf_kprobe_multi_link *link, bool strict
 	return err;
 }
 
-int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
+int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog,
+				 struct bpf_verifier_log *log)
 {
 	struct inline_sites inlines = {};
+	struct inline_site *failed = NULL;
+	struct user_syms us = {};
 	struct modules_array mods = {};
 	struct bpf_kprobe_multi_link *link = NULL;
 	struct bpf_link_primer link_primer;
@@ -3535,8 +3554,10 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	if (!!uaddrs == !!usyms)
 		return -EINVAL;
 
-	if (strict && !(flags & BPF_F_KPROBE_MULTI_INLINE))
+	if (strict && !(flags & BPF_F_KPROBE_MULTI_INLINE)) {
+		bpf_log(log, "Strict flag needs to be used with inline flag.\n");
 		return -EINVAL;
+	}
 
 	if (flags & BPF_F_KPROBE_MULTI_INLINE) {
 		/*
@@ -3544,16 +3565,28 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 		 * have just entry probe, so there's no return probe, session
 		 * or override support.
 		 */
-		if (flags & BPF_F_KPROBE_MULTI_RETURN)
+		if (flags & BPF_F_KPROBE_MULTI_RETURN) {
+			bpf_log(log, "Inlined functions can't be attached with return probe.\n");
 			return -EINVAL;
-		if (is_kprobe_session(prog) || prog->kprobe_override)
+		}
+		if (is_kprobe_session(prog) || prog->kprobe_override) {
+			bpf_log(log,
+				"Inlined functions can't be attached with session or override program.\n");
 			return -EINVAL;
-		if (uaddrs)
+		}
+		if (uaddrs) {
+			bpf_log(log,
+				"Inlined functions need to be specified with kprobe_multi.syms.\n");
 			return -EINVAL;
-		if (!IS_ENABLED(CONFIG_KPROBES))
+		}
+		if (!IS_ENABLED(CONFIG_KPROBES)) {
+			bpf_log(log, "Inlined functions need kprobes support.\n");
 			return -EOPNOTSUPP;
-		if (!IS_ENABLED(CONFIG_HAVE_KPROBE_MULTI_INLINE))
+		}
+		if (!IS_ENABLED(CONFIG_HAVE_KPROBE_MULTI_INLINE)) {
+			bpf_log(log, "Inlined functions are not supported on this architecture.\n");
 			return -EOPNOTSUPP;
+		}
 	}
 
 	cnt = attr->link_create.kprobe_multi.cnt;
@@ -3604,7 +3637,6 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 		struct multi_symbols_sort data = {
 			.cookies = cookies,
 		};
-		struct user_syms us;
 
 		err = copy_user_syms(&us, usyms, cnt);
 		if (err)
@@ -3635,6 +3667,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 				.addrs    = addrs,
 				.cookies  = cookies,
 				.args_cnt = args_cnt,
+				.log      = log,
 			};
 
 			err = inline_lookup_symbols(&lookup);
@@ -3643,7 +3676,6 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 				cnt = lookup.addrs_cnt;
 		}
 
-		free_user_syms(&us);
 		if (err)
 			goto error;
 	}
@@ -3701,7 +3733,16 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	link->mods_cnt = mods.mods_cnt;
 
 	if (inlines.sites_cnt) {
-		err = inline_sites_register(link, strict);
+		err = inline_sites_register(link, strict, &failed);
+		if (failed && strict) {
+			bpf_log(log,
+				"Function %s has inlined instance that can't be attached, %pS failed with %d.\n",
+				us.syms[failed->sym_idx], failed->kp.addr, err);
+		} else if (failed) {
+			bpf_log(log,
+				"Function %s has no entry and none of its inlined instances can be attached, %pS failed with %d.\n",
+				us.syms[failed->sym_idx], failed->kp.addr, err);
+		}
 		if (err)
 			goto error_modules;
 	}
@@ -3713,6 +3754,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 			goto error_inlines;
 	}
 
+	free_user_syms(&us);
 	return bpf_link_settle(&link_primer);
 
 error_inlines:
@@ -3721,9 +3763,11 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	kprobe_multi_put_modules(link->mods, link->mods_cnt);
 error_cleanup:
 	bpf_link_cleanup(&link_primer);
+	free_user_syms(&us);
 	return err;
 
 error:
+	free_user_syms(&us);
 	kprobe_multi_put_modules(mods.mods, mods.mods_cnt);
 	kfree(mods.mods);
 	kfree(link);
@@ -3734,8 +3778,10 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	return err;
 }
 #else /* !CONFIG_FPROBE */
-int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
+int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog,
+				 struct bpf_verifier_log *log)
 {
+	bpf_log(log, "This kernel does not support kprobe multi link.\n");
 	return -EOPNOTSUPP;
 }
 static u64 bpf_kprobe_multi_cookie(struct bpf_run_ctx *ctx)
-- 
2.56.1


  parent reply	other threads:[~2026-12-02 12:33 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 01/31] x86/ptrace: Add regs_get_dwarf_register function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 02/31] kprobes: Make the kprobe hash table size configurable Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 03/31] kprobes: Add enable_kprobes to enable multiple kprobes at once Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 04/31] module: Add module_sect_addr function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 05/31] bpf: Add bpf_get_btf_vmlinux_inline function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 06/31] bpf: Use goto labels for error path in bpf_kprobe_multi_link_attach Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 07/31] bpf: Add support to attach inlined functions with kprobe multi link Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 08/31] bpf: Add cookie support for kprobe multi inlined functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 09/31] bpf: Add link info " Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 10/31] bpf: Add fdinfo " Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 11/31] bpf: Add btf_for_each_module_inline function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 12/31] bpf: Change get_modules_for_addrs to use struct modules_array Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 13/31] tbpf: Add support to attach inlined functions in modules with kprobe multi link Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 14/31] bpf: Add BPF_F_KPROBE_MULTI_INLINE_STRICT flag for " Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 15/31] bpf: Add get_func_arg[_cnt] support for kprobe multi functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 16/31] bpf: Add get_func_arg[_cnt] support for kprobe multi inlined functions Jiri Olsa
2026-12-02 12:30 ` Jiri Olsa [this message]
2026-12-02 12:30 ` [PATCH RFC bpf-next 18/31] bpf: Add inlined functions for kprobe multi inline tests Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 19/31] libbpf: Add inline options to bpf_kprobe_multi_opts Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 20/31] libbpf: Print kernel log for failed kprobe multi attach Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 21/31] bpftool: Display inlined functions for kprobe multi link Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 22/31] selftests/bpf: Add inlined functions to bpf_testmod Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 23/31] selftests/bpf: Add kprobe multi inline attach test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 24/31] selftests/bpf: Add kprobe multi inline mixed test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 25/31] selftests/bpf: Add kprobe multi inline skip test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 26/31] selftests/bpf: Add kprobe multi inline fails test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 27/31] selftests/bpf: Add kprobe multi inline module test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 28/31] selftests/bpf: Add kprobe multi inline strict test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 29/31] selftests/bpf: Add kprobe multi inline args test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 30/31] selftests/bpf: Add kprobe multi inline bench attach test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 31/31] selftests/bpf: Add kprobe multi inline link info test Jiri Olsa

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=20261202123035.10335-18-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=almagui@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=qmo@kernel.org \
    --cc=song@kernel.org \
    --cc=x86@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

all inboxes | Powered by JetHome®