[PATCH bpf-next 0/4] bpf: Per-task recursion follow-ups for struct_ops and PREEMPT_RT
From: Mike Bazov via B4 Relay
Date: Wed Dec 02 2026 - 08:15:54 EST
Two follow-ups to "bpf: Check recursion per task for preemptible
programs", per Alexei's review [1].
Patch 1 fixes an existing hole: a struct_ops program with a private
stack can be the target of a tail call, which enters it past the
trampoline and its recursion check. The caller is a struct_ops program
of the same op without a private stack, so it has no recursion check,
and two tasks on one CPU can run the target on the same private stack.
Such a program is now refused as a prog array element.
Patch 2 keeps marked programs preemptible on PREEMPT_RT: instead of
disabling preemption, a per-CPU counter refuses another run of the
program on the CPU, and the refused run is counted as a recursion
miss.
1. bpf: Refuse struct_ops programs with a private stack in prog arrays
2. bpf: Keep a per-CPU counter for marked programs on PREEMPT_RT
3. selftests/bpf: Test private-stack struct_ops progs in prog arrays
4. selftests/bpf: Expect marked programs to drop B on PREEMPT_RT
Testing, x86-64, with and without PREEMPT_RT:
With the series, private_stack_tail_call and the trampoline_preempt
subtests pass on both; timer_cb skips on PREEMPT_RT, as before. Without
patch 1, private_stack_tail_call fails: the program with a private
stack goes into the prog array. On PREEMPT_RT without patch 2, the nine
subtests of marked programs fail: B runs after A instead of being
dropped. Without PREEMPT_RT, test_progs shows no new failures.
[1] https://lore.kernel.org/bpf/DN9PF7JVRP7H.262PMB9O02SBG@xxxxxxxxx/
---
Mike Bazov (4):
bpf: Refuse struct_ops programs with a private stack in prog arrays
bpf: Keep a per-CPU counter for marked programs on PREEMPT_RT
selftests/bpf: Test private-stack struct_ops progs in prog arrays
selftests/bpf: Expect marked programs to drop B on PREEMPT_RT
include/linux/bpf.h | 33 +++++++++++----
include/linux/filter.h | 7 ----
kernel/bpf/arraymap.c | 1 +
.../bpf/prog_tests/struct_ops_private_stack.c | 34 +++++++++++++++
.../selftests/bpf/prog_tests/trampoline_preempt.c | 35 +++++++++++++---
.../bpf/progs/struct_ops_private_stack_tail_call.c | 49 ++++++++++++++++++++++
6 files changed, 138 insertions(+), 21 deletions(-)
---
base-commit: 23eac23279b6c114ad70a176b6dd546e88a981f8
change-id: 20261202-followup-rt-stops-02dc25401b3d
Best regards,
--
Mike Bazov <mike.bazov@xxxxxxxxx>