From: Arnd Bergmann <arnd@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
bpf@vger.kernel.org
Subject: [PATCH] bpf: reduce kernel stack usage in bpf_guess_first_trips()
Date: Tue, 24 Nov 2026 15:01:31 +0100 [thread overview]
Message-ID: <20261124140155.1555535-1-arnd@kernel.org> (raw)
From: Arnd Bergmann <arnd@arndb.de>
The large 'bpf_verifier_state' structure causes the newly added
bpf_guess_first_trips() function to have one of the largest stack frames
in the kernel. With CONFIG_KASAN_STACK this exceeds the warning limit
I have set on arm64:
kernel/bpf/equation_join.c: In function 'bpf_guess_first_trips':
kernel/bpf/equation_join.c:1502:1: error: the frame size of 1552 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]
There are already some dynamic allocations in this code path, so
do the same here and use kzalloc_obj() as well here.
Fixes: 97f92b0c1df6 ("bpf: Check the body of a counted loop once")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
kernel/bpf/equation_join.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/kernel/bpf/equation_join.c b/kernel/bpf/equation_join.c
index d7ad7fb52ed6..4123a8448237 100644
--- a/kernel/bpf/equation_join.c
+++ b/kernel/bpf/equation_join.c
@@ -1455,7 +1455,7 @@ int bpf_guess_first_trips(struct bpf_verifier_env *env, struct bpf_verifier_stat
struct bpf_loop *loop)
{
struct loop_stack_entry *e = bpf_top_loop(st->frame[st->curframe]);
- struct bpf_verifier_state next = {};
+ struct bpf_verifier_state *next;
struct bpf_loop_steps *steps;
u64 trips = U64_MAX, xreg;
struct scalar *s;
@@ -1488,15 +1488,18 @@ int bpf_guess_first_trips(struct bpf_verifier_env *env, struct bpf_verifier_stat
return 0;
e->exit_threshold = e->trip_index.r64.base + trips;
add_iv_threshold(env, loop, e->exit_threshold, 1, THRESHOLD_EXIT_JUMP, U32_MAX);
+ next = kzalloc_obj(*next);
+ if (!next)
+ return -ENOMEM;
for (i = 0; i < min(trips, 2) && !err; i++) {
- err = bpf_copy_verifier_state(env, &next, st);
- if (err || !move_by_steps(env, &next, steps))
+ err = bpf_copy_verifier_state(env, next, st);
+ if (err || !move_by_steps(env, next, steps))
break;
- err = bpf_states_join(env, st, &next, loop, true);
+ err = bpf_states_join(env, st, next, loop, true);
env->extra_values = true;
bitmap_or(loop->nonlinear_xregs, loop->nonlinear_xregs, steps->nonlinear_xregs,
MAX_BPF_XREG);
}
- bpf_free_verifier_state(env, &next, false);
+ bpf_free_verifier_state(env, next, true);
return err ?: i > 0;
}
--
2.53.0
next reply other threads:[~2026-11-24 14:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 14:01 Arnd Bergmann [this message]
2026-11-24 14:09 ` [PATCH] bpf: reduce kernel stack usage in bpf_guess_first_trips() sashiko-bot
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=20261124140155.1555535-1-arnd@kernel.org \
--to=arnd@kernel.org \
--cc=andrii@kernel.org \
--cc=arnd@arndb.de \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--cc=yonghong.song@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