From: bot+bpf-ci@kernel.org
To: mike.bazov@gmail.com,bpf@vger.kernel.org,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org
Cc: martin.lau@linux.dev,eddyz87@gmail.com,memxor@gmail.com,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,john.fastabend@gmail.com,emil@etsalapatis.com,ihor.solodrai@linux.dev,rostedt@goodmis.org,mhiramat@kernel.org,mathieu.desnoyers@efficios.com,jp.kobryn@linux.dev,linux-trace-kernel@vger.kernel.org,linux-kernel@vger.kernel.org,mike.bazov@gmail.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next 2/4] bpf: Keep a per-CPU counter for marked programs on PREEMPT_RT
Date: Wed, 2 Dec 2026 13:59:36 +0000 (UTC) [thread overview]
Message-ID: <9c78ab6b556b2a0b721de1419187467b53c54ef09dbbf7166e4d245c929c428b@mail.kernel.org> (raw)
In-Reply-To: <20261202-followup-rt-stops-v1-2-22562be9ddb0@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2721 bytes --]
> 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
next prev parent reply other threads:[~2026-12-02 13:59 UTC|newest]
Thread overview: 6+ 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 [this message]
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 ` [PATCH bpf-next 4/4] selftests/bpf: Expect marked programs to drop B on PREEMPT_RT Mike Bazov via B4 Relay
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=9c78ab6b556b2a0b721de1419187467b53c54ef09dbbf7166e4d245c929c428b@mail.kernel.org \
--to=bot+bpf-ci@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@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--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
all inboxes | Powered by JetHome®