I'm experimenting with writing eBPF using libbpf but the documentation is very sparse and I'm having troubles understanding even some basic things related to eBPF program execution. I'm mostly interested in BPF_PROG_TYPE_PERF_EVENT
program type, in case an answer depends on the program type, but I'd also appreciate references to where the corresponding info can be found for the other program types.
- How does a eBPF program get executed relative to a task/thread (AFAIU, these are the same in the eBPF context) that triggered the event to which the eBPF program is attached? Is eBPF executed on the same CPU on which the triggering task/thread has been running (and the task/thread is paused until the program finishes), or they can run in parallel?
- Where can I find out exactly what is passed to a eBPF program as its argument (context)? I know this is program-type-dependent, and for
BPF_PROG_TYPE_SOCKET_FILTER
this is even documented on the bpf(2) man page, but what about the other program types? - Does the return value of a eBPF program have an impact on something? I figure, every eBPF program in C programming language terms has to return a 64-bit integer because the eBPF register responsible for storing the return value has to be filled on program exit, but does the return value actually mean something to Linux? Again, if this is program-type-dependent, where can I find any information about this?
I'd really appreciate not only the answers, but also references to some official sources where the answers on these and similar questions can be found.