]> git.baikalelectronics.ru Git - kernel.git/commit
bpf, libbpf: Add bpf_tail_call_static helper for bpf programs
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 30 Sep 2020 15:18:18 +0000 (17:18 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 30 Sep 2020 18:50:35 +0000 (11:50 -0700)
commit3a4edcea1f6948b6f79b59d3cd3d5543c4ab5e30
tree59bbc2e77e6832566e76243fca5805868126eea4
parentac000c99d1afb518e86e1a7e2803f1928dc0670f
bpf, libbpf: Add bpf_tail_call_static helper for bpf programs

Port of tail_call_static() helper function from Cilium's BPF code base [0]
to libbpf, so others can easily consume it as well. We've been using this
in production code for some time now. The main idea is that we guarantee
that the kernel's BPF infrastructure and JIT (here: x86_64) can patch the
JITed BPF insns with direct jumps instead of having to fall back to using
expensive retpolines. By using inline asm, we guarantee that the compiler
won't merge the call from different paths with potentially different
content of r2/r3.

We're also using Cilium's __throw_build_bug() macro (here as: __bpf_unreachable())
in different places as a neat trick to trigger compilation errors when
compiler does not remove code at compilation time. This works for the BPF
back end as it does not implement the __builtin_trap().

  [0] https://github.com/cilium/cilium/commit/f5537c26020d5297b70936c6b7d03a1e412a1035

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/1656a082e077552eb46642d513b4a6bde9a7dd01.1601477936.git.daniel@iogearbox.net
tools/lib/bpf/bpf_helpers.h