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=1796216809; b=vP7dyvhgRFjZyfHDcrXkUUsltNB8DpsKPfAXqP5rPzOsiTJoJf4GhF1JAjGQ+wa2zQjz dq1N8xePhJ8uiDx6fQqb2XYvh1vXqN6kmTUR2PzxZhoVt7t6UKslKkEVhA0/5WLUM5Bo1 nY2WjYtDdfgHzLUYud8wkXaGAIq+iLtKYkBrue08sg6OzdyZ3X8QuwDZK2vkYawxyWzR0 0JkgC08mAzmX40Y1w2SfKFx3AAO/dtnm2L3zbzBDud2CjnkBWrYfTLsDxGXnojnE3LZmp RrUuPrAT5R9ebjVShXoFrKCjw8G4HlRPa7RlPLUMHmkhAstzpFMe+SoRE6FbagTTWYA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796216809; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=8EmeSPumKsz2VJbsR9lguHkXMYXH9IqNdr4HV0U1IKA=; b=VJiy7bMFwdKuKXU/GoVyhPu0V5B8DsW48t0IgRENQsgVcG1uzIKov8w59xBqcDcUaAn6 X34wFFYH4Sp4Qq00GRdTaMwCZ6hMnjAxZkOKodCr1AOI7gG6Xj0OLNrw9eEyegGIjwXf/ 7+lcSqr4nAMjx/BmzNoY8M+da4KZ9amDxAKFSv4Jlgz7CSVaDP2DYR3GZ+R8HHnZllfXk t1VrDSWfIUtsKMV6DKkQWaz82/bSnze4WAptTIRQmIN8ifWSh5fJ1z14Bb9zF0+33jDVo Mr9+3FyYj+ltYPsRi+YBdU/Gz2QcH9H+y+QWwdRzq1c1+AG+3FuqZ0uEO+uRomRRVEQ== 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=JkbR7Q+h; 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 33414606A31A; Wed, 2 Dec 2026 13:06:48 +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=JkbR7Q+h Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8329B1F00893; Wed, 2 Dec 2026 13:06:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796216808; bh=8EmeSPumKsz2VJbsR9lguHkXMYXH9IqNdr4HV0U1IKA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=JkbR7Q+hExJ6kELcF42e3+H95QpNIhH5rxN1888Mal/SH+X4liseYT4u1S+dOoAIy iKDpBWtfyX5+5IsdpYURc1Zu1CzCUJB5MZEQeYoL/9gk7ukdxb4nQulmvfrzMkHoN7 tCsjIRQwMUO2lqIKtkXZqo7izMEzftCru09yrN33/c9K0iNSjg0ljL20zVNgtn9Jhu HqVDn/b3sIIM8yrZkut2hFDVfSnEuEKOz5tcRGbqEELFhIyDCZNKXWvPowQ1yUBqpq UjMsvMhNNrWqsqQOkuvPGWNgQW8tPk2RzmLXVF93pD3gF7I4fiwh7BNIGajWwaAQxY zxpxAiRJQYtuw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RFC bpf-next 15/31] bpf: Add get_func_arg[_cnt] support for kprobe multi functions Reply-To: sashiko-reviews@lists.linux.dev To: "Jiri Olsa" Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org In-Reply-To: <20261202123035.10335-16-jolsa@kernel.org> References: <20261202123035.10335-1-jolsa@kernel.org> <20261202123035.10335-16-jolsa@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 13:06:48 +0000 X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] bpf: missing call_get_func_arg propagation for tail calls and freplace - [Medium] bpf: unscoped bpf_find_btf_id() lookup in kprobe_multi_args_cnt() -- commit 70cd82b71680ac2bf4eba159cfcb717936c5ada2 Author: Jiri Olsa bpf: Add get_func_arg[_cnt] support for kprobe multi functions This commit adds bpf_get_func_arg() and bpf_get_func_arg_cnt() helper support for kprobe multi programs by looking up each attached function's argument count in BTF at attach time and reading argument values from ftrace_regs at runtime. > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index dc2a533098ca1..a82ff5c709c7e 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -13479,6 +13479,9 @@ static int check_helper_call(struct bpf_verifier_= env *env, struct bpf_insn *insn > env->prog->call_get_func_ip =3D true; > } > =20 > + if (func_id =3D=3D BPF_FUNC_get_func_arg || func_id =3D=3D BPF_FUNC_get= _func_arg_cnt) > + env->prog->call_get_func_arg =3D true; > + > /* a call that only a speculative state reaches is dead code */ > if (func_id =3D=3D BPF_FUNC_override_return && !env->cur_state->specula= tive) > env->prog->kprobe_override =3D 1; [Severity: Medium] Should call_get_func_arg also be set when a program uses BPF_FUNC_tail_call (and handled for BPF_PROG_TYPE_EXT freplace attachments)? In bpf_do_misc_fixups(), BPF_FUNC_tail_call conservatively sets prog->call_get_func_ip and prog->call_session_cookie on the root program, because a tail-called program can invoke those helpers at runtime: kernel/bpf/fixups.c:bpf_do_misc_fixups() { ... prog->cb_access =3D 1; prog->call_get_func_ip =3D 1; if (prog_type =3D=3D BPF_PROG_TYPE_TRACING && (eatype =3D=3D BPF_TRACE_FSESSION || eatype =3D=3D BPF_TRACE_FSESSIO= N_MULTI)) prog->call_session_cookie =3D 1; ... } Without setting prog->call_get_func_arg there as well, attaching a root kprobe_multi program that tail-calls (or is extended via freplace by) a program calling bpf_get_func_arg() or bpf_get_func_arg_cnt() leaves link->args_cnt NULL in bpf_kprobe_multi_link_attach(), so those helpers fail with -EOPNOTSUPP or return 0 at runtime. > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > index 76db21880accb..3531d35d0ad72 100644 > --- a/kernel/trace/bpf_trace.c > +++ b/kernel/trace/bpf_trace.c [ ... ] > @@ -3068,6 +3157,49 @@ static int inline_lookup_modules(struct inline_loo= kup *lookup) > } > #endif > =20 > +/* Get number of arguments of the function from its BTF, zero if there's= none. */ > +static u8 func_args_cnt(const char *name) > +{ > + const struct btf_type *t; > + struct btf *btf; > + u32 cnt =3D 0; > + s32 id; > + > + id =3D bpf_find_btf_id(name, BTF_KIND_FUNC, &btf); > + if (id < 0) > + return 0; > + t =3D btf_type_by_id(btf, btf_type_by_id(btf, id)->type); > + if (btf_type_is_func_proto(t)) > + cnt =3D btf_type_vlen(t); > + /* Do not count variable arguments. */ > + if (cnt && !btf_params(t)[cnt - 1].type) > + cnt--; > + btf_put(btf); > + return min(cnt, U8_MAX); > +} > + > +/* > + * Get number of arguments for @cnt functions in @addrs, the function > + * name is taken from @syms if it's provided, otherwise it's resolved > + * from the function address. > + */ > +static void kprobe_multi_args_cnt(u8 *args_cnt, const char **syms, > + unsigned long *addrs, u32 cnt) > +{ > + char buf[KSYM_NAME_LEN]; > + const char *name; > + u32 i; > + > + for (i =3D 0; i < cnt; i++) { > + /* Function that has only inlined instances. */ > + if (!addrs[i]) > + continue; > + name =3D syms ? syms[i] : kallsyms_lookup(addrs[i], NULL, NULL, NULL, = buf); > + if (name) > + args_cnt[i] =3D func_args_cnt(name); > + } > +} [Severity: Medium] Can func_args_cnt() look up BTF by bare symbol name across all BTF objects instead of scoping the lookup to the BTF owning addrs[i]? Because bpf_find_btf_id() searches vmlinux BTF first and then walks every module BTF in btf_idr, a traced module function that shares a name with a static function in vmlinux or an earlier module resolves against the wrong BTF_KIND_FUNC entry and records the wrong argument count in args_cnt[i]. In addition, for every attached address not present in vmlinux BTF (such as module symbols or compiler clones like .isra.0 and .constprop.0), bpf_find_btf_id() cycles spin_lock_bh(&btf_idr_lock) across all loaded module BTFs, and each btf_find_by_name_kind(mod_btf, ...) call recursively re-searches base_btf (vmlinux BTF) before checking the module BTF. Looking up addrs[i]'s owning module (or vmlinux when it is a core kernel address) and searching only that BTF object would avoid both the wrong-symbol match and the O(N * M) module BTF scan during attach. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202123035.1033= 5-1-jolsa@kernel.org?part=3D15