BPF List
 help / color / mirror / Atom feed
* [PATCH] bpf: reduce kernel stack usage in bpf_guess_first_trips()
@ 2026-11-24 14:01 Arnd Bergmann
  2026-11-24 14:09 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Arnd Bergmann @ 2026-11-24 14:01 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi
  Cc: Arnd Bergmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	Jiri Olsa, Emil Tsalapatis, Ihor Solodrai, bpf

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-24 20:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 14:01 [PATCH] bpf: reduce kernel stack usage in bpf_guess_first_trips() Arnd Bergmann
2026-11-24 14:09 ` sashiko-bot
2026-11-24 19:51 ` Alexei Starovoitov
2026-11-24 20:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox