Re: [EXT.MSG] Re: [PATCH bpf-next v2 0/5] bpf: Check recursion per task for preemptible programs

From: Mike Bazov

Date: Thu Nov 12 2026 - 17:47:26 EST


> The link walk doesn't look too bad,
> but pls share bench trig-fentry/exit/rawtp numbers.

Got the numbers below, bpf-next 0fb18ce8a2e9 with and without the series,
x86-64 VM with 4 vCPUs, lazy preemption. Each value is the median of
10 runs of:

./bench -w2 -d12 -a trig-<x>

(M/s, median of 10 runs, min-max in brackets; non-debug kernels from
the same config; bpf-next #2 is a second boot after the series)

bpf-next series bpf-next #2
trig-fentry 39.71 [38.75-40.43] 40.35 [39.74-41.12] 39.75 [39.10-40.08]
trig-fexit 35.67 [32.67-37.56] 36.70 [33.26-37.79] 36.56 [31.69-37.60]
trig-rawtp 41.07 [40.43-41.73] 38.15 [37.78-38.87] 40.30 [39.86-40.92]

In these runs, fentry measured about 1.5% higher throughput with the
series. The fexit difference is comparable to the variation between
the two baseline boots.

raw_tp is 5-7% slower, outside the run-to-run variation. Its run
context is a C local in __bpf_trace_run() that grew from 16 to 32
bytes, and bpf_trace_run1() now zero-fills more of it, realigns the
stack, and checks jits_use_priv_stack, which a raw_tp program can't
need after patch 1. I'll try to trim those and send the numbers again.

> Maybe we should do a per-task array of progs instead to detect recursion?
> It's likely more cache efficient than link list walk.

I think it would bring a different set of trade-offs rather
than a clear win:

- I believe most of the time the chain is empty, so there is nothing
to walk and an array wouldn't save anything.
- A fixed-size array would require choosing a capacity and an overflow
policy. Its setup cost would depend on the generated code; the extra
stack initialization in the raw_tp disassembly is a reason to check
that cost.
- The chain reuses bpf_ctx and the existing stack-allocated contexts,
without a capacity limit.

do you think it is worth doing?

> A prog with a scratch map of its own is correct today and
> that's what plenty of production bpf progs use today.
>
> This patch set will make them send corrupted events, and nothing counts
> this corrupted events. Today, at least, you have a miss count.

agreed, can we consider keeping today's per-CPU guard for
the programs that depend on it?

- programs with a private stack (as in v2);
- programs that use timed may_goto;
- programs that use per-CPU map values: lookups, bpf_this_cpu_ptr()/
bpf_per_cpu_ptr(), and bpf_for_each_map_elem() callbacks;
- programs that can reach a tail call, since a tail-called program
skips its own guard.

Only the remaining programs would get the per-task check. Extensions
(freplace) of raw_tp and tracepoint programs still need a rule.
Preemption-disable, as you suggested, could later remove the drops for
the guarded programs as a separate step. The commit logs will spell out
these trade-offs.

> With the link list approach every B gives A 250 ms more:
[...]
> So the promise of may_goto that I just fixed a week or so ago
> will be borken again.

right. The proposal above keeps the existing per-CPU guard
for the relevant programs.

Thanks,
Mike