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
1
vote
0 answers

Can I collaborate my own kernel module and eBPF program?

I am trying to write a project in which I need to write a customized kernel module and some eBPF programs. In this project, I use eBPF programs to collect some data and store these data in the eBPF map, and these data are needed in my kernel…
Jzzzsen Li
  • 15
  • 3
1
vote
0 answers

Retrieving user friendly TSC from a bpf program

Is there any way to correlate user accessible timestamps like RDTSC with timestamps from bpf_ktime_get_ns() in a bpf program? The reason of asking is that the kernel time is not related to time that user can get. So I need to find out a graceful…
vtsymbal
  • 21
  • 2
1
vote
1 answer

PERCPU map performance gains when only reading from XDP

I write to eBPF maps of type BPF_MAP_TYPE_HASH and BPF_MAP_TYPE_ARRAY in user space and read the maps from an XDP program. Would I get performance improvements in the XDP program if I use BPF_MAP_TYPE_PERCPU_HASH and BPF_MAP_TYPE_PERCPU_ARRAY? In…
user2233706
  • 6,148
  • 5
  • 44
  • 86
1
vote
1 answer

A bpf program is loaded but not found: how to debug it

Short description of problem/question In bpf samples, the libbpf calls in user program were successful: bpf_object__open_file bpf_object__load But the following ones failed: bpf_object__find_program_by_name bpf_object__find_map_fd_by_name Ho to…
vtsymbal
  • 21
  • 2
1
vote
1 answer

Compiling eBPF programs over multiple files into a single bpf object file

I am working on a project with eBPF code with one file and it is getting quite long, I was hoping I could split it into multiple files. I am trying to build multiple files into bpf object files and then link them together into one object file. This…
imawful
  • 69
  • 5
1
vote
0 answers

How to detect that bpftrace has attached its probes and is ready to trace?

I working with bpftrace scripts attaching to hundreds of probes and sometimes it takes a couple of seconds or minutes for bpftrace to start tracing. This is not an issue if I'm providing the command via -c because the command starts when the tracer…
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
1
vote
0 answers

What would cause Go to not be able put floats in registers without loss of precision? (tracing with bpf)

I'm tracing go functions with uprobes/bpf and printing the contents of registers/stacks to confirm I understand the Go ABI specification. I'm looking at a function with just floats as parameters, and what I notice is that sometimes Go puts these…
1
vote
1 answer

How to detach ebpf cgroup programs without using bpftool?

I am using Cilium ebpf to attach programs to cgroups. However, in my code I didn’t detach the program correctly and now I have some cgroup programs running in the background and I am trying to look for other ways to close them. I tried to delete…
Angela
  • 23
  • 4
1
vote
0 answers

bpf helpers: how to convert struct sock *sk to struct xdp_sock *?

Given a struct socket *sock I basically try to do the following: struct sock { struct sock_common __sk_common; } __attribute__((preserve_access_index)); struct socket { struct sock *sk; // sic! a pointer }…
TheDiveO
  • 2,183
  • 2
  • 19
  • 38
1
vote
1 answer

Why are the kernel function names not resolving in the output of kstack()?

I am trying to see the kernel stack with the following bpftrace command: root@ubuntu:~$ bpftrace -e 'k:vfs_read{@[kstack] = count()}' Attaching 1 probe... ^C @[ 0xffffffffa78d2dc1 0xffffffffa78d306a 0xffffffffa7604fd7 …
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
1
vote
0 answers

Can't compile linux kernel 5.10 with BTF type info enabled

I am want to compile linux 5.10.162 with CONFIG_DEBUG_INFO_BTF=y, the end goal being to enable bpf CO-RE. However, the build is failing with: + ./tools/bpf/resolve_btfids/resolve_btfids vmlinux FAILED unresolved symbol udp_sock I first thought it…
Ivan Kalchev
  • 345
  • 1
  • 4
  • 9
1
vote
1 answer

How to get the name, or the ID, of the System Call that was detected with BCC/eBPF

I have this code, which is largely inspired by the syscount.py tool present in BCC: BPF_HASH(data, u32, u64); TRACEPOINT_PROBE(raw_syscalls,sys_exit){ u64 pid_tgid = bpf_get_current_pid_tgid(); u32 key = pid_tgid >> 32; u32 tid = (u32)pid_tgid; u64…
1
vote
2 answers

eBPF vs non-eBPF tracepoint/kprobes

As per this document (amongst others): https://blogs.oracle.com/linux/post/taming-tracepoints-in-the-linux-kernel It is possible using both eBPF and other kernel-provided mechanisms to register callbacks for tracepoints or kprobes. It seems that…
Mario
  • 1,661
  • 13
  • 22
1
vote
1 answer

eBPF verifier: R1 is not a scalar

I have this eBPF code: struct sock_info { struct sockaddr addr; }; SEC("tracepoint/syscalls/sys_enter_accept4") int sys_enter_accept4(int fd, struct sockaddr *upeer_sockaddr, int *upeer_addrlen, int flags) { struct sock_info *iad =…
Mario
  • 1,661
  • 13
  • 22
1
vote
1 answer

What is the difference between the following two eBPF program types BPF_PROG_TYPE_SYSCALL and BPF_PROG_TYPE_KPROBE?

So I am assuming that BPF_PROG_TYPE_SYSCALL programs are triggered whenever a particular syscall is executed inside the kernel. Can't BPF_PROG_TYPE_KPROBE ebpf programs be used for that purpose? kprobes can hook into any kernel function and syscalls…
Palash Nigam
  • 1,653
  • 3
  • 14
  • 26