From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: Amery Hung <ameryhung@gmail.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
Nicholas Carlini <npc@anthropic.com>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@meta.com
Subject: [PATCH bpf-next v2 03/11] bpf: Append complete reference states
Date: Fri, 9 Oct 2026 13:27:50 -0700 [thread overview]
Message-ID: <20261009202759.50520-4-ihor.solodrai@linux.dev> (raw)
In-Reply-To: <20261009202759.50520-1-ihor.solodrai@linux.dev>
Reference acquisition exposes an uninitialized entry for each caller to
fill after insertion.
Accept a complete reference entry and return its id after insertion. Keep
lock and IRQ accounting and acquisition diagnostics in their callers.
Take the target state directly so acquisition can also serve queued
callback states.
No functional change.
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
kernel/bpf/verifier.c | 73 +++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 34 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 8d6812fee0c9..62b991f3c39a 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1497,51 +1497,53 @@ static int grow_stack_arg_slots(struct bpf_verifier_env *env,
return 0;
}
-/* Acquire a pointer id from the env and update the state->refs to include
- * this new pointer reference.
- * On success, returns a valid pointer id to associate with the register
- * On failure, returns a negative errno.
+/*
+ * Append @ref to @state->refs. Return its id, or a negative errno.
*/
-static struct bpf_reference_state *acquire_reference_state(struct bpf_verifier_env *env, int insn_idx)
+static int acquire_reference_state(struct bpf_verifier_state *state,
+ const struct bpf_reference_state *ref)
{
- struct bpf_verifier_state *state = env->cur_state;
int new_ofs = state->acquired_refs;
int err;
err = resize_reference_state(state, state->acquired_refs + 1);
if (err)
- return NULL;
- state->refs[new_ofs].insn_idx = insn_idx;
-
- return &state->refs[new_ofs];
+ return err;
+ state->refs[new_ofs] = *ref;
+ return ref->id;
}
static int acquire_reference(struct bpf_verifier_env *env, int insn_idx, int parent_id)
{
- struct bpf_reference_state *s;
+ struct bpf_reference_state ref = {
+ .type = REF_TYPE_PTR,
+ .id = ++env->id_gen,
+ .insn_idx = insn_idx,
+ .parent_id = parent_id,
+ };
+ int id;
- s = acquire_reference_state(env, insn_idx);
- if (!s)
- return -ENOMEM;
- s->type = REF_TYPE_PTR;
- s->id = ++env->id_gen;
- s->parent_id = parent_id;
- bpf_diag_record_ref_acquire(env, insn_idx, s->id);
- return s->id;
+ id = acquire_reference_state(env->cur_state, &ref);
+ if (id >= 0)
+ bpf_diag_record_ref_acquire(env, insn_idx, id);
+ return id;
}
static int acquire_lock_state(struct bpf_verifier_env *env, int insn_idx, enum ref_state_type type,
int id, void *ptr)
{
struct bpf_verifier_state *state = env->cur_state;
- struct bpf_reference_state *s;
+ struct bpf_reference_state ref = {
+ .type = type,
+ .id = id,
+ .insn_idx = insn_idx,
+ .ptr = ptr,
+ };
+ int err;
- s = acquire_reference_state(env, insn_idx);
- if (!s)
- return -ENOMEM;
- s->type = type;
- s->id = id;
- s->ptr = ptr;
+ err = acquire_reference_state(state, &ref);
+ if (err < 0)
+ return err;
state->active_locks++;
state->active_lock_id = id;
@@ -1554,18 +1556,21 @@ static int acquire_lock_state(struct bpf_verifier_env *env, int insn_idx, enum r
static int acquire_irq_state(struct bpf_verifier_env *env, int insn_idx)
{
struct bpf_verifier_state *state = env->cur_state;
- struct bpf_reference_state *s;
+ struct bpf_reference_state ref = {
+ .type = REF_TYPE_IRQ,
+ .id = ++env->id_gen,
+ .insn_idx = insn_idx,
+ };
+ int id;
- s = acquire_reference_state(env, insn_idx);
- if (!s)
- return -ENOMEM;
- s->type = REF_TYPE_IRQ;
- s->id = ++env->id_gen;
+ id = acquire_reference_state(state, &ref);
+ if (id < 0)
+ return id;
- state->active_irq_id = s->id;
+ state->active_irq_id = id;
bpf_diag_record_context(env, insn_idx, BPF_DIAG_CONTEXT_IRQ, true,
bpf_diag_irq_depth(state));
- return s->id;
+ return id;
}
static void release_reference_state(struct bpf_verifier_state *state, int idx)
--
2.56.0
next prev parent reply other threads:[~2026-10-09 20:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 20:27 [PATCH bpf-next v2 00/11] bpf: Scope callback arguments to their frame Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 01/11] bpf: Set up callee state outside of setup_func_entry() Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 02/11] bpf: Pass the owning verifier state to callback setters Ihor Solodrai
2026-10-09 20:27 ` Ihor Solodrai [this message]
2026-10-09 20:27 ` [PATCH bpf-next v2 04/11] bpf: Separate reference removal from descendant invalidation Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 05/11] bpf: Share map-backed callback register setup Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 06/11] bpf: Rely on callback frame initialization defaults Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 07/11] bpf: Introduce REF_TYPE_FRAME in the verifier Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 08/11] bpf: Scope the bpf_user_ringbuf_drain() dynptr to its callback frame Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 09/11] selftests/bpf: Cover the user ringbuf callback dynptr lifetime Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 10/11] bpf: Scope the bpf_for_each_map_elem() array key to the callback frame Ihor Solodrai
2026-10-09 20:27 ` [PATCH bpf-next v2 11/11] selftests/bpf: Cover callback-frame map key lifetime Ihor Solodrai
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=20261009202759.50520-4-ihor.solodrai@linux.dev \
--to=ihor.solodrai@linux.dev \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=memxor@gmail.com \
--cc=npc@anthropic.com \
/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
all inboxes | Powered by JetHome®