From: Mike Bazov Date: Wed, 02 Dec 2026 15:15:16 +0200 Subject: [PATCH bpf-next 4/4] selftests/bpf: Expect marked programs to drop B on PREEMPT_RT MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-followup-rt-stops-v1-4-22562be9ddb0@gmail.com> References: <20261202-followup-rt-stops-v1-0-22562be9ddb0@gmail.com> In-Reply-To: <20261202-followup-rt-stops-v1-0-22562be9ddb0@gmail.com> To: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Eduard Zingerman , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Jiri Olsa , John Fastabend , Emil Tsalapatis , Ihor Solodrai , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , JP Kobryn , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, Mike Bazov X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796217344; l=3736; i=mike.bazov@gmail.com; s=gmail-20261116; h=from:subject:message-id; bh=a2D9SgQ63Hx41NxkazNXVVNX5pT9XqK9V/kPWElo2b8=; b=QqVrcFl7BARtvyzXWDbckl1QrZIW8q0Jwy5aZ3nd0Ulr4/roRoNxJqAHlHvVLaaWWF2C+9ZMi w0nSWXYrIOSB6I/3nKexeJA8LFWZOLzO9hUkOKQ733dqS4CXFQ2k7Ca X-Developer-Key: i=mike.bazov@gmail.com; a=ed25519; pk=Rr9fagn0pNA+bs8tgc6DXZpRAhl/maU6BeqkttIR7DA= X-Endpoint-Received: by B4 Relay for mike.bazov@gmail.com/gmail-20261116 with auth_id=1544 List-Id: B4 Relay Submissions 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 --- .../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 #include #include +#include #include #include #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