Re: [PATCH bpf-next 2/4] bpf: Keep a per-CPU counter for marked programs on PREEMPT_RT

From: bot+bpf-ci

Date: Wed Dec 02 2026 - 08:59:48 EST


> bpf: Keep a per-CPU counter for marked programs on PREEMPT_RT

TL;DR: Not a bug, but comments and an freplace error message elsewhere may now
be stale on PREEMPT_RT. With freplace multi-attach or tail calls, the
extension or target may also run in two tasks on one CPU.

> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h

[ ... ]

> @@ -2877,10 +2888,12 @@ static __always_inline bool bpf_prog_enter_run_ctx(struct bpf_prog *prog,
> #endif
> run_ctx->saved_run_ctx = old_ctx;
> run_ctx->prog = prog;
> - if (prog->percpu_state) {
> - if (!prog->sleepable)
> + /* sleepable prog should be using explicit bpf_preempt_disable() */
> + if (prog->percpu_state && !prog->sleepable) {
> + if (!IS_ENABLED(CONFIG_PREEMPT_RT))
> preempt_disable_notrace();
> - /* sleepable prog should be using explicit bpf_preempt_disable() */
> + else if (this_cpu_inc_return(prog->stats->active) != 1)
> + return false;
> }

This isn't a bug, but are some comments outside this diff now stale on
PREEMPT_RT, where a marked program is no longer run with preemption
disabled?

In bpf_enable_priv_stack() in kernel/bpf/verifier.c:

* programs are serialized per CPU by bpf_prog_active, and struct_ops
* programs that get a private stack run with preemption disabled, see
* bpf_prog_enter_run_ctx(). A sleepable one can't, so it gets none.

On RT the private stack is now protected only by the per-program counter in
prog->stats->active.

In bpf_tracing_prog_attach() in kernel/bpf/syscall.c, the comment "a target
that is checked per task must run with preemption disabled: marked and not
sleepable" and the message "Freplace prog with per-CPU state needs a target
that runs with preemption disabled." no longer describe a target that passes
this check on RT.

There the extension is kept from overlapping with itself only by the
target's own counter. With several targets (freplace multi-attach), each
target has its own counter, so can the extension run in two tasks on one
CPU?

The same applies to the tail_call marking in check_helper_call() ("The
target runs without a recursion check of its own"). On RT, marking the
dispatcher no longer stops the target from running in another task on the
same CPU through a second dispatcher.

The commit message only gives "drops the runs of other tasks" as the
trade-off. Should these comments and the freplace message be updated
together with bpf_prog_enter_run_ctx()?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/46893049890