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 4/4] selftests/bpf: Expect marked programs to drop B on PREEMPT_RT
Date: Wed, 02 Dec 2026 15:15:16 +0200 [thread overview]
Message-ID: <20261202-followup-rt-stops-v1-4-22562be9ddb0@gmail.com> (raw)
In-Reply-To: <20261202-followup-rt-stops-v1-0-22562be9ddb0@gmail.com>
From: Mike Bazov <mike.bazov@gmail.com>
On PREEMPT_RT a program with per-CPU state stays preemptible, and its
per-CPU counter refuses B's run while A is preempted inside it. Expect B
to be dropped in the subtests of such programs there. In
two_dispatchers, B's own run of the first dispatcher is dropped too, and
B reaches the handler through the second one, which has a counter of its
own, and runs it inside A.
Signed-off-by: Mike Bazov <mike.bazov@gmail.com>
---
.../selftests/bpf/prog_tests/trampoline_preempt.c | 35 ++++++++++++++++++----
1 file changed, 30 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/trampoline_preempt.c b/tools/testing/selftests/bpf/prog_tests/trampoline_preempt.c
index 8708239fed5..0234e5dec51 100644
--- a/tools/testing/selftests/bpf/prog_tests/trampoline_preempt.c
+++ b/tools/testing/selftests/bpf/prog_tests/trampoline_preempt.c
@@ -5,6 +5,7 @@
#include <signal.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
+#include <sys/utsname.h>
#include <unistd.h>
#include <test_progs.h>
#include "trampoline_preempt.skel.h"
@@ -31,8 +32,21 @@ enum { NO_PERCPU, PERCPU_MAP, PERCPU_VAR, THIS_CPU_PTR, CPU_ID };
enum expect {
B_RUNS, /* B runs the program while A is preempted inside it */
B_AFTER, /* B runs the program after A has left it */
+ B_DROPPED, /* B can't run the program while A is inside it */
};
+/*
+ * On PREEMPT_RT a program with per-CPU state stays preemptible, and a per-CPU
+ * counter refuses another run of it: B, which would run it after A, is dropped.
+ */
+static bool preempt_rt(void)
+{
+ struct utsname u;
+
+ /* The version of a PREEMPT_RT kernel says so, see init/Makefile */
+ return !uname(&u) && strstr(u.version, "PREEMPT_RT");
+}
+
/* What threads A and B share */
struct ctx {
struct trampoline_preempt *skel;
@@ -162,10 +176,21 @@ static void run_subtest(const struct subtest *t)
{
struct bpf_prog_info info = {};
__u32 info_len = sizeof(info), zero = 0;
+ enum expect expect = t->expect;
struct ctx c = {};
sigset_t oldset;
pthread_t ta, tb;
- int err, fd;
+ int err, fd, misses = 0;
+
+ /*
+ * B's own run of A's program is dropped. In two_dispatchers B still reaches
+ * the handler through the other dispatcher, which has a counter of its own,
+ * and runs it inside A.
+ */
+ if (expect == B_AFTER && preempt_rt()) {
+ expect = t->handler ? B_RUNS : B_DROPPED;
+ misses = NR_ROUNDS;
+ }
c.skel = load_progs(t->prog, t->prog_b, t->handler, t->percpu);
if (!c.skel)
@@ -203,21 +228,21 @@ static void run_subtest(const struct subtest *t)
ASSERT_OK(c.err_a, "worker_a");
ASSERT_OK(c.err_b, "worker_b");
ASSERT_EQ(c.skel->bss->sig_err, 0, "sig_err");
- if (t->expect == B_RUNS && !c.overlaps) {
+ if (expect == B_RUNS && !c.overlaps) {
/* B never preempted A inside the program, so nothing was tested */
test__skip();
goto out;
}
- ASSERT_EQ(c.overlaps, t->expect == B_RUNS ? NR_ROUNDS : 0, "overlaps");
+ ASSERT_EQ(c.overlaps, expect == B_AFTER ? 0 : NR_ROUNDS, "overlaps");
ASSERT_EQ(c.skel->bss->runs_a, NR_ROUNDS, "runs_a");
- ASSERT_EQ(c.skel->bss->runs_b, NR_ROUNDS, "runs_b");
+ ASSERT_EQ(c.skel->bss->runs_b, expect == B_DROPPED ? 0 : NR_ROUNDS, "runs_b");
if (t->handler)
ASSERT_EQ(c.skel->bss->stack_corrupt, 0, "stack_corrupt");
fd = bpf_program__fd(bpf_object__find_program_by_name(c.skel->obj, t->prog));
err = bpf_prog_get_info_by_fd(fd, &info, &info_len);
if (!ASSERT_OK(err, "prog_info"))
goto out;
- ASSERT_EQ(info.recursion_misses, 0, "recursion_misses");
+ ASSERT_EQ(info.recursion_misses, misses, "recursion_misses");
out:
trampoline_preempt__destroy(c.skel);
}
--
2.43.0
next prev parent reply other threads:[~2026-12-02 13:16 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 ` [PATCH bpf-next 3/4] selftests/bpf: Test private-stack struct_ops progs in prog arrays Mike Bazov via B4 Relay
2026-12-02 13:15 ` Mike Bazov via B4 Relay [this message]
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-4-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