BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/7] bpf: Keep the state of may_goto in a register
@ 2026-12-05  3:37 Alexei Starovoitov
  2026-12-05  3:37 ` [PATCH bpf-next 1/7] selftests/bpf: Don't depend on the expansion of may_goto Alexei Starovoitov
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Alexei Starovoitov @ 2026-12-05  3:37 UTC (permalink / raw)
  To: bpf; +Cc: daniel, andrii, eddyz87, memxor

From: Alexei Starovoitov <ast@kernel.org>

may_goto cancels a prog that loops for too long. It counts iterations in
per-cpu memory that all invocations of the prog share. When one preempts
another, a loop can run forever or get cancelled too early.

Give each invocation its own state and keep it in %r11 on x86-64, in x24
on arm64 and in current on other archs. It also makes may_goto faster: two
insns on x86-64 and arm64.

  ns per iteration                        Ice Lake       Neoverse V2
                                       before   after  before   after
  empty loop                             1.81    0.29    2.15    0.48
  load and store in arena                1.44    1.15    2.15    1.21
  call of bpf_get_numa_node_id()         2.01    1.81    2.15    0.95
  may_goto in callback of bpf_loop()     2.61    2.02    2.74    2.17
  call of a subprog with may_goto        3.49    1.99    4.30    2.15
  the same in a prog with a tail call    2.99    4.28    4.30    4.40

Progs with tail calls pass the state to subprogs through current, which is
slower. freplace of a subprog of a prog with may_goto is now refused.

Alexei Starovoitov (7):
  selftests/bpf: Don't depend on the expansion of may_goto
  selftests/bpf: Wait longer in parallel tests of libarena
  bpf: Keep the state of may_goto per invocation
  bpf, x86: Keep the state of may_goto in %r11
  bpf, arm64: Keep the state of may_goto in x24
  bpf: Keep the state of may_goto in the task on other archs
  selftests/bpf: Test may_goto state across calls and clobbers of %r11

 arch/arm64/net/bpf_jit_comp.c                 | 203 ++++++--
 arch/arm64/net/bpf_timed_may_goto.S           |  20 +-
 arch/loongarch/net/bpf_timed_may_goto.S       |   9 +-
 arch/powerpc/net/bpf_timed_may_goto.S         |  10 +-
 arch/riscv/net/bpf_timed_may_goto.S           |   8 +-
 arch/s390/net/bpf_timed_may_goto.S            |   2 +-
 arch/x86/net/bpf_jit_comp.c                   | 362 ++++++++++++---
 arch/x86/net/bpf_timed_may_goto.S             |  17 +-
 include/linux/bpf.h                           |   6 +-
 include/linux/bpf_verifier.h                  |   9 +
 include/linux/filter.h                        |  74 ++-
 include/linux/sched.h                         |   2 +
 kernel/bpf/arena.c                            |   1 +
 kernel/bpf/core.c                             |  78 +---
 kernel/bpf/disasm.c                           |  15 +
 kernel/bpf/fixups.c                           | 432 +++++++++++++-----
 kernel/bpf/helpers.c                          |  18 +-
 kernel/bpf/rqspinlock.c                       |   2 +
 kernel/bpf/stream.c                           |   5 +-
 kernel/bpf/verifier.c                         |  19 +
 .../selftests/test_parallel_bitmap.bpf.c      |   2 +-
 .../selftests/test_parallel_spmc.bpf.c        |   2 +-
 .../selftests/bpf/prog_tests/patch_list.c     |   9 +-
 .../selftests/bpf/prog_tests/share_subprogs.c |   9 +-
 .../selftests/bpf/prog_tests/timed_may_goto.c |  71 ++-
 .../selftests/bpf/progs/timed_may_goto.c      |  96 +++-
 .../selftests/bpf/progs/timed_may_goto_ext.c  |  18 +
 .../selftests/bpf/progs/timed_may_goto_user.c |  53 ++-
 .../bpf/progs/verifier_arena_stack.c          |   6 +-
 .../bpf/progs/verifier_bpf_fastcall.c         |  70 +--
 .../selftests/bpf/progs/verifier_budget.c     |  18 +-
 .../selftests/bpf/progs/verifier_loop_walk.c  |   2 +-
 .../selftests/bpf/progs/verifier_may_goto_1.c |  83 +++-
 .../selftests/bpf/progs/verifier_passes.c     |   2 +-
 .../selftests/bpf/progs/verifier_patch_list.c | 117 +++--
 .../selftests/bpf/progs/verifier_trip_count.c |   2 +
 36 files changed, 1340 insertions(+), 512 deletions(-)

-- 
2.55.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-12-05  6:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05  3:37 [PATCH bpf-next 0/7] bpf: Keep the state of may_goto in a register Alexei Starovoitov
2026-12-05  3:37 ` [PATCH bpf-next 1/7] selftests/bpf: Don't depend on the expansion of may_goto Alexei Starovoitov
2026-12-05  3:37 ` [PATCH bpf-next 2/7] selftests/bpf: Wait longer in parallel tests of libarena Alexei Starovoitov
2026-12-05  3:37 ` [PATCH bpf-next 3/7] bpf: Keep the state of may_goto per invocation Alexei Starovoitov
2026-12-05  3:37 ` [PATCH bpf-next 4/7] bpf, x86: Keep the state of may_goto in %r11 Alexei Starovoitov
2026-12-05  4:29   ` bot+bpf-ci
2026-12-05  3:37 ` [PATCH bpf-next 5/7] bpf, arm64: Keep the state of may_goto in x24 Alexei Starovoitov
2026-12-05  4:18   ` bot+bpf-ci
2026-12-05  3:38 ` [PATCH bpf-next 6/7] bpf: Keep the state of may_goto in the task on other archs Alexei Starovoitov
2026-12-05  4:18   ` bot+bpf-ci
2026-12-05  3:38 ` [PATCH bpf-next 7/7] selftests/bpf: Test may_goto state across calls and clobbers of %r11 Alexei Starovoitov
2026-12-05  4:51   ` sashiko-bot
2026-12-05  6:40 ` [PATCH bpf-next 0/7] bpf: Keep the state of may_goto in a register patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox