BPF List
 help / color / mirror / Atom feed
* [PATCH] bpf: test_run: reduce kernel stack usage
@ 2026-05-15 11:25 Arnd Bergmann
  2026-05-15 14:47 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2026-05-15 11:25 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Jesper Dangaard Brouer,
	John Fastabend, Martin KaFai Lau,
	Toke Høiland-Jørgensen
  Cc: Arnd Bergmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	Jiri Olsa, Simon Horman, Stanislav Fomichev, bpf, netdev,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

The xdp_test_data structure is really too large to put on the stack
and results in one of the largest stack frames in the kernel:

net/bpf/test_run.c: In function 'bpf_test_run_xdp_live':
net/bpf/test_run.c:387:1: error: the frame size of 1608 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]

Reduce this using dynamic allocation, which avoids around 1KB of
stack usage.

Fixes: b530e9e1063e ("bpf: Add "live packet" mode for XDP in BPF_PROG_RUN")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
found while build testing s390 with gcc-16, had not seen this on
other architectures before.
---
 net/bpf/test_run.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index c9aea7052ba7..763891df02be 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -362,27 +362,31 @@ static int bpf_test_run_xdp_live(struct bpf_prog *prog, struct xdp_buff *ctx,
 				 u32 repeat, u32 batch_size, u32 *time)
 
 {
-	struct xdp_test_data xdp = { .batch_size = batch_size };
+	struct xdp_test_data *xdp __free(kfree) = kzalloc_obj(*xdp);
 	struct bpf_test_timer t = {};
 	int ret;
 
+	if (!xdp)
+		return -ENOMEM;
+
 	if (!repeat)
 		repeat = 1;
 
-	ret = xdp_test_run_setup(&xdp, ctx);
+	xdp->batch_size = batch_size;
+	ret = xdp_test_run_setup(xdp, ctx);
 	if (ret)
 		return ret;
 
 	bpf_test_timer_enter(&t);
 	do {
-		xdp.frame_cnt = 0;
-		ret = xdp_test_run_batch(&xdp, prog, repeat - t.i);
+		xdp->frame_cnt = 0;
+		ret = xdp_test_run_batch(xdp, prog, repeat - t.i);
 		if (unlikely(ret < 0))
 			break;
-	} while (bpf_test_timer_continue(&t, xdp.frame_cnt, repeat, &ret, time));
+	} while (bpf_test_timer_continue(&t, xdp->frame_cnt, repeat, &ret, time));
 	bpf_test_timer_leave(&t);
 
-	xdp_test_run_teardown(&xdp);
+	xdp_test_run_teardown(xdp);
 	return ret;
 }
 
-- 
2.39.5


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

* Re: [PATCH] bpf: test_run: reduce kernel stack usage
  2026-05-15 11:25 [PATCH] bpf: test_run: reduce kernel stack usage Arnd Bergmann
@ 2026-05-15 14:47 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2026-05-15 14:47 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Jesper Dangaard Brouer,
	John Fastabend, Martin KaFai Lau,
	Toke Høiland-Jørgensen, Arnd Bergmann, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Simon Horman,
	Stanislav Fomichev, bpf, Network Development, LKML

On Fri, May 15, 2026 at 4:31 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> The xdp_test_data structure is really too large to put on the stack
> and results in one of the largest stack frames in the kernel:
>
> net/bpf/test_run.c: In function 'bpf_test_run_xdp_live':
> net/bpf/test_run.c:387:1: error: the frame size of 1608 bytes is larger than 1536 bytes [-Werror=frame-larger-than=]
>
> Reduce this using dynamic allocation, which avoids around 1KB of
> stack usage.

1k?
pahole -C xdp_test_data
/* size: 192, cachelines: 3, members: 9 */
/* sum members: 120, holes: 1, sum holes: 56 */
/* padding: 16 */
/* paddings: 1, sum paddings: 36 */

what s390 doing to make it huge?

Probably better to rearrange the field and fix the root cause.

pw-bot: cr

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

end of thread, other threads:[~2026-05-15 14:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-15 11:25 [PATCH] bpf: test_run: reduce kernel stack usage Arnd Bergmann
2026-05-15 14:47 ` Alexei Starovoitov

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