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

How I can include the /kernel/sched/* into a BPF program?

I am trying to make a custom bpf program with bpftrace in Linux, according to the book BPF Performance Tools. I tried to include some files from the path linux/kernel/sched/sched.h. How can I include them? (not only the /include folder but also from…
2
votes
0 answers

How to set the number of cores/threads a XDP hook uses?

I am using a multi-producer single-consumer implementation on the user side to handle incoming data from a eBPF map from an XDP hook. However, in order to do this, I need to limit the number of cores the XDP hook can use to send information to the…
2
votes
1 answer

what is the detailed process of bps API map helpers like "bpf_map_update_elem"?

In my understanding, when userspace use bpf_map_update_elem(int fd, void *key, void *value, __u64 flags), first, userspace find the map through the fd; second, userspace make a memory in user-space; and .... I know a little bit, but the specific…
Vector
  • 67
  • 1
  • 5
2
votes
1 answer

What are the limitations of bpf virtual machine and bpf map?

I am using ebpf+XDP to make some demo. when I use a large memory MAP, for example: BPF_HASH(cache, u64, u64, 10240000); BPF_HASH(filter1, u32, u64, 10240000); BPF_HASH(filter2, struct XXX, u16, 10240000); when I run this demo, After running for a…
Vector
  • 67
  • 1
  • 5
2
votes
1 answer

Can eBPF's perf_submit() be used in a socket_filter program as well?

So I was trying to send some data from the kernel space program to the user space program using perf_submit. I've done some studies and here(https://github.com/iovisor/bcc/issues/2423), yonghong-song answered(the last comment) that a socket_filter…
Rosè
  • 345
  • 2
  • 13
2
votes
0 answers

Linux samples BPF is not compiling

Just synced up to latest Linux bpf-next repo (5.3.0) and trying to compile samples/bpf directory. The Linux kernel compiles fine. This is on a Linux host and the default config was taken from /boot/config-* and changed to define XDP param. I do have…
jay
  • 21
  • 1
2
votes
2 answers

Attach bpftrace probe to C++ function

I have a question about bpftrace syntax and hoping that someone might have seen this before. In looking at the bpftrace reference document, I've been able to trace a user-app function successfully. No problems there. What I can't figure out is how…
2
votes
1 answer

Main difference between ebpf loaders

If I understood well there are different ebpf loaders: bpf_load.c into the kernel source code libbpf bpftool tc ... <-- others? Which are the main differences between them? Are they always interchangeably? Should I always prefer libbpf?
Maicake
  • 1,046
  • 10
  • 34
2
votes
1 answer

context for each type of ebpf program

I've seen that for each type of ebpf program there is a different input (context) to the program. For example in the case of a BPF_PROG_TYPE_SOCKET_FILTER program a pointer to struct __sk_buff is passed as an argument. Where are defined the…
Maicake
  • 1,046
  • 10
  • 34
2
votes
2 answers

XDP offloaded mode flags set is not working with bcc

I'm trying to run this tutorial XDP code that is provided in the bcc. The code I use is this script: bcc/examples/networking/xdp/xdp_drop_count.py. and to my understanding, XDP flag works as follows (from that question): #define XDP_FLAGS_SKB_MODE…
Rosè
  • 345
  • 2
  • 13
2
votes
1 answer

with attach_xdp, does flags control the mode?

When I use xdp with eBPF, I figured I could use ip link to set mode. For example, ip link set dev eno1 xdpoffload obj xdp.o sec .text I wanted to know how that xdpoffload or generic or native mode is implemented in the code. So I was looking at…
Rosè
  • 345
  • 2
  • 13
2
votes
1 answer

BPF verifier rejecting XDP program due to back-edge even though pragma unroll is used

So, as per title I'm trying to load an XDP program, when surprisingly the bpf verifier kicks in spitting in my face with the famous back-edge error: libbpf: load bpf program failed: Invalid argument libbpf: -- BEGIN DUMP LOG --- libbpf: back-edge…
pa5h1nh0
  • 262
  • 3
  • 13
2
votes
1 answer

Is it possible to tail call eBPF codes that use different modes?

Is it possible to tail call eBPF codes that use different modes? For example, if I coded a code that printk("hello world") using kprobe, would I be able to tail call a XDP code afterwards or vice versa? I programmed something on eBPF that uses a…
Rosè
  • 345
  • 2
  • 13
2
votes
0 answers

How long TCP state change from SYN_RECV to ESTABLISHED should take?

While playing with eBPF i tried tcpstates and noticed very low time for TCP state transition SYN_RECV -> ESTABLISHED My numbers from tests: SYN_RECV -> ESTABLISHED 0.015 SYN_RECV -> ESTABLISHED 0.017 SYN_RECV -> ESTABLISHED 0.051 From…
it4ddict
  • 29
  • 5
2
votes
0 answers

Detach bpf object from event?

I want to be able to detach my BPF objects from an attached event. Is the only way to detach from an event to destroy the BPF object? I'm trying to avoid having to create/destroy objects everytime a new program that I want to trace is launched…
belgarn
  • 21
  • 2