Chapters

The whole tutorial, in order.

Every part and chapter, linked. Read it top to bottom the first time through; each program chapter also stands on its own once the lab from Foundations exists. New here? Start with the Tutorial Outline at the top of Foundations.

Part 0 Foundations

Set up the disposable Fedora 44 KVM lab, the Grafana/OTel stack, and the Rust + Aya toolchain, then write and deploy your first eBPF program.

  1. 0 Tutorial outline What this tutorial covers, how the chapters are grouped, and the order in which they build on each other.
  2. 1 Prerequisites The hardware floor, the host OS, and the virtualization stack you need before building anything.
  3. 2 Lab setup: the eBPF target VM(s) Provision a disposable Fedora 44 guest under libvirt with one script, prove you can deploy a binary to it, and add a second guest plus the network between them for two-host tests.
  4. 3 The observability stack Stand up Grafana + Tempo + Mimir + Loki in one Podman container, run a Python 3.14 OTLP client, and learn how your Rust eBPF programs will report their measurements into it.
  5. 4 The Rust + Aya toolchain Install Rust 1.96.0 via rustup (not dnf), add the nightly BPF target and bpf-linker, scaffold projects with cargo-generate and the aya-template, and set up RustRover. Plus the background that pays off later: the LLVM/Clang/rustc compiler path that turns code into BPF bytecode, the wider eBPF tooling landscape, and the glibc-vs-musl choice for your loader binary.
  6. 5 eBPF concepts and tools Programs, maps, the verifier, BTF and CO-RE, program types and attach points: the mental model you need before writing the first Aya program, and how bpftool and bpftrace fit in.
  7. 6 Hello, eBPF A first Aya program (a tracepoint that counts process executions in the kernel and reports to Grafana), with a short libbpf / libbpf-rs warm-up first, deployed to the target VM.

Part 1 Tracing the kernel

Observe kernel and syscall activity with kprobes, fentry/fexit, and tracepoints: from file deletes and opens to process lifecycle and signals.

  1. 7 kprobe + unlink Your first kprobe: attach to the kernel function behind file deletion, read the calling process's identity, attempt to read the filename argument, and stream per-event records to user space via a ring buffer.
  2. 8 fentry + unlink Revisit the unlink target with fentry/fexit, BTF-trampoline probes that are lower overhead than kprobes, give typed argument access, and let fexit read the function's return value, so we can report whether each unlink actually succeeded.
  3. 9 opensnoop Trace every file open with stable syscall tracepoints: read tracepoint arguments by offset, learn the user-vs-kernel memory-read distinction, and pair entry and exit to report which process opened which file with what result.
  4. 10 sigsnoop A shorter sibling to opensnoop: one tracepoint on the kill syscall to trace which process signals which, with signal-number-to-name mapping done in user space.
  5. 11 execsnoop Trace every program launch with its full command line: the new skill is reading argv, an array of user-space string pointers, in a bounded verifier-friendly loop, written straight into the ring-buffer slot.
  6. 12 exitsnoop The bookend to execsnoop: trace process termination and exit codes via the exit_group tracepoint, getting the status without touching task_struct, and learn how the exit-code encoding differs from the wait() status.

Part 2 User-space & language probing

Turn the lens around: uprobes, USDT, and probing inside running applications and language runtimes: bash, your own Rust binaries, TLS, and more.

  1. 13 uprobe + bashreadline The first user-space probe: attach a uretprobe to bash's readline() to capture commands typed at interactive prompts, learning how uprobes target a binary or library by symbol and read the calling process's memory.
  2. 14 uprobe on a Rust binary Point a uprobe at a function in a Rust program you built: confront symbol mangling and calling conventions, read a function argument at entry, and lay the groundwork for tracing your own services.
  3. 15 BTF-assisted uprobe Read a struct argument from a uprobe by following a pointer into the target's memory, and understand how BTF recovers a struct's layout so you can probe binaries you didn't write without hardcoding offsets.
  4. 16 Bootstrap: containerized targets (Java & Python) Stand up real application targets (Java 25 + Quarkus and Python 3.14 + FastAPI, both as multi-stage UBI containers) and learn to observe a process that lives inside a container by scoping eBPF to its cgroup, with crun's role on Fedora.
  5. 17 sslsniff See the plaintext crossing TLS by probing OpenSSL (SSL_write before encryption and SSL_read after decryption), learning to probe a shared library and to capture bounded binary data, with the ethics that come with it.
  6. 18 funclatency Time a function per call by pairing a uprobe at entry with a uretprobe at return and bpf_ktime_get_ns, then turn the durations into an OTLP latency histogram, and weigh per-call events against an in-kernel histogram.
  7. 19 Tracing goroutine states Probe the Go scheduler's state machine through runtime.casgstatus, and meet two Go-specific realities head-on: the register ABI (args aren't where C puts them) and why you must never put a uretprobe on Go.
  8. 20 javagc Time JVM garbage-collection pauses; learn what USDT is and why it's the ideal surface, discover that a stock OpenJDK ships no gc USDT markers, and fall back to uprobing the G1 collector's real stop-the-world function resolved from libjvm.so's symbol table.

Part 3 Performance & resources

Measure where time and resources go: scheduling latency, hardware IRQs, sampling profiles, memory leaks, block-I/O patterns, and power.

  1. 21 runqlat Measure scheduler run-queue latency (how long tasks wait runnable-but-not-running) by stitching together the sched tracepoints, and meet the technique that hot paths demand: aggregating a histogram in the kernel instead of emitting per-event.
  2. 22 hardirqs Measure the time the kernel spends in hardware-interrupt handlers, per IRQ vector, by timing the irq tracepoints keyed by CPU and accumulating per-vector totals in a kernel map, and understand why hardirq time is hidden latency.
  3. 23 profile Build a sampling CPU profiler with a perf_event program firing at a fixed frequency across all CPUs, capture kernel and user call stacks with bpf_get_stackid and StackTrace maps, and emit flame-graph-ready folded output.
  4. 24 memleak Find allocations that are never freed by pairing malloc/calloc with free on libc, recording each outstanding allocation's call stack with bpf_get_stackid so the leak points back to the code that made it.
  5. 25 biopattern Classify block-device I/O as sequential or random per device by tracking each device's sector position across the block_rq_issue tracepoint: the access pattern that determines whether storage thrives or thrashes.
  6. 26 Energy monitoring Attribute power consumption to individual processes (the modern sustainability use of eBPF) by crediting each task its on-CPU time and multiplying its share by system power from RAPL, and why virtualization makes this hard.

Part 4 Networking

See and shape packets: TCP connection latency and state, L7 tracing, sockops, TC, and XDP: including a load balancer and packet capture.

  1. 27 tcpconnlat Open the networking part by building out the second VM and measuring active TCP connection latency (connect() to SYN-ACK) with kprobes on the kernel TCP stack keyed by the socket pointer, reading struct fields by offset.
  2. 28 tcpstates Trace every TCP connection through its state machine using the single stable sock:inet_sock_set_state tracepoint: the clean, offset-light counterpart to the connect-latency kprobes, with the endpoints handed to you directly.
  3. 29 L7 tracing: HTTP Parse application-layer HTTP out of raw packets with a socket-filter program (walking Ethernet, IPv4, and TCP headers to the payload) and weigh it against the syscall/uprobe approach for encrypted or buffer-level L7.
  4. 30 sockops Meet a different model: a sock_ops program attached to a cgroup that the TCP stack calls back at connection-lifecycle moments, handing you the 4-tuple directly, and that can also act on the socket, not just observe it.
  5. 31 tc-BPF: acting on packets Move from observing traffic to acting on it: attach a classifier to the clsact qdisc, count egress packets per protocol in-kernel, and drop traffic to a port with a TC_ACT_SHOT verdict.
  6. 32 XDP: the earliest hook Drop and count packets at XDP, the eXpress Data Path, in the driver before an sk_buff is allocated. The fastest eBPF hook, raw packet pointers, and the bounds-checking discipline the verifier demands.
  7. 33 XDP capture: a tcpdump in eBPF Use XDP to observe rather than drop: parse and filter packets in the kernel, and ship only the interesting ones (TCP SYN/FIN/RST) to user space through a ring buffer for a live tcpdump-style view of connection activity.
  8. 34 XDP load balancer: rewriting packets Make XDP forward, not just observe: a UDP load balancer that rewrites the destination port of packets aimed at a virtual port, round-robins them across backends through a map, and passes them on: the packet-mutation and backend-selection core of an XDP load balancer.
  9. 35 Testing eBPF with BPF_PROG_TEST_RUN Unit-test eBPF programs without a NIC or live traffic: feed a hand-built packet to a loaded program with BPF_PROG_TEST_RUN, get back the verdict, output buffer, and duration, and assert on them: turning a verifier-only check into a real test suite.
  10. 36 tcx: the modern tc attach Attach tc programs the modern way: tcx (kernel 6.6+) replaces the clsact-qdisc wiring with bpf_link ownership and a kernel-managed ordering of multiple programs per hook: auto-detach on close, no manual qdisc, and composable with other tools.

Part 5 Security & LSM

Enforce and observe security with LSM hooks and signal programs: connection control, tamper detection, and lab-only offense to understand defense.

  1. 37 BPF LSM: from observing to deciding The shift from watching the kernel to mediating it: attach a BPF program to an LSM hook whose return value allows (0) or denies (-EPERM) an operation, and confine a single container's outbound connections by cgroup without touching the host.
  2. 38 Signal programs: reacting with force The other enforcement style: instead of denying a syscall at an LSM hook, react to one. A tracepoint on execve matches a forbidden binary and calls bpf_send_signal(SIGKILL) to kill the process before it runs: a 'signal program', lab-only offense that illuminates defense.
  3. 39 Hiding a process (lab-only offense) Understand rootkit-style eBPF by building one in the lab: rewrite the getdents64 buffer with bpf_probe_write_user so a chosen PID vanishes from /proc, invisible to ps and ls, then learn exactly how a defender detects the tampering.
  4. 40 Protecting a file with LSM The defensive counterpart to the offense chapter: an LSM program on inode_permission that denies write access to one protected file by inode (making it read-only even for root), and a first look at reading a kernel struct field from an LSM program (with CO-RE deferred to a later chapter).
  5. 41 Faking your way to root (lab-only offense) The third lab-only offense: intercept the read() a privileged process makes and rewrite the bytes it gets back. When sudo reads /etc/sudoers, inject a line granting full privileges (the file on disk untouched) to see how read-buffer tampering escalates, and how to detect it.
  6. 42 A security sensor: telemetry and shielding Close the security part by building the sensor layer of a runtime-security tool: several attacker-relevant hooks (execve, ptrace, setuid) feeding one structured event stream to Grafana, with a clear path from observing to shielding.

Part 6 Schedulers (sched_ext)

Write real CPU schedulers in BPF with sched_ext / struct_ops, from a minimal policy to a more realistic one.

  1. 43 Writing a scheduler: sched_ext and struct_ops A new kind of BPF program: implementing a CPU scheduler with sched_ext and the struct_ops model. Walk the minimal scx_simple scheduler's callbacks, understand dispatch queues and the safety watchdog, then run the real scheduler and watch it work with an Aya tracing probe.
  2. 44 A realistic policy: keeping work on warm cores Move past the minimal scheduler to a real strategy. The scx_nest policy concentrates work on a small set of warm, high-frequency cores instead of spreading it thin: express it through CPU selection and a nest of cores, run the real scheduler, and watch the concentration appear with an Aya per-CPU busy probe.

Part 7 Application targets

Probe real workloads end to end: an nginx server, a three-signal OpenTelemetry final project, and a postgres database, tying together kernel and user-space techniques.

  1. 45 Probing nginx: latency inside a real server Turn the toolkit on production software: attach uprobes to a containerized nginx's request functions, key timing by the request object to measure per-request handling latency without touching nginx, and confront the real-world frictions: symbols and container namespaces.
  2. 46 Final project: tying the three signals together A short final project for the applications part. We can't symbol-probe Java or Python the way we did nginx, so we instrument at the kernel socket layer, the way the OpenTelemetry eBPF Instrumentation (OBI) project does, and turn one request into three correlated signals: a span, a log, and a RED metric sharing a trace_id. Then we watch the click-through correlation in Grafana and place it against the production tool.
  3. 47 Probing postgres: queries and lock waits A harder target: a postgres database. Attach uprobes to a multi-process server so one probe covers every backend, capture per-query latency with the SQL text, and measure the lock-wait time that is invisible from outside the database. Meet USDT, the stable probe API databases ship, and cross-check against postgres's own statistics views.

Part 8 Advanced kernel surface

The modern (2024โ€“2026) BPF feature set: kfuncs, BPF tokens, workqueues, struct_ops, dynptr, BPF arenas, iterators, and user ring buffers.

  1. 48 Detaching and pinning: outliving the loader Open the advanced part with the lifecycle question every earlier chapter dodged: what happens to a program when its loader exits? Learn how BPF objects are reference-counted, pin a program, map, and link to bpffs so they survive the loader, read the pinned map from a separate process, and detach by removing the pin.
  2. 49 Syscall programs: when BPF loads BPF A program type with no hook: BPF_PROG_TYPE_SYSCALL programs run on demand and can call the bpf() syscall themselves via bpf_sys_bpf. Understand loader programs (a 'strace of libbpf' replayed in-kernel) and the light skeletons bpftool builds from them, the path toward libbpf-free and signed program loading.
  3. 50 The user ring buffer: a channel into BPF Every ring buffer so far carried data kernel-to-user. The user ring buffer runs the other way: user space is the producer and the BPF program is the consumer, draining submitted samples with bpf_user_ringbuf_drain and a callback. Learn when to reach for it over a plain map, and meet the dynptr that each sample arrives as.
  4. 51 Userspace eBPF: the same bytecode, no kernel eBPF is a portable bytecode ISA, and it doesn't need the kernel. Run an eBPF program in a user-space VM with the Rust rbpf crate (interpreter and JIT, with a Rust helper the bytecode calls), needing no root, no kernel, not even the lab VM. Then meet bpftime, the runtime that accelerates uprobes in user space.
  5. 52 kfuncs: calling the kernel, the modern way The BPF helper list froze, so the kernel grew a better mechanism: kfuncs, real kernel functions exposed to BPF through BTF, with typed pointer arguments and per-function flags. Understand why helpers stopped scaling, how the KF_ACQUIRE/KF_RELEASE/KF_RET_NULL/KF_TRUSTED_ARGS flags let the verifier reason about kernel objects, and write an Aya program that looks up a task by pid and is forced to release it.
  6. 53 The BPF token: delegating BPF into containers Loading BPF has always demanded capabilities in the init namespace: all or nothing for a container. The BPF token (kernel 6.9) breaks that open: a privileged runtime mounts a bpffs with four delegation axes, a trusted unprivileged container derives a token from it, and the kernel checks the token instead of init-namespace capabilities. Learn the capability problem it solves, the delegation model, and where it plugs into Aya.
  7. 54 Timers and workqueues: deferred work in the kernel A BPF program runs to completion and cannot sleep or loop forever, so how does it do something later, or periodically, or move expensive work off a hot probe? BPF timers (kernel 5.15) fire a callback in softirq context and can re-arm themselves; BPF workqueues (kernel 6.10) run a sleepable callback in process context. Learn the init/set_callback/start lifecycle, build an in-kernel periodic aggregator, and know when to reach for each.
  8. 55 struct_ops: BPF that implements the kernel Most BPF observes or filters at a hook the kernel calls. struct_ops inverts that: the kernel defines an interface (a struct of function pointers) and BPF supplies the whole implementation, which the kernel then calls into like a built-in module. Understand the vtable model behind the schedulers, write a minimal TCP congestion-control algorithm in BPF, and see the same mechanism reused across the kernel.
  9. 56 Dynptrs and arenas: flexible memory for BPF Classic BPF memory is rigid: fixed-size maps, fixed-size stack, bounds the verifier can prove at compile time. Two modern primitives loosen that. A dynptr is a verifier-tracked handle to a variable-length region: the thing the user ring buffer handed you. A BPF arena is a sparse memory region shared zero-copy with user space, where BPF builds real pointer-based data structures. Learn both, and when each applies.
  10. 57 BPF iterators: walking the kernel Closing the advanced part with one more inversion. Instead of reacting to an event, a BPF iterator is the body of an in-kernel loop: the kernel walks a set (every task, every socket, every map entry) and calls your program once per element, which emits through a seq_file you can cat. Learn the iterator program type, the open-coded iterators that put bounded loops anywhere, and why pushing iteration into the kernel beats dragging state to user space.

Part 9 Operating eBPF

Operate eBPF in production: CO-RE portability, L3AF-style zero-downtime upgrades, AI/GPU offloading, power management, and where to go next.

  1. 58 CO-RE: compile once, run everywhere The portability machinery the whole book has leaned on, finally examined head-on. Kernel struct layouts differ across versions, so a hardcoded field offset breaks on the next kernel. CO-RE compiles your program once against generic types, records relocations that name the fields you touch, and patches them at load time against the target kernel's BTF. Understand the relocations, how Aya does it transparently, how aya-tool generates portable bindings, and what 'works across the fleet' actually requires.
  2. 59 Operating eBPF: lifecycle, pinning, and zero-downtime upgrades A program you load in a demo dies the instant the loader exits: fine for a chapter, fatal for a service. Operating eBPF means treating programs like deployable, upgradable services: they outlive the process that loaded them, survive a loader restart, swap to a new version without dropping a packet, and keep their state across the upgrade. The three pillars are pinning, link update, and pinned maps, plus the orchestrators (L3AF, bpfman) that productize them.
  3. 60 Offload: running eBPF off the host CPU Every program so far has run on the host CPU in the kernel. Offload moves the work elsewhere: onto a SmartNIC's flow processor, a DPU's ARM Linux, an FPGA, or paired with GPU inference. Learn XDP's three modes and true hardware offload, why the practical 2026 answer is running ordinary eBPF on a DPU, where the FPGA and AI frontiers actually stand, and how Aya fits each.
  4. 61 Power and efficiency: attributing energy with eBPF The OS bills a process for CPU time, never for joules, so per-workload energy is invisible to ordinary tools. RAPL exposes socket-level energy, and eBPF supplies the missing piece: low-overhead per-workload CPU-time shares to divide that energy by. Learn the powercap interface, the attribution model and its known limits, where Kepler and the field stand in 2026, and the cpufreq_ext frontier where eBPF starts to control power, not just measure it.
  5. 62 Correlating the signals: Tempo, Mimir, and one trace We have used the metrics half of the observability stack for sixty chapters and never touched the rest. The otel-lgtm backend also runs Tempo for traces and Loki for logs, and the real power is correlation: from a metric spike to the exact trace, from that span to its logs, from a request to the eBPF view of what the kernel did. Learn spans and trace context, what each backend is (and where Mimir fits), and how Grafana links them by trace_id: the groundwork for the final project.
  6. 63 Final project: one request, every layer Everything the book has built, in a single request. A curl carrying a traceparent hits a FastAPI service that calls a Quarkus service; both emit spans, metrics, and logs on one trace_id, while an Aya program watches the same request at the socket layer and ties its eBPF view into that trace. The result is one investigation that reads from the HTTP span all the way down to the kernel: the payoff of sixty-two chapters.

Part 10 Field guide: the validation tools

Optional. The command-line tools we leaned on for validation all along (bpftrace, bpftool, and the BCC tools), and how to drive them from Python to turn one-liners into repeatable tools.

  1. 64 bpftrace from Python: one-liners into tools bpftrace has been our cross-check all along: the awk-for-the-kernel one-liner we ran to confirm what an Aya program reported. This optional field-guide chapter turns that into a repeatable instrument: bpftrace emits newline-delimited JSON, so a small Python wrapper can run a program, parse the stream by event type, and render a live table or feed a metric, exploration on tap, without writing or compiling Aya.
  2. 65 bpftool from Python: inventory and audit bpftool was our ground truth all book: prog show, map dump, link show, struct_ops register. It speaks JSON, so a small Python wrapper turns it into real tools: an inventory of every loaded program, a runtime 'top' of which BPF costs the most CPU, map dumps, attachment audits, and a kernel-feature summary. Several working examples you can run on any box.
  3. 66 The BCC tools: the ready-made suite BCC ships the ~100 ready-made tracers whose names recur in every cross-check: execsnoop, biolatency, runqlat, tcpconnect, profile. This closing field-guide chapter tours them, explains the two generations (classic Python+C that compiles at runtime versus precompiled libbpf-tools CO-RE binaries), and drives them from Python: resolve a tool, run it, parse its columns into a summary. Several working examples, plus a minimal BCC program to show what a tool is underneath.

Part 11 Retrospective

A look back across the whole arc, from a kprobe counting unlink to operating a fleet: what held throughout, and where eBPF and Aya go next.

  1. 67 Retrospective: the whole arc, and the road ahead A look back across everything, from a kprobe counting unlink to a single request traced through two services and the kernel. What stayed constant, what changed in how you think about the kernel, the true state of the code, and where eBPF and Aya are heading: the all-Rust frontier, sched_ext and struct_ops, cpufreq_ext, OBI, and the operating layers above.

Part 12 Addenda

Optional extensions that apply the book's machinery to a special case, starting with observing a homomorphic-encryption workload you cannot read.

  1. 68 Final-project addendum: observing a homomorphic-encryption workload A final project extension. Homomorphic encryption lets a server compute on data it can never see. That makes ordinary observability (log the inputs, trace the values) both impossible and forbidden. eBPF is the right fit precisely because it measures timing and resource behavior without touching operands. We attach uprobes to a TFHE-rs workload's operation boundaries, build a per-operation latency histogram, and surface it in Grafana: observing the system while the data stays sealed.
  2. 69 Appendix: eBPF metrics with Performance Co-Pilot (PCP) Performance Co-Pilot is the other major metrics model: pull-and-record rather than push-and-stream, host-centric, decades old, and shipped in Fedora. It has a first-class eBPF on-ramp: pmdabpf runs BPF CO-RE modules and pmdabpftrace runs bpftrace scripts, both surfaced as ordinary PCP metrics with archives, alerting, and a Grafana plugin. This appendix covers what PCP is, how it's used and extended, how it meets eBPF, and how it complements the book's OTLP stack.