BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/5] bpf: Trampolines: the size of the image, the type of the return value
@ 2026-11-19  1:29 Alexei Starovoitov
  2026-11-19  1:29 ` [PATCH bpf-next 1/5] bpf, x86: Count the size of a trampoline, do not emit it Alexei Starovoitov
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Alexei Starovoitov @ 2026-11-19  1:29 UTC (permalink / raw)
  To: bpf; +Cc: daniel, andrii, eddyz87, memxor

From: Alexei Starovoitov <ast@kernel.org>

Two things that the x86-64 and arm64 trampolines get wrong, and a limit
that does not hold what it promises.

Patches 1 - 3, the size of the image. BPF_MAX_TRAMP_LINKS programs are
meant to fit in a page. They may not: on x86-64 with call depth tracking
the pass that finds the size warns or writes past its scratch page. Let
that pass count without an image, as the other JITs do. Then the size is
the limit on each architecture, and BPF_MAX_TRAMP_LINKS can go.

Patches 4 - 5, the return value. A BPF program returns 64 bits. The
trampoline hands them to a caller that was compiled for a function that
returns int or bool, and it tests all 64 bits to tell whether an fmod_ret
program wants the traced function skipped.

	program returns                   before              after
	fmod_ret, int f():       1 << 32  f() is skipped,     f() is called
	                                  the caller reads 0
	fmod_ret, bool f():      2        the caller gets 2   1
	struct_ops, bool member: 2        the caller gets 2   1

Extend the value from the width of the return type, as s390 does, and
make a bool 0 or 1. The trampolines of the other architectures do not get
that.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Alexei Starovoitov (5):
  bpf, x86: Count the size of a trampoline, do not emit it
  selftests/bpf: Don't use BPF_MAX_TRAMP_LINKS
  bpf: Remove BPF_MAX_TRAMP_LINKS
  bpf, x86, arm64: Fit the return value of a prog to the return type
  selftests/bpf: Test the width of the value of an fmod_ret program

 arch/arm64/net/bpf_jit_comp.c                 | 39 ++++++--
 arch/s390/net/bpf_jit_comp.c                  | 18 +---
 arch/x86/net/bpf_jit_comp.c                   | 87 ++++++++++++------
 include/linux/bpf.h                           | 24 +++--
 kernel/bpf/bpf_struct_ops.c                   |  2 +-
 kernel/bpf/btf.c                              |  2 +
 kernel/bpf/trampoline.c                       | 25 +++---
 kernel/bpf/verifier.c                         | 12 ++-
 .../selftests/bpf/prog_tests/fexit_stress.c   | 29 +++---
 .../selftests/bpf/prog_tests/modify_return.c  | 51 +++++++++++
 .../selftests/bpf/prog_tests/tracing_multi.c  | 35 ++++----
 .../bpf/prog_tests/trampoline_count.c         | 89 -------------------
 .../selftests/bpf/progs/fmodret_retval.c      |  2 +-
 .../selftests/bpf/progs/modify_return_width.c | 39 ++++++++
 .../bpf/progs/test_trampoline_count.c         | 24 -----
 .../selftests/bpf/test_kmods/bpf_testmod.c    | 19 ++--
 tools/testing/selftests/bpf/test_progs.c      | 37 --------
 tools/testing/selftests/bpf/test_progs.h      |  2 -
 18 files changed, 256 insertions(+), 280 deletions(-)
 delete mode 100644 tools/testing/selftests/bpf/prog_tests/trampoline_count.c
 create mode 100644 tools/testing/selftests/bpf/progs/modify_return_width.c
 delete mode 100644 tools/testing/selftests/bpf/progs/test_trampoline_count.c


base-commit: 32b66b94c86f009b49668de7340f2ed65aad2dc5
-- 
2.55.0


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

end of thread, other threads:[~2026-11-19  5:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  1:29 [PATCH bpf-next 0/5] bpf: Trampolines: the size of the image, the type of the return value Alexei Starovoitov
2026-11-19  1:29 ` [PATCH bpf-next 1/5] bpf, x86: Count the size of a trampoline, do not emit it Alexei Starovoitov
2026-11-19  1:29 ` [PATCH bpf-next 2/5] selftests/bpf: Don't use BPF_MAX_TRAMP_LINKS Alexei Starovoitov
2026-11-19  1:29 ` [PATCH bpf-next 3/5] bpf: Remove BPF_MAX_TRAMP_LINKS Alexei Starovoitov
2026-11-19  1:39   ` sashiko-bot
2026-11-19  1:45     ` Alexei Starovoitov
2026-11-19  2:08   ` bot+bpf-ci
2026-11-19  1:29 ` [PATCH bpf-next 4/5] bpf, x86, arm64: Fit the return value of a prog to the return type Alexei Starovoitov
2026-11-19  1:29 ` [PATCH bpf-next 5/5] selftests/bpf: Test the width of the value of an fmod_ret program Alexei Starovoitov
2026-11-19  5:10 ` [PATCH bpf-next 0/5] bpf: Trampolines: the size of the image, the type of the return value 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