From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
kkd@meta.com, kernel-team@meta.com
Subject: [PATCH bpf-next v6 2/6] bpf: Propagate async callback instructions to scheduling subprograms
Date: Wed, 5 Aug 2026 03:15:10 +0200 [thread overview]
Message-ID: <20260805011517.1717238-3-memxor@gmail.com> (raw)
In-Reply-To: <20260805011517.1717238-1-memxor@gmail.com>
Asynchronous callbacks are explored as fresh frame-zero verifier states,
so normal callee-to-caller accounting cannot propagate their instruction
budget to the subprograms which scheduled them.
When an async callback is queued, save the active subprogram IDs in a fixed
async_stats_subprog_ids array and record its length. Copy this metadata with
the verifier state. When an async frame-zero path finishes, add its inclusive
subtotal to every saved scheduling subprogram.
If an async callback schedules another callback, preserve its saved IDs before
appending the active call chain. This propagates nested callback work to both
the immediate callback and the original scheduling subprograms.
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
include/linux/bpf_verifier.h | 2 ++
kernel/bpf/verifier.c | 31 +++++++++++++++++++++++++------
2 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 9de45ade473b..42fa464c520f 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -447,6 +447,8 @@ static_assert(MAX_BPF_STACK / 8 <= (1 << 6));
struct bpf_verifier_state {
/* call stack tracking */
struct bpf_func_state *frame[MAX_CALL_FRAMES];
+ u32 async_stats_subprog_ids[MAX_CALL_FRAMES];
+ u32 async_stats_subprog_cnt;
struct bpf_verifier_state *parent;
/* Acquired reference states */
struct bpf_reference_state *refs;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 88e7ea6fbe73..47f3791530de 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1632,6 +1632,9 @@ int bpf_copy_verifier_state(struct bpf_verifier_state *dst_state,
dst_state->callback_unroll_depth = src->callback_unroll_depth;
dst_state->may_goto_depth = src->may_goto_depth;
dst_state->equal_state = src->equal_state;
+ memcpy(dst_state->async_stats_subprog_ids, src->async_stats_subprog_ids,
+ sizeof(dst_state->async_stats_subprog_ids));
+ dst_state->async_stats_subprog_cnt = src->async_stats_subprog_cnt;
for (i = 0; i <= src->curframe; i++) {
dst = dst_state->frame[i];
if (!dst) {
@@ -2261,6 +2264,8 @@ static struct bpf_verifier_state *push_async_cb(struct bpf_verifier_env *env,
{
struct bpf_verifier_stack_elem *elem;
struct bpf_func_state *frame;
+ int i;
+ u32 cnt;
elem = kzalloc_obj(struct bpf_verifier_stack_elem, GFP_KERNEL_ACCOUNT);
if (!elem)
@@ -2293,6 +2298,12 @@ static struct bpf_verifier_state *push_async_cb(struct bpf_verifier_env *env,
0 /* frameno within this callchain */,
subprog /* subprog number within this prog */);
elem->st.frame[0] = frame;
+ cnt = env->cur_state->async_stats_subprog_cnt;
+ memcpy(elem->st.async_stats_subprog_ids, env->cur_state->async_stats_subprog_ids,
+ cnt * sizeof(elem->st.async_stats_subprog_ids[0]));
+ for (i = 0; i <= env->cur_state->curframe; i++)
+ elem->st.async_stats_subprog_ids[cnt++] = env->cur_state->frame[i]->subprogno;
+ elem->st.async_stats_subprog_cnt = cnt;
return &elem->st;
}
@@ -9818,9 +9829,9 @@ static void account_processed_insn(struct bpf_verifier_env *env)
env->subprog_info[frame->subprogno].insns_own++;
}
-static void account_processed_insns(struct bpf_verifier_env *env,
- struct bpf_func_state *callee,
- struct bpf_func_state *caller)
+static u32 account_processed_insns(struct bpf_verifier_env *env,
+ struct bpf_func_state *callee,
+ struct bpf_func_state *caller)
{
u32 insns = callee->insns_subtotal;
@@ -9828,16 +9839,24 @@ static void account_processed_insns(struct bpf_verifier_env *env,
if (caller)
caller->insns_subtotal += insns;
callee->insns_subtotal = 0;
+ return insns;
}
static void account_current_path(struct bpf_verifier_env *env)
{
struct bpf_verifier_state *state = env->cur_state;
- int frame;
+ u32 insns;
+ int frame, i;
for (frame = state->curframe; frame >= 0; frame--)
- account_processed_insns(env, state->frame[frame],
- frame ? state->frame[frame - 1] : NULL);
+ insns = account_processed_insns(env, state->frame[frame],
+ frame ? state->frame[frame - 1] : NULL);
+
+ if (!state->async_stats_subprog_cnt)
+ return;
+
+ for (i = 0; i < state->async_stats_subprog_cnt; i++)
+ env->subprog_info[state->async_stats_subprog_ids[i]].insns_total += insns;
}
/* Are we currently verifying the callback for a rbtree helper that must
--
2.53.0
next prev parent reply other threads:[~2026-08-05 1:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 1:15 [PATCH bpf-next v6 0/6] Improve stack depth verification stats output Kumar Kartikeya Dwivedi
2026-08-05 1:15 ` [PATCH bpf-next v6 1/6] bpf: Track verifier instruction stats for each subprogram Kumar Kartikeya Dwivedi
2026-08-05 1:26 ` sashiko-bot
2026-08-05 1:15 ` Kumar Kartikeya Dwivedi [this message]
2026-08-05 1:40 ` [PATCH bpf-next v6 2/6] bpf: Propagate async callback instructions to scheduling subprograms sashiko-bot
2026-08-05 18:18 ` Eduard Zingerman
2026-08-07 22:05 ` Andrii Nakryiko
2026-08-07 22:12 ` Eduard Zingerman
2026-08-05 1:15 ` [PATCH bpf-next v6 3/6] bpf: Show more useful info in stack depth stats Kumar Kartikeya Dwivedi
2026-08-05 1:28 ` sashiko-bot
2026-08-05 1:15 ` [PATCH bpf-next v6 4/6] selftests/bpf: Adjust veristat stack depth parsing Kumar Kartikeya Dwivedi
2026-08-05 1:15 ` [PATCH bpf-next v6 5/6] selftests/bpf: Test stack depth stats without BTF subprog names Kumar Kartikeya Dwivedi
2026-08-05 1:15 ` [PATCH bpf-next v6 6/6] selftests/bpf: Test subprogram instruction statistics Kumar Kartikeya Dwivedi
2026-08-05 1:23 ` sashiko-bot
2026-08-07 22:05 ` [PATCH bpf-next v6 0/6] Improve stack depth verification stats output Andrii Nakryiko
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=20260805011517.1717238-3-memxor@gmail.com \
--to=memxor@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=kkd@meta.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 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.