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
2
votes
1 answer

Why does my BPF_PROG_TYPE_CGROUP_SKB program not work in a container?

I have written the following eBPF program to count packets: #include #include #include "include/bpf_map.h" #include "include/bpf_helpers.h" struct bpf_map_def SEC("maps/count") count_map = { .type =…
dippynark
  • 2,743
  • 20
  • 58
2
votes
1 answer

Why is a kretprobe on sys_futex called less often than a corresponding kprobe?

I am doing some tracing of various kernel functions and system calls, and establishing patterns between them which can be used for certain performance profiling. One thing that I noticed is that sometimes, even in my simple testing application which…
Ashley Davies
  • 1,873
  • 1
  • 23
  • 42
2
votes
1 answer

How do I access xmm registers in an eBPF program

I am trying to use bcc-tools to trace a user process using uprobe, but some functions take floating point arguments. According to x86_64 ABI, these values are normally passed in the xmm registers. The eBPF functions in bcc takes a struct pt_regs *…
filijokus
  • 105
  • 2
2
votes
1 answer

Take name of called function in eBPF

I'd like to trace functions of the particular PID and collect some stats (total calls, total times, etc.), and it's not completely clear for me how to create BPF_HASH with pairs of funcname+my_struct. Is there any way to obtain names of called…
lesovsky
  • 326
  • 2
  • 14
2
votes
1 answer

Is it feasible to use eBPF to trace code at the Python stack level?

dtrace on non-Linux platforms has long been advertised to be able to dynamically instrument node.js code to do dynamic tracing at the node level, for example to allow debugging of node programs at the level of JavaScript stack frames and variables…
Croad Langshan
  • 2,646
  • 3
  • 24
  • 37
2
votes
1 answer

LLVM BPF backend doesn't put source file name on symbol table

I'm now trying to extract source C file name from ELF object which is compiled from following C code by clang. #include uint64_t test(uint64_t a) { return a + 1; } When I specify amd64 as a backend, the clang generates the symtab like…
2
votes
1 answer

does eBPF support events?

Is is possible to have ebpf program generate event, for example packet counter reached a predefined threshold value and ebpf would generate some notification/event to user, something similar to what netlink provides. I see that currently the only…
Mark
  • 6,052
  • 8
  • 61
  • 129
2
votes
1 answer

BPF: translation of program contexts

I was looking at the different types of BPF program, and noticed that for different program types the context is being passed differently. Example: For program type BPF_PROG_TYPE_SOCK_OPS, an object of type struct bpf_sock_ops_kern is passed.…
Mark
  • 6,052
  • 8
  • 61
  • 129
2
votes
1 answer

eBPF: retrieve `fd` of the pinned bpf program

I know that eBPF program can be pinned to /sys/fs/bpf (default location of small bpffs. For example using bpftool : $ bpftool prog load ./my_bpf.o /sys/fs/bpf/my_bpf I was expecting that open("/sys/fs/bpf/my_bpf") would return me the value of file…
Mark
  • 6,052
  • 8
  • 61
  • 129
2
votes
1 answer

eBPF: default bpf programs/maps?

I'm facing a strange behaviour of bpf with the latest net-next kernel. With all the BPF kernel options enabled (including CONFIG_BPF_JIT_ALWAYS_ON) and without any bpf programs loaded, bpftool reports the following: # ./bpftool prog show 2:…
Mark
  • 6,052
  • 8
  • 61
  • 129
2
votes
1 answer

How can I retrieve a task's sessionid in an eBPF program?

I want to retrieve the sessionid from a task struct in an eBPF program. I have the following code in my eBPF program: struct task_struct *task; u32 sessionid; task = (struct task_struct *)bpf_get_current_task(); sessionid =…
dippynark
  • 2,743
  • 20
  • 58
2
votes
1 answer

failing to attach eBPF `kretprobes` to `napi_poll()` with bcc tools

Idea is to use argdist to measure latency duration of napi_poll() which returns number of packet processed (called work). Ratio of execution latency of napi_poll() to number of packets processed would give me average amount of time it took to…
Valmik Roy
  • 57
  • 1
  • 7
2
votes
2 answers

How to build Linux kernel to support SO_ATTACH_BPF socket option?

I want to build a application which supports eBPF on CentOS 7 (the kernel version is 3.10.0): if(setsockopt(sock, SOL_SOCKET, SO_ATTACH_BPF, prog_fd, sizeof(prog_f)) { ...... } So I download a 4.0.5 version, make the following configurations…
Nan Xiao
  • 16,671
  • 18
  • 103
  • 164
1
vote
1 answer

Output from trace pipe and perf_output are different

Im trying to get the IHL and Version fields from an IP header using XDP, and when I output these values to the trace pipe using bpf_trace_printk the values appear correct but using perf_output i get invalid values such as IPV = 0, IHL = 69. Code is…
1
vote
1 answer

BPF tracepoint args and why they're different in different example code

I've done a lot of searching for information about writing a BPF program for tracepoints and I seem to be missing an important nugget of information that I can't find a definitive answer for. Let's take tracepoint/syscalls/sys_enter_open as an…
Greg Brown
  • 43
  • 5