Questions tagged [ebpf]

eBPF (from “extended Berkeley Packet Filter”) is a subsystem introduced in Linux and allowing to load user programs into the kernel, to verify them for safety, possibly to JIT (Just-In-Time) compile them, and to attach them to hook points, where they run on certain events. eBPF's performance and flexibility make it suitable for a wide range of use cases, the most prominent being network packet processing, system monitoring, and security enforcement.

eBPF (from “extended Berkeley Packet Filter”) is a subsystem allowing to load user programs into the kernel, to verify them for safety, possibly to JIT (Just-In-Time) compile them, and to attach them to hook points, where they run on certain events. eBPF's performance and flexibility make it suitable for a wide range of use cases, the most prominent being network packet processing, system monitoring, and security enforcement. Introduced in Linux, eBPF gained support to varying degrees on other systems, including Windows or FreeBSD.

See also https://ebpf.io/ for a more detailed introduction and for additional resources. More assistance can also be found at the following locations:

When submitting questions related to a specific eBPF piece of code, please consider including a full stand-alone reproducer, it helps a lot for debugging the issues.

Related tags include bpf, bcc-bpf, or xdp-bpf.

641 questions
4
votes
1 answer

BPF verifier rejects when try to access __sk_buff member

I'm trying to write a sample eBPF program which can access __sk_buff member and dump it into /sys/kernel/debug/tracing/trace. #include #include #include SEC("dump_skb_member") int…
lcl1996
  • 53
  • 4
4
votes
1 answer

What is the real address of `%fs:0xfffffffffffffff8`?

I want to trace the goid of go programs using ebpf. After reading for some posts and blogs, I know that %fs:0xfffffffffffffff8 points to the g struct of go and mov %fs:0xfffffffffffffff8,%rcx instruction always appear at the start of a go…
jl0x61
  • 407
  • 3
  • 12
4
votes
1 answer

libbpf: Error loading ELF section .BTF: 0

I got this error message on ubuntu 19.04 when I try to execute sudo ./mineonlyret which is the user space program which loads an ebpf program and it is described after. I tried the same configuration on ubuntu 18.04 and it worked without errors.…
Maicake
  • 1,046
  • 10
  • 34
4
votes
1 answer

Why are the first 8 bytes of cpumap_enqueue_ctx not accessible by bpf code?

Reading some ebpf examples which are attached to tracepoints I've noticed that every struct is build starting with a padding like this (from samples/bpf/xdp_redirect_cpu_kern.c) /* Tracepoint:…
Maicake
  • 1,046
  • 10
  • 34
4
votes
2 answers

What is not allowed in restricted C for ebpf?

From bpf man page: eBPF programs can be written in a restricted C that is compiled (using the clang compiler) into eBPF bytecode. Various features are omitted from this restricted C, such as loops, global variables, …
Maicake
  • 1,046
  • 10
  • 34
4
votes
1 answer

while installing bcc, can't find package bpfcc

I am trying to install bcc module on my Linux machine so I can code BPF programs. I've been following up with the page https://github.com/iovisor/bcc/blob/master/INSTALL.md#kernel-configuration to build a kernel and install bcc module. However,…
Rosè
  • 345
  • 2
  • 13
4
votes
1 answer

eBPF: understand two macros in verifier code

I'm looking in the ebpf verifier code, and I can't get my head around the following macros: #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) #define offsetofend(TYPE, MEMBER) \ (offsetof(TYPE, MEMBER) + sizeof(((TYPE…
Mark
  • 6,052
  • 8
  • 61
  • 129
4
votes
1 answer

ebpf - sections names

Is it mandatory to have unique names for every program section in bpf program? For instance, this program compiles fine with llvm-5.0 : ... SEC("sockops") int bpf1(struct bpf_sock_ops *sk_ops) { return 1; } SEC("sockops") int bpf2(struct…
Mark
  • 6,052
  • 8
  • 61
  • 129
4
votes
1 answer

Simple eBPF action not taking effect with tc

I compiled BPF example from samples/bpf/pare_simple.c (from the Linux kernel tree) with very simple change: SEC("simple") int handle_ingress(struct __sk_buff *skb) { return TC_ACT_SHOT; } So I want ANY packets to be dropped. I install it as…
Mark
  • 6,052
  • 8
  • 61
  • 129
4
votes
1 answer

Is it possible to use eBPF or perf to calculate time spent in individual traced functions?

Currently, I can tell trace-cmd (an ftrace front-end) to use ftrace's function graph infrastructure to trace a specified workload. Using some trace data processing tools, I can look at the frequency with which functions were called and the…
buratino
  • 1,408
  • 2
  • 17
  • 40
3
votes
1 answer

eBPF: BPF stack limit exceeded when storing stack variable in map

I have the following eBPF program: #include #include #include #include #include char LICENSE[] SEC("license") = "GPL"; // msg_data_map carries a key-value pair of (msg_id,…
diviquery
  • 569
  • 5
  • 19
3
votes
1 answer

How can I filter process name in bpftrace?

I'm currently trying to learn how to use BPF tools with the book "BPF performance Tools" Its really complet and really interesting. At the end of some chapter there are some optionnal exercices..but there is no solution. I also checked the github…
NicoW
  • 61
  • 5
3
votes
2 answers

ebpf kprobe argument not matching the syscall

I'm learning eBPF and I'm playing with it in order to understand it better while following the docs but there's something I don't understand why it's not working... I have this very simple code that stops the code and returns 5. int main() { …
3
votes
1 answer

How does __sync_fetch_and_add() work in bpf programs

I'm writing several bpf programs that will update the same counter which is implemented by a BPF_MAP_TYPE_ARRAY bpf map. To avoid data races, I referred the bpf kernel doc and used the __sync_fetch_and_add() intrinsic. However, I'm confused about…
sk_buff
  • 81
  • 7
3
votes
1 answer

How to make eBPF program sleepable

I've been reading about sleepable eBPF programs, specifically this article provides a nice introduction. However I am struggling to find any documentation or examples on how to actually achieve this in code. Any tips or links to documentation are…
nela
  • 429
  • 5
  • 13
1 2
3
42 43