From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 2/6] bpf: Check many main programs in one set of insns
Date: Wed, 02 Dec 2026 01:18:17 +0000 [thread overview]
Message-ID: <sashiko-outbox-244597@kernel.org> (raw)
In-Reply-To: <20261202001639.2301557-3-alexei.starovoitov@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf: missing sleepable_async_cb propagation in
mark_sleepable_async_cb()
--
commit e81391289aecdf18a4497171d32e314bcc48b1a9
Author: Alexei Starovoitov <ast@kernel.org>
bpf: Check many main programs in one set of insns
This commit extends the BPF verifier to verify multiple main program entry
points within a single instruction buffer so that they can share common
subprograms.
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 15a73e3991f9f..58b30c1c2b0b1 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -23902,11 +24052,27 @@ static int do_check_all(struct bpf_verifier_env *env)
[ ... ]
> +/* Each main prog has passes of its own. They start from what the progs before it wrote. */
> +static int do_check_mains(struct bpf_verifier_env *env)
> +{
> + u64 max_cost = env->max_cost, max_mem = env->max_mem;
> + int err = 0;
> +
> + for (; env->pass_main < env->main_cnt && !err; env->pass_main++) {
> + env->max_cost = max_cost;
> + env->max_mem = max_mem;
> + bpf_flow_new_main(env);
> + err = do_check_all(env);
> + }
> + err = err ?: bpf_flow_drop_guards(env);
> if (!err && env->sleepable_async_cb)
> mark_sleepable_async_cb(env);
> - bpf_precision_free(env);
> - kvfree(initial);
> - kvfree(good_pass);
> return err;
> }
[ ... ]
> @@ -25057,6 +25232,138 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
> return 0;
> }
>
> +static bool can_share_subprogs(struct bpf_verifier_env *env, const struct bpf_main_prog *main)
> +{
> + const struct bpf_prog *prog = env->prog, *entry = main->prog;
> +
> + if (entry->type != prog->type)
> + return false;
> + if (entry->type == BPF_PROG_TYPE_STRUCT_OPS)
> + return entry->aux->st_ops == prog->aux->st_ops;
> + return entry->expected_attach_type == prog->expected_attach_type &&
> + entry->sleepable == prog->sleepable;
> +}
[ ... ]
> +/* An entry is a prog of one function. The code belongs to @prog. */
> +static int finish_entry(struct bpf_verifier_env *env, int s)
> +{
> + struct bpf_subprog_info *sub = &env->subprog_info[s];
> + struct bpf_prog *prog = env->prog, *entry, *func = prog->aux->func[s];
> + struct bpf_prog_aux *aux, *from = prog->aux;
> + u32 i, start = func->aux->subprog_start;
[ ... ]
> + memcpy(aux_fields(aux, max_ctx_offset), aux_fields(from, max_ctx_offset),
> + aux_fields_size(max_ctx_offset, cgroup_storage));
[ ... ]
> + for (; aux->used_map_cnt < from->used_map_cnt; aux->used_map_cnt++) {
> + if (bpf_prog_runs_sleepable(entry))
> + atomic64_inc(&aux->used_maps[aux->used_map_cnt]->sleepable_refcnt);
> + bpf_map_inc(aux->used_maps[aux->used_map_cnt]);
> + }
> +
> + /* Maps of progs were compared with the owner. Nothing here does tail calls. */
> + return bpf_prog_lock_ro(entry);
> +}
[Severity: Medium]
Can a non-sleepable struct_ops entry miss sleepable_async_cb and map
sleepable_refcnt accounting when the first entry in the load is sleepable?
can_share_subprogs() allows struct_ops entries in the same load to mix
sleepable and non-sleepable programs. When any entry registers a sleepable
async callback, do_check_mains() calls mark_sleepable_async_cb(env) with
env->prog->sleepable restored to the first entry's value:
kernel/bpf/verifier.c:mark_sleepable_async_cb() {
int i;
if (bpf_prog_runs_sleepable(env->prog))
return;
env->prog->aux->sleepable_async_cb = true;
for (i = 0; i < env->used_map_cnt; i++)
atomic64_inc(&env->used_maps[i]->sleepable_refcnt);
}
If the first entry is sleepable, mark_sleepable_async_cb() returns early
without setting env->prog->aux->sleepable_async_cb = true. finish_entry()
then copies sleepable_async_cb == false into every entry, so for a
non-sleepable entry in the same load bpf_prog_runs_sleepable(entry) is
false: finish_entry() skips incrementing sleepable_refcnt on its used_maps,
and freeing that entry uses call_rcu() instead of call_rcu_tasks_trace().
Setting env->prog->aux->sleepable_async_cb = true before the early return in
mark_sleepable_async_cb() would allow finish_entry() to propagate it to all
entries without double-incrementing sleepable_refcnt on env->prog's maps.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202001639.2301557-1-alexei.starovoitov@gmail.com?part=2
next prev parent reply other threads:[~2026-12-02 1:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 0:16 [PATCH bpf-next 0/6] bpf: Share subprogs between programs Alexei Starovoitov
2026-12-02 0:16 ` [PATCH bpf-next 1/6] bpf: Prepare for many main programs in one load Alexei Starovoitov
2026-12-02 0:16 ` [PATCH bpf-next 2/6] bpf: Check many main programs in one set of insns Alexei Starovoitov
2026-12-02 1:13 ` bot+bpf-ci
2026-12-02 1:18 ` sashiko-bot [this message]
2026-12-02 0:16 ` [PATCH bpf-next 3/6] bpf: Take entries at BPF_PROG_LOAD Alexei Starovoitov
2026-12-02 1:13 ` bot+bpf-ci
2026-12-02 0:16 ` [PATCH bpf-next 4/6] libbpf, bpftool: Share subprogs between programs Alexei Starovoitov
2026-12-02 1:13 ` bot+bpf-ci
2026-12-02 0:16 ` [PATCH bpf-next 5/6] libbpf: Share subprogs in light skeletons Alexei Starovoitov
2026-12-02 0:16 ` [PATCH bpf-next 6/6] selftests/bpf: Test programs that share subprogs Alexei Starovoitov
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-244597@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexei.starovoitov@gmail.com \
--cc=bpf@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox