Linux Trace Kernel
 help / color / mirror / Atom feed
From: Mike Bazov via B4 Relay <devnull+mike.bazov.gmail.com@kernel.org>
To: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>
Cc: Martin KaFai Lau <martin.lau@linux.dev>,
	 Eduard Zingerman <eddyz87@gmail.com>,
	 Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Song Liu <song@kernel.org>,
	 Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	 John Fastabend <john.fastabend@gmail.com>,
	 Emil Tsalapatis <emil@etsalapatis.com>,
	 Ihor Solodrai <ihor.solodrai@linux.dev>,
	 Steven Rostedt <rostedt@goodmis.org>,
	 Masami Hiramatsu <mhiramat@kernel.org>,
	 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	 JP Kobryn <jp.kobryn@linux.dev>,
	linux-trace-kernel@vger.kernel.org,
	 linux-kernel@vger.kernel.org, Mike Bazov <mike.bazov@gmail.com>
Subject: [PATCH bpf-next 3/4] selftests/bpf: Test private-stack struct_ops progs in prog arrays
Date: Wed, 02 Dec 2026 15:15:15 +0200	[thread overview]
Message-ID: <20261202-followup-rt-stops-v1-3-22562be9ddb0@gmail.com> (raw)
In-Reply-To: <20261202-followup-rt-stops-v1-0-22562be9ddb0@gmail.com>

From: Mike Bazov <mike.bazov@gmail.com>

Load two bpf_testmod test_1 programs, which request a private stack: one
with 400 bytes of stack, which gets it, and one under
BPF_PRIV_STACK_MIN_SIZE, which doesn't. The small one goes into a prog
array first, so that the big one is compatible with the array; the big
one is then refused with -EINVAL.

Signed-off-by: Mike Bazov <mike.bazov@gmail.com>
---
 .../bpf/prog_tests/struct_ops_private_stack.c      | 34 +++++++++++++++
 .../bpf/progs/struct_ops_private_stack_tail_call.c | 49 ++++++++++++++++++++++
 2 files changed, 83 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/struct_ops_private_stack.c b/tools/testing/selftests/bpf/prog_tests/struct_ops_private_stack.c
index 103179ff873..84ce5623467 100644
--- a/tools/testing/selftests/bpf/prog_tests/struct_ops_private_stack.c
+++ b/tools/testing/selftests/bpf/prog_tests/struct_ops_private_stack.c
@@ -5,6 +5,7 @@
 #include "struct_ops_private_stack_fail.skel.h"
 #include "struct_ops_private_stack_recur.skel.h"
 #include "struct_ops_private_stack_large.skel.h"
+#include "struct_ops_private_stack_tail_call.skel.h"
 
 #if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) || \
 	(defined(__riscv) && __riscv_xlen == 64)
@@ -108,6 +109,37 @@ static void test_private_stack_large(void)
 	struct_ops_private_stack_large__destroy(skel);
 }
 
+/*
+ * A tail call enters its target past the trampoline, which keeps two runs of a
+ * prog off its private stack on a CPU, so a prog with a private stack can't be
+ * a tail call target. The small one has none and goes in first, so that the
+ * big one would be compatible with the prog array.
+ */
+static void test_private_stack_tail_call(void)
+{
+	struct struct_ops_private_stack_tail_call *skel;
+	int map_fd, fd, err;
+	__u32 key;
+
+	skel = struct_ops_private_stack_tail_call__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack_tail_call__open_and_load"))
+		return;
+
+	map_fd = bpf_map__fd(skel->maps.prog_array);
+
+	key = 0;
+	fd = bpf_program__fd(skel->progs.test_1_small_stack);
+	err = bpf_map_update_elem(map_fd, &key, &fd, BPF_ANY);
+	ASSERT_OK(err, "update_small_stack");
+
+	key = 1;
+	fd = bpf_program__fd(skel->progs.test_1_big_stack);
+	err = bpf_map_update_elem(map_fd, &key, &fd, BPF_ANY);
+	ASSERT_EQ(err, -EINVAL, "update_big_stack");
+
+	struct_ops_private_stack_tail_call__destroy(skel);
+}
+
 static void __test_struct_ops_private_stack(void)
 {
 	if (test__start_subtest("private_stack"))
@@ -118,6 +150,8 @@ static void __test_struct_ops_private_stack(void)
 		test_private_stack_recur();
 	if (test__start_subtest("private_stack_large"))
 		test_private_stack_large();
+	if (test__start_subtest("private_stack_tail_call"))
+		test_private_stack_tail_call();
 }
 #else
 static void __test_struct_ops_private_stack(void)
diff --git a/tools/testing/selftests/bpf/progs/struct_ops_private_stack_tail_call.c b/tools/testing/selftests/bpf/progs/struct_ops_private_stack_tail_call.c
new file mode 100644
index 00000000000..69dc65090e3
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/struct_ops_private_stack_tail_call.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+#include "../test_kmods/bpf_testmod.h"
+
+char _license[] SEC("license") = "GPL";
+
+int val;
+
+/* 400 bytes of stack: test_1 requests a private stack, and this one gets it */
+SEC("struct_ops")
+int BPF_PROG(test_1_big_stack)
+{
+	volatile int a[100] = {};
+
+	a[10] = 1;
+	val = a[10];
+	return 0;
+}
+
+/* Under BPF_PRIV_STACK_MIN_SIZE: no private stack */
+SEC("struct_ops")
+int BPF_PROG(test_1_small_stack)
+{
+	volatile int a[4] = {};
+
+	a[1] = 2;
+	val = a[1];
+	return 0;
+}
+
+SEC(".struct_ops")
+struct bpf_testmod_ops3 testmod_big = {
+	.test_1 = (void *)test_1_big_stack,
+};
+
+SEC(".struct_ops")
+struct bpf_testmod_ops3 testmod_small = {
+	.test_1 = (void *)test_1_small_stack,
+};
+
+struct {
+	__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
+	__uint(max_entries, 2);
+	__type(key, __u32);
+	__type(value, __u32);
+} prog_array SEC(".maps");

-- 
2.43.0



  parent reply	other threads:[~2026-12-02 13:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 13:15 [PATCH bpf-next 0/4] bpf: Per-task recursion follow-ups for struct_ops and PREEMPT_RT Mike Bazov via B4 Relay
2026-12-02 13:15 ` [PATCH bpf-next 1/4] bpf: Refuse struct_ops programs with a private stack in prog arrays Mike Bazov via B4 Relay
2026-12-02 13:15 ` [PATCH bpf-next 2/4] bpf: Keep a per-CPU counter for marked programs on PREEMPT_RT Mike Bazov via B4 Relay
2026-12-02 13:59   ` bot+bpf-ci
2026-12-02 13:15 ` Mike Bazov via B4 Relay [this message]
2026-12-02 13:15 ` [PATCH bpf-next 4/4] selftests/bpf: Expect marked programs to drop B " Mike Bazov via B4 Relay
2026-12-02 20:00 ` [PATCH bpf-next 0/4] bpf: Per-task recursion follow-ups for struct_ops and PREEMPT_RT patchwork-bot+netdevbpf

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=20261202-followup-rt-stops-v1-3-22562be9ddb0@gmail.com \
    --to=devnull+mike.bazov.gmail.com@kernel.org \
    --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=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=jp.kobryn@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=memxor@gmail.com \
    --cc=mhiramat@kernel.org \
    --cc=mike.bazov@gmail.com \
    --cc=rostedt@goodmis.org \
    --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