From: sashiko-bot@kernel.org
To: "Jiri Olsa" <jolsa@kernel.org>
Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH RFC bpf-next 15/31] bpf: Add get_func_arg[_cnt] support for kprobe multi functions
Date: Wed, 02 Dec 2026 13:06:48 +0000 [thread overview]
Message-ID: <sashiko-outbox-245841@kernel.org> (raw)
In-Reply-To: <20261202123035.10335-16-jolsa@kernel.org>
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 <jolsa@kernel.org>
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 = true;
> }
>
> + if (func_id == BPF_FUNC_get_func_arg || func_id == BPF_FUNC_get_func_arg_cnt)
> + env->prog->call_get_func_arg = true;
> +
> /* a call that only a speculative state reaches is dead code */
> if (func_id == BPF_FUNC_override_return && !env->cur_state->speculative)
> env->prog->kprobe_override = 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 = 1;
prog->call_get_func_ip = 1;
if (prog_type == BPF_PROG_TYPE_TRACING &&
(eatype == BPF_TRACE_FSESSION || eatype == BPF_TRACE_FSESSION_MULTI))
prog->call_session_cookie = 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_lookup *lookup)
> }
> #endif
>
> +/* 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 = 0;
> + s32 id;
> +
> + id = bpf_find_btf_id(name, BTF_KIND_FUNC, &btf);
> + if (id < 0)
> + return 0;
> + t = btf_type_by_id(btf, btf_type_by_id(btf, id)->type);
> + if (btf_type_is_func_proto(t))
> + cnt = 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 = 0; i < cnt; i++) {
> + /* Function that has only inlined instances. */
> + if (!addrs[i])
> + continue;
> + name = syms ? syms[i] : kallsyms_lookup(addrs[i], NULL, NULL, NULL, buf);
> + if (name)
> + args_cnt[i] = 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202123035.10335-1-jolsa@kernel.org?part=15
next prev parent reply other threads:[~2026-12-02 13:06 UTC|newest]
Thread overview: 37+ 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 13:06 ` sashiko-bot [this message]
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:55 ` sashiko-bot
2026-12-02 12:30 ` [PATCH RFC bpf-next 17/31] bpf: Add log messages for kprobe multi inline attach Jiri Olsa
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:51 ` sashiko-bot
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 13:00 ` sashiko-bot
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:50 ` sashiko-bot
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=sashiko-outbox-245841@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jolsa@kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-reviews@lists.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.