From: Eduard Zingerman <eddyz87@gmail.com>
To: Puranjay Mohan <puranjay@kernel.org>, bpf@vger.kernel.org
Cc: Puranjay Mohan <puranjay12@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
kernel-team@meta.com
Subject: Re: [PATCH bpf-next v3 1/6] bpf: Add KF_ACQUIRE and KF_RELEASE support for iterators
Date: Mon, 23 Feb 2026 12:41:03 -0800 [thread overview]
Message-ID: <9ae642bd94696a019f62aca5f49da3b3d941a927.camel@gmail.com> (raw)
In-Reply-To: <20260223174659.2749964-2-puranjay@kernel.org>
On Mon, 2026-02-23 at 09:46 -0800, Puranjay Mohan wrote:
[...]
> @@ -1083,6 +1084,23 @@ static int mark_stack_slots_iter(struct bpf_verifier_env *env,
> return 0;
> }
>
> +/*
> + * Release the acquired reference tracked by iter_st->id, if any.
> + * Used during auto-release in _next, DRAINED handling, and _destroy.
> + */
> +static int iter_release_acquired_ref(struct bpf_verifier_env *env,
> + struct bpf_reg_state *iter_st)
> +{
> + int err;
> +
> + if (!iter_st->id)
> + return 0;
> + err = release_reference(env, iter_st->id);
> + if (!err)
> + iter_st->id = 0;
Nit: maybe drop the `!err` check?
It requires a few moments to process mentally and the verifier
should stop on this error anyway.
> + return err;
> +}
> +
> static int unmark_stack_slots_iter(struct bpf_verifier_env *env,
> struct bpf_reg_state *reg, int nr_slots)
> {
[...]
> @@ -9178,8 +9204,11 @@ static int process_iter_next_call(struct bpf_verifier_env *env, int insn_idx,
> /* mark current iter state as drained and assume returned NULL */
> cur_iter->iter.state = BPF_ITER_STATE_DRAINED;
> __mark_reg_const_zero(env, &cur_fr->regs[BPF_REG_0]);
> -
> - return 0;
> + /*
> + * If _next acquired a ref (KF_ACQUIRE), release it in the DRAINED branch since NULL
> + * was returned.
> + */
> + return iter_release_acquired_ref(env, cur_iter);
Nit: Check that `_next` is KF_ACQUIRE here?
Not strictly needed for this patch but is a bit more consistent.
E.g. consider some future iterator that acquires reference on creation
and not on `_next`.
> }
>
> static bool arg_type_is_mem_size(enum bpf_arg_type type)
> @@ -14197,6 +14226,17 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
>
> if (meta.initialized_dynptr.ref_obj_id) {
> err = unmark_stack_slots_dynptr(env, reg);
> + } else if (base_type(reg->type) == PTR_TO_STACK) {
> + struct bpf_reg_state *iter_st;
> +
> + iter_st = get_iter_from_state(env->cur_state, &meta);
> + if (!iter_st->id) {
> + verbose(env, "no acquired reference to release\n");
> + return -EINVAL;
> + }
> + err = release_reference(env, iter_st->id);
> + if (!err)
> + iter_st->id = 0;
Nit: iter_release_acquired_ref()?
> } else {
> err = release_reference(env, reg->ref_obj_id);
> if (err)
[...]
next prev parent reply other threads:[~2026-02-23 20:41 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-23 17:46 [PATCH bpf-next v3 0/6] Introduce KF_FORBID_SLEEP modifier for acquire/release kfuncs Puranjay Mohan
2026-02-23 17:46 ` [PATCH bpf-next v3 1/6] bpf: Add KF_ACQUIRE and KF_RELEASE support for iterators Puranjay Mohan
2026-02-23 19:59 ` Mykyta Yatsenko
2026-02-23 20:41 ` Eduard Zingerman [this message]
2026-02-23 17:46 ` [PATCH bpf-next v3 2/6] bpf: consolidate sleepable context error message printing Puranjay Mohan
2026-02-23 20:06 ` Mykyta Yatsenko
2026-02-23 20:27 ` Eduard Zingerman
2026-02-23 17:46 ` [PATCH bpf-next v3 3/6] bpf: Add KF_FORBID_SLEEP modifier for KF_ACQUIRE kfuncs Puranjay Mohan
2026-02-23 22:14 ` Eduard Zingerman
2026-02-24 15:24 ` Puranjay Mohan
2026-02-24 18:17 ` Eduard Zingerman
2026-02-24 19:41 ` Kumar Kartikeya Dwivedi
2026-02-23 17:46 ` [PATCH bpf-next v3 4/6] bpf: Move locking to bpf_iter_task_vma_next() Puranjay Mohan
2026-02-23 17:46 ` [PATCH bpf-next v3 5/6] bpf: Add split iteration support to task_vma iterator Puranjay Mohan
2026-02-23 17:46 ` [PATCH bpf-next v3 6/6] selftests/bpf: Add tests for split " Puranjay Mohan
2026-02-24 1:49 ` [PATCH bpf-next v3 0/6] Introduce KF_FORBID_SLEEP modifier for acquire/release kfuncs Alexei Starovoitov
2026-02-24 11:24 ` Puranjay Mohan
2026-02-24 18:00 ` Alexei Starovoitov
2026-02-24 18:55 ` Eduard Zingerman
2026-02-24 19:32 ` Alexei Starovoitov
2026-02-24 19:47 ` Puranjay Mohan
2026-02-24 19:51 ` Puranjay Mohan
2026-02-24 20:15 ` Eduard Zingerman
2026-02-24 20:20 ` Puranjay Mohan
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=9ae642bd94696a019f62aca5f49da3b3d941a927.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@meta.com \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
--cc=mykyta.yatsenko5@gmail.com \
--cc=puranjay12@gmail.com \
--cc=puranjay@kernel.org \
/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