From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796214786; b=AS9JwVLjdsJYDEbY9olaL7iQQexavJKl/fCZNciwn/qMWNg/J7yBe93w726n8VZqUwdW ckUHrVGI2FV/Du+8eV8ngHPoUuFOIR+671eQFW482Lqtq786MZ0qpyEoYfg9wudSVvvKO 4PX1/LR0cTAm3XRrlp6JgjBPq5iB7l1zOauuNRJr8qYJJqbeimOnLggouFEwjYlG2w4sf CQ8q2oED4IVt5Bk9tBDRuN6ZthpXcksZzFEAOoCV3kMOpn7DQuZACKBfCM8Y81PT/0o8C 02tbv5Iv4DsgTN6JXsWX3SD8u0j29TuYQzAngWTgwaH6t3LFM4LmbXt0SCO4diWjzyg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214786; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=/xrdHpb1TaNM/9ghQGkhXDmH1opRqrfGDN7+VvZlCa4=; b=YRFSWXoLDnO5j82NaNiKaVAfGUc70td8SOtkN4XyNM4/z+0iw+xJ/cvOlWT59zsi9tY6 2n1GuKHS60gXDMCRvRekvrB2ZbAX6oxFHK/DnsY6PpefuhMm8PuN2XilFmhN+2KZvxbOM oJay+47y7EM536pPsaQ+Uze0AeE/NI7KFbhCahme0SzQajMHcNghyOUok5hujEQndLfhg d2AEXkUxNm8mjj4ZoqL7svsbOm80dxJIF8bCa4UCmlTE5mMx/TvST5uCmtDtyQ47VMwBS zCDEzkpweSmdIoJNshcBNwhFFzhowD2hD1IuquqwhPyaXLIEiHJxYrQpd5px8ncHPlg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hs+KYrAI; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1A23606A325; Wed, 2 Dec 2026 12:33:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hs+KYrAI Received: by smtp.kernel.org (Postfix) with ESMTPSA id 975811F00893; Wed, 2 Dec 2026 12:33:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796214786; bh=/xrdHpb1TaNM/9ghQGkhXDmH1opRqrfGDN7+VvZlCa4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hs+KYrAIihL7WicDU2V7hrK9oVPcUvJEJdfjR0GQFnbTPRJbIx5RDoIb6rCiguMa3 B2lbpCykwCg78AnDDUQBPxta6BFc7q0kFjeISsR6dWG74tAFb4JWWdbcWVelFDa+de kKrgxUe2hibjzdko1K5WyDBRs241iSEPVCnJzQ8xevGWuEKdPDfOYKCpTN/yLSJ3DL qdCpLDCdG/vD7Hd3XNwbS4aBSN9GezL/4Cb9odIzKaD5/TDiQr1hwNLn6mNCTpco+M 039GN2qi5fw2oOxSdr1ZMcDcyXR34ChP7rDJqvz+d0Fi3UFQ/6jnbVG3y1A4aqf+Ub uXWgZao0UNzJg== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Song Liu , Yonghong Song , Quentin Monnet , Alan Maguire Subject: [PATCH RFC bpf-next 14/31] bpf: Add BPF_F_KPROBE_MULTI_INLINE_STRICT flag for kprobe multi link Date: Wed, 2 Dec 2026 13:30:18 +0100 Message-ID: <20261202123035.10335-15-jolsa@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202123035.10335-1-jolsa@kernel.org> References: <20261202123035.10335-1-jolsa@kernel.org> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The kprobe multi link with BPF_F_KPROBE_MULTI_INLINE flag skips inlined instances that fail to attach, so the link can end up attached just to some of the inlined instances of the function. Add BPF_F_KPROBE_MULTI_INLINE_STRICT flag for users that need all the inlined instances attached. With the flag the attach fails on the first inlined instance that fails to register and returns its error. The flag needs to be used together with BPF_F_KPROBE_MULTI_INLINE flag, the attach fails with -EINVAL otherwise. Signed-off-by: Jiri Olsa --- include/uapi/linux/bpf.h | 3 +++ kernel/trace/bpf_trace.c | 17 +++++++++++++---- tools/include/uapi/linux/bpf.h | 3 +++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index eee02f62f98b..3b97904851f4 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1373,6 +1373,9 @@ enum { /* Attach also to inlined function instances, skip those that fail. */ BPF_F_KPROBE_MULTI_INLINE = (1U << 1), + + /* With BPF_F_KPROBE_MULTI_INLINE, fail if inlined instance fails. */ + BPF_F_KPROBE_MULTI_INLINE_STRICT = (1U << 2), }; /* link_create.uprobe_multi.flags used in LINK_CREATE command for diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 71da54a6ea20..552a7420fb8c 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -3184,9 +3184,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. + * Fail if function has no entry and none of its instances registered, + * with @strict fail on the first instance that fails to register. */ -static int inline_sites_register(struct bpf_kprobe_multi_link *link) +static int inline_sites_register(struct bpf_kprobe_multi_link *link, bool strict) { struct inline_sites *inlines = &link->inlines; struct inline_site *site, *first = NULL; @@ -3212,6 +3213,8 @@ static int inline_sites_register(struct bpf_kprobe_multi_link *link) err = site->traceable ? register_kprobe(&site->kp) : -EINVAL; if (err == -ENOMEM) goto error; + if (err && strict) + goto error; if (err) { first_err = first_err ?: err; } else { @@ -3255,6 +3258,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr void __user *uaddrs; u64 *cookies = NULL; void __user *usyms; + bool strict; int err; /* no support for 32bit archs yet */ @@ -3276,14 +3280,19 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr return -EINVAL; flags = attr->link_create.kprobe_multi.flags; - if (flags & ~(BPF_F_KPROBE_MULTI_RETURN | BPF_F_KPROBE_MULTI_INLINE)) + if (flags & ~(BPF_F_KPROBE_MULTI_RETURN | BPF_F_KPROBE_MULTI_INLINE | + BPF_F_KPROBE_MULTI_INLINE_STRICT)) return -EINVAL; + strict = flags & BPF_F_KPROBE_MULTI_INLINE_STRICT; uaddrs = u64_to_user_ptr(attr->link_create.kprobe_multi.addrs); usyms = u64_to_user_ptr(attr->link_create.kprobe_multi.syms); if (!!uaddrs == !!usyms) return -EINVAL; + if (strict && !(flags & BPF_F_KPROBE_MULTI_INLINE)) + return -EINVAL; + if (flags & BPF_F_KPROBE_MULTI_INLINE) { /* * Inlined instances are resolved from function names and @@ -3426,7 +3435,7 @@ 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); + err = inline_sites_register(link, strict); if (err) goto error_modules; } diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index eee02f62f98b..3b97904851f4 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -1373,6 +1373,9 @@ enum { /* Attach also to inlined function instances, skip those that fail. */ BPF_F_KPROBE_MULTI_INLINE = (1U << 1), + + /* With BPF_F_KPROBE_MULTI_INLINE, fail if inlined instance fails. */ + BPF_F_KPROBE_MULTI_INLINE_STRICT = (1U << 2), }; /* link_create.uprobe_multi.flags used in LINK_CREATE command for -- 2.56.1