From: "JP Kobryn (CrowdStrike)" <jp.kobryn@linux.dev>
To: mikeba@sentinelone.com, 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>,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
Martin Kelly <martin.kelly@crowdstrike.com>,
Andrey Grodzovsky <andrey.grodzovsky@crowdstrike.com>,
tyler.wilson@crowdstrike.com
Subject: Re: [PATCH bpf-next v3 0/4] bpf: Check recursion per task for preemptible programs
Date: Wed, 18 Nov 2026 21:02:52 -0800 [thread overview]
Message-ID: <9a47ede3-24fa-4fa3-8d7e-50f221de0929@linux.dev> (raw)
In-Reply-To: <20261117-bpf-preempt-v2-r2-v3-0-586376ec3672@sentinelone.com>
Hi Mike,
On 11/17/26 3:29 AM, Mike Bazov via B4 Relay wrote:
> fentry, fexit, raw_tp and syscall tracepoint programs can be preempted
> while they run, but their recursion check is a per-CPU counter:
>
> task A enters prog on CPU 0 prog->active = 1
> task A is preempted inside prog
> task B enters prog on CPU 0 dropped, counted as recursion miss
>
> Nothing recursed, but B's event is lost. Since 7.0, x86 and arm64 have
> only lazy and full preemption, so this happens on stock kernels. Our
> fentry/fexit probe on inet_sendmsg() and inet_recvmsg() loses 9,254 of
> 8 million runs under HTTP load on a 4-CPU VM. With the series it loses
> none.
>
> The series checks recursion per task instead: a program is recursing
> only if the current task is already inside it.
>
> v2 did that for every program, which breaks a program that uses a
> per-CPU map as scratch space: the second task overwrites its buffer,
> and nothing counts that. So in v3 the verifier marks the programs that
> keep per-CPU state, and those keep the per-CPU counter and behave
> exactly as today:
>
> - per-CPU maps, bpf_this_cpu_ptr(), bpf_per_cpu_ptr()
> - tail calls: the target has no recursion check of its own
> - timed may_goto: its budget is per CPU
> - a private stack
>
> Trade-offs:
>
> - Marked programs are not fixed. A program with a per-CPU map or a
> tail call loses runs to preemption as it does today.
> - The verifier can't see everything. A program that keeps per-CPU
> slots of its own, like array[bpf_get_smp_processor_id()], is not
> marked. Today the counter keeps its runs apart. With the series two
> runs can write one slot, and nothing counts that.
> - raw_tp is about 2% slower in bench, see the table below. fentry and
> fexit are within noise.
> - Tracing, raw_tp and tracepoint programs lose the private stack
> (patch 1). It is already unsafe for them: two raw_tp programs that
> tail-call one handler let two tasks share its stack today. A program
> with two 2000-byte frames no longer loads.
> - A marked freplace program can't be attached to an unmarked raw_tp or
> tracepoint program: -EINVAL.
>
> One question: the marking is automatic. A flag that the program's
> author sets would avoid the second trade-off, but existing programs
> would keep losing runs until they are rebuilt. Which do you prefer?
>
> 1. bpf: Avoid per-CPU private stack in preemptible tracing progs
> 2. bpf: Mark programs whose runs must not overlap on a CPU
> 3. bpf: Check program recursion per task via bpf_ctx
> 4. selftests/bpf: Add preemption recursion test for tracing programs
>
> Testing, x86-64 VM with 4 vCPUs:
>
> The selftest pins two tasks to one CPU and makes B enter the program
> while A is preempted inside it, 20 rounds per subtest. With the series
> all 19 subtests pass. On bpf-next 7 fail: B is dropped in every round
> (fentry, fentry_s, raw_tp, raw_tp_s, tp_syscall), A's stack is
> overwritten (two_dispatchers), and the freplace attach is not rejected
> (ext_attach).
>
> bench -w2 -d12 -a trig-<x>, M/s, median of 10 runs [min-max], lazy
> preemption, in boot order, on bpf-next 0fb18ce8a2e9:
>
> trig-fentry trig-fexit trig-rawtp
> bpf-next 41.65 [40.81-42.14] 38.89 [37.58-39.41] 42.62 [41.95-42.80]
> series 42.40 [41.87-43.04] 39.33 [35.24-41.68] 41.31 [40.48-41.74]
> bpf-next #2 41.64 [40.87-41.74] 39.29 [35.18-40.62] 42.05 [41.24-42.35]
> series #2 42.34 [42.12-42.78] 39.87 [39.46-41.38] 41.53 [40.79-41.75]
We tested this series and wanted to share the data. Overall unmarked LSM/fentry
hooks previously affected went to zero. Marked hooks remained about the same or
regressed slightly. Normalized data:
category before after
raw_tp (marked) 240 213
fexit (marked) 61 135
fentry (unmarked) 3 0
other (unmarked) 805 0
It's nice to see the series progressing since we are affected by the same issue.
See some comments on the individual patches.
next prev parent reply other threads:[~2026-11-19 5:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 11:29 [PATCH bpf-next v3 0/4] bpf: Check recursion per task for preemptible programs Mike Bazov via B4 Relay
2026-11-17 11:29 ` [PATCH bpf-next v3 1/4] bpf: Avoid per-CPU private stack in preemptible tracing progs Mike Bazov via B4 Relay
2026-11-17 11:29 ` [PATCH bpf-next v3 2/4] bpf: Mark programs whose runs must not overlap on a CPU Mike Bazov via B4 Relay
2026-11-19 5:04 ` JP Kobryn (CrowdStrike)
2026-11-19 11:23 ` [EXT.MSG] " Mike Bazov
2026-11-17 11:29 ` [PATCH bpf-next v3 3/4] bpf: Check program recursion per task via bpf_ctx Mike Bazov via B4 Relay
2026-11-17 12:20 ` bot+bpf-ci
2026-11-19 5:05 ` JP Kobryn (CrowdStrike)
2026-11-19 11:35 ` [EXT.MSG] " Mike Bazov
2026-11-17 11:29 ` [PATCH bpf-next v3 4/4] selftests/bpf: Add preemption recursion test for tracing programs Mike Bazov via B4 Relay
2026-11-19 5:09 ` JP Kobryn (CrowdStrike)
2026-11-19 5:02 ` JP Kobryn (CrowdStrike) [this message]
[not found] ` <CAPnbwjpmRCR3F4V3StUz=702AdWZzHHZjP68GepnYdYykjoC8g@mail.gmail.com>
2026-11-19 11:22 ` [EXT.MSG] Re: [PATCH bpf-next v3 0/4] bpf: Check recursion per task for preemptible programs Mike Bazov
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=9a47ede3-24fa-4fa3-8d7e-50f221de0929@linux.dev \
--to=jp.kobryn@linux.dev \
--cc=andrey.grodzovsky@crowdstrike.com \
--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=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.kelly@crowdstrike.com \
--cc=martin.lau@linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=memxor@gmail.com \
--cc=mhiramat@kernel.org \
--cc=mikeba@sentinelone.com \
--cc=rostedt@goodmis.org \
--cc=song@kernel.org \
--cc=tyler.wilson@crowdstrike.com \
--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