Re: [PATCH bpf-next v3 0/4] bpf: Check recursion per task for preemptible programs
From: Alexei Starovoitov
Date: Tue Nov 24 2026 - 15:26:55 EST
On Tue, Nov 24, 2026 at 08:10 AM Mike Bazov <mikeba@xxxxxxxxxxxxxxx> wrote:
> Timed may_goto sets the mark, so a may_goto loop would run with
> preemption off for up to 250 ms, which you ruled out on v1 ("with
> may_goto they can take 1/4 sec"). Move count and timestamp per
> invocation, in bpf_run_ctx, so that may_goto needs no mark?
Well, since you brought it up, let's fix may_goto overwrite issue
as part of this series.
may_goto's count and timestamp cannot really move to bpf_run_ctx,
since xdp, tc, perf_event progs and async callbacks
don't have it. In bpf_timer_cb() current->bpf_ctx is NULL or belongs to
the interrupted prog.
Keep count and timestamp per-cpu. Call bpf_timed_may_goto_save() in
bpf_prog_enter_run_ctx() and bpf_timed_may_goto_restore() in
bpf_prog_exit_run_ctx(), like bpf_timer_cb() does.
Then the preempted run gets its count and timestamp back.
For progs that enter this way skip this store in bpf_do_misc_fixups():
insn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_0, owner_off, 0);
With it cur->owner == saved is false and restore does nothing.