From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Martin Kelly" <martin.kelly@crowdstrike.com>
Cc: "Mike Bazov" <mikeba@sentinelone.com>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"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>,
"Shuah Khan" <shuah@kernel.org>, <bpf@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Andrey Grodzovsky" <andrey.grodzovsky@crowdstrike.com>
Subject: Re: [EXT.MSG] Re: [PATCH RFC bpf-next 0/2] bpf: Do not let preemption cause false recursion drops in trampoline progs
Date: Thu, 05 Nov 2026 05:18:48 +0000 [thread overview]
Message-ID: <DMN0USP1E59A.34N710IJOO0PJ@gmail.com> (raw)
In-Reply-To: <CAH=2mMABxvf+GNr7vUKNkGvyU-gmaXKMGNJHg4URUCW_eyuxGg@mail.gmail.com>
On Thu Nov 5, 2026 at 1:12 AM UTC, Martin Kelly wrote:
> We have noticed this issue independently in testing of our own security
> agent and have hit the same false recursion skips on 7.0 and 7.1
> kernels. More details and measurements below.
>
> On Tue, Nov 3, 2026 at 6:24 PM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
>> Today a fentry prog never runs twice at the same time on one cpu.
>> Existing progs rely on that for their per-cpu maps.
>>
>> task A, cpu 0 task B, cpu 0
>> buf = lookup(&percpu_scratch)
>> fill buf
>> <preempted>
>> buf = lookup(&percpu_scratch)
>> fill buf
>> output(buf)
>> output(buf) <- data of B
>>
>> A plain (*cnt)++ in a per-cpu map loses updates the same way.
>> Today B is skipped and recursion_misses counts it.
>> With the per-task check A sends a corrupted event and nothing counts it.
>
> Our programs avoid writing to per-CPU arrays because of corruption on
> PREEMPT_RT kernels, where trampolines have always been preemptible and
> thus can corrupt these structures.
what do you mean? the reentrance prevention counter works on PREEMPT_RT too.
per-cpu array are not corrupted there.
> So for us, an opt-in flag that allows
> preemption (instead of skipping) would work well and not regress current
> programs that don't opt in. A verifier scan for per-CPU arrays could
> also work, but it would need to distinguish read-only vs write access to
> those maps.
>
>> Add bpf_preempt_disable().
>> Your test forces the preemption in the middle of the prog.
>> Explicit bpf_preempt_disable() will fix it.
>> And you'll have an easy way to see why disabling preemtion
>> for the whole program might hurt your own production.
>
> We tried bpf_preempt_disable()/bpf_preempt_enable() around our hooks on
> a 2-vCPU 7.1.5 VM with HRTICK under an open/close stress test load.
> recursion_misses for the locks_remove_file fentry actually increased
> slightly 29M to 31M (this may be within noise). As far as we can tell
> from the code, the trampoline takes prog->active before the program's
> first instruction and releases it in __bpf_prog_exit_recur() after the
> program finishes. bpf_preempt_enable() calls preempt_enable(), which is
> a reschedule point. That reschedule happens with prog->active still
> held.
pls try _no_resched() as I suggested in the other reply.
> In a process-heavy workload on a 2-vCPU VM (~1M fork+exec of
> short-lived processes, ~606/second) we recorded the following number of
> recursion_misses on a 7.0.9 and a 7.1.5 kernel. Both kernels use lazy
> preemption with PREEMPT_RCU enabled. The miss rate has increased
> significantly, which we suspect is due to the HRTICK change.
>
> 7.0.9 (HRTICK off) 7.1.5 (HRTICK on)
> ================== =================
> security_file_permission fentry 1 in 61,580 1 in 1,568
> security_inode_getattr fentry 1 in 59,242 1 in 1,707
> do_file_open fexit 1 in 813,983 1 in 2,503
> sched_process_exec raw_tracepoint 1 in 1,000,816 1 in 500,408
Thanks for the numbers.
Are you saying turning off HRTICK is not an option for your production?
> We don't have a preferred mechanism and are generally open to any
> approach that would help reduce these recursion_misses. Whatever the
> mechanism, it would be ideal to cover raw_tp programs too, since
> a46023d5616e made those preemptible.
agree. let's come up with a design then.
next prev parent reply other threads:[~2026-11-05 5:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-25 11:02 Mike Bazov via B4 Relay
2026-10-25 11:02 ` [PATCH RFC bpf-next 1/2] bpf: Keep recursion-checked trampoline programs non-preemptible on !PREEMPT_RT Mike Bazov via B4 Relay
2026-10-25 11:02 ` [PATCH RFC bpf-next 2/2] selftests/bpf: Add trampoline preemption false-recursion test Mike Bazov via B4 Relay
2026-10-30 22:22 ` [PATCH RFC bpf-next 0/2] bpf: Do not let preemption cause false recursion drops in trampoline progs Alexei Starovoitov
2026-11-02 23:24 ` [EXT.MSG] " Mike Bazov
2026-11-03 1:49 ` Alexei Starovoitov
2026-11-03 21:28 ` Mike Bazov
2026-11-04 2:20 ` Alexei Starovoitov
2026-11-05 1:12 ` Martin Kelly
2026-11-05 5:18 ` Alexei Starovoitov [this message]
2026-11-05 8:53 ` Peter Zijlstra
2026-11-03 23:46 ` JP Kobryn
2026-11-04 2:21 ` Alexei Starovoitov
2026-11-05 0:12 ` [EXT.MSG] " Mike Bazov
2026-11-05 5:14 ` Alexei Starovoitov
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=DMN0USP1E59A.34N710IJOO0PJ@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrey.grodzovsky@crowdstrike.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.kelly@crowdstrike.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mikeba@sentinelone.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.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®