eBPF: Tail calls (Part-1)
Objective
- to understand performing tail-calls in eBPF
Reasoning
In order to perform tail calls, we need to
- declare
prototype
of funcs to call - declare map:
prog_array map
with key=u32, values=signature_of_funcs - fill map:
- can be done in userspace as well in kernelspace
- use
bpf_tail_call
to redirect flow to func of interest
Code
Observations
- same-cpu: callee function is executed by same-cpu
- same-context: caller and callee must have same ctx i.e program of same type
- no-new-stack: callee uses caller's stack
- no-return: callee doesn't returns to caller
Refer
-
https://docs.ebpf.io/linux/program-type/BPF_PROG_TYPE_CGROUP_SKB/
-
https://docs.ebpf.io/linux/concepts/tail-calls/
-
https://docs.ebpf.io/linux/helper-function/bpf_tail_call/
-
real_world_example: https://github.com/cilium/tetragon/blob/c51dd078bfb568075ba1fb287f2447f29f709073/bpf/process/bpf_generic_rawtp.c#L27-L45