SlideShare a Scribd company logo
1 of 27
Download to read offline
© Netronome 2018
eBPF Tooling
and Debugging Infrastructure
Quentin Monnet
Fall eBPF Webinar Series • 2018-10-09
Injecting Programs into the Kernel
eBPF programs are usually compiled from C (or Go, Rust, Lua…) to eBPF bytecode
They are injected into the kernel with the bpf() system call
Safety and termination are ensured by the kernel verifier
Programs can be JIT (Just-In-Time) compiled
Once loaded, programs can be attached to a hook in the kernel (socket, TC, XDP…)
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 2/27
eBPF for Network Packet Processing
Userspace
Kernel
Host JIT
Host CPU
NFP JIT
eBPF bytecode
C program
bpf() syscall
Verifier
LLVM
Agilio SmartNIC
ndo_bpf()
ndo_bpf()
Hardware
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 3/27
Agenda
Short reminder about eBPF infrastructure and program loading… DONE
Understand the basic tools available for working with eBPF
Understand how to dump the eBPF instructions at the different stages of the process
Learn how to avoid some common mistakes
Learn where to find more resources for troubleshooting other issues
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 4/27
eBPF for Network Packet Processing
Userspace
Kernel
Host JIT
Host CPU
NFP JIT
eBPF bytecode
C program
bpf() syscall
Verifier
LLVM
Agilio SmartNIC
ndo_bpf()
ndo_bpf()
Hardware
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 5/27
From C to eBPF Bytecode: Tools
Compile with clang
$ clang -O2 -emit-llvm -c sample_ret0.c -o - | 
llc -march=bpf -mcpu=probe -filetype=obj -o sample_ret0.o
Dump with llvm-objdump (v4.0+)
$ llvm-objdump -d -r -print-imm-hex sample_ret0.o
sample_ret0.o: file format ELF64-BPF
Disassembly of section .text:
func:
0: b7 00 00 00 00 00 00 00 r0 = 0
1: 95 00 00 00 00 00 00 00 exit
If -g is passed to clang, llvm-objdump -S can dump the original C code
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 6/27
From C to eBPF Bytecode: Common Mistakes
Unroll loops
next_iph_u16 = (u16 *)iph;
#pragma clang loop unroll(full)
for (i = 0; i < sizeof(*iph) >> 1; i++)
csum += *next_iph_u16++;
Force function inlining on older kernels (before v4.16)
Functional errors will be detected only at load time by the verifier
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 7/27
From C to eBPF, in Two Steps: eBPF Assembly
Compile from C to eBPF assembly file
$ clang -target bpf -S -o sample_ret0.S sample_ret0.c
$ cat sample_ret0.S
.text
.globl func # -- Begin function func
.p2align 3
func: # @func
# %bb.0:
r0 = 0
exit
# -- End function
… Hack…
Then compile from assembly to eBPF bytecode (LLVM v6.0+)
$ clang -target bpf -c -o sample_ret0.o sample_ret0.S
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 8/27
eBPF for Network Packet Processing
Userspace
Kernel
Host JIT
Host CPU
NFP JIT
eBPF bytecode
C program
bpf() syscall
Verifier
LLVM
Agilio SmartNIC
ndo_bpf()
ndo_bpf()
Hardware
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 9/27
Loading eBPF Program
TC hook: create a qdisc and attach the program as a filter, with tc
# tc qdisc add dev eth0 clsact
# tc filter add dev eth0 ingress bpf 
object-file bpf_program.o section ”.text” direct-action
# tc filter show dev eth0 ingress
filter pref 49152 bpf chain 0
filter pref 49152 bpf chain 0 handle 0x1 sample_ret0.o:[.text] 
id 73 tag b07f8eff09a9a611
XDP: attach to the driver (or as “generic XDP”) with ip link
# ip -force link set dev eth0 xdp object sample_ret0.o section ”.text”
# ip link show dev eth0
11: eth0: <BROADCAST,NOARP> mtu 1500 xdpoffload qdisc noop state DOWN 
mode DEFAULT group default qlen 1000
link/ether 0e:41:b5:45:47:51 brd ff:ff:ff:ff:ff:ff
prog/xdp id 74 tag 704bfda100a6df93
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 10/27
Loading eBPF: Common Mistakes
tc, ip: Error fetching program/map!
→ Make sure to pass the correct section name (defaults to ”.text”)
With tc, direct-action (da) option is recommended (mandatory for offload): makes TC
consider return values as actions (pass, drop…) instead of queues id.
RTNETLINK answers: Device or resource busy
→ -force option with ip link to overwrite a program previously loaded
Make sure your version of iproute2 is recent enough
If in doubt, download and compile the latest version
For offload: v4.18 (iproute2-ss180813) recommended for perf map support
(see also Netronome eBPF – Getting Started Guide)
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 11/27
The Kernel eBPF Verifier: Checking Programs for Safety
The verifier performs many checks on control flow graph and individual instructions
It complains about:
Erroneous syntax (unknown instruction, incorrect usage for the instruction)
Too many instructions or maps or branches
Back edges (i.e. loops) in the control flow graph
Unreachable instructions
Jump out of range
Out of bounds memory access (data or stack, including passing stack pointers to functions)
Access to forbidden context fields (read or write)
Reading access to non-initialized memory (stack or registers)
Use of forbidden helpers for the current type of program
Use of GPL helpers in non-GPL program (mostly tracing)
R0 not initialized before exiting the program
Memory access with incorrect alignment
Missing check on result from map_lookup_elem() before accessing map element
…
Problem: error messages are not always easy to understand. Examples…
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 12/27
Extending Kernel eBPF Verifier for Offload
The NFP driver hooks into the verifier to add its own checks, but output any error in the
console just as the kernel verifier does
Verifier Analysis:
0: (b7) r2 = 0x32
1: (07) r2 += -8
2: (b7) r1 = 0x0
3: (85) call 6
[nfp] unsupported function id: 6
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 13/27
eBPF for Network Packet Processing
Userspace
Kernel
Host JIT
Host CPU
NFP JIT
eBPF bytecode
C program
bpf() syscall
Verifier
LLVM
Agilio SmartNIC
ndo_bpf()
ndo_bpf()
Hardware
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 14/27
JIT-compile eBPF Programs for the Hardware
Most programs will be offloaded smoothly if they have passed the verifiers.
Some error messages at JIT-compiling time cannot reuse the verifier buffer, they are sent to
the kernel logs (in /var/log/kernel, or print with dmesg)
[88613.915838] nfp 0000:04:00.0 nfp_p0: stack too large: program 576B > FW stack 512B
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 15/27
Program is Loaded: Introspection
We have passed the verifier! The program is loaded in the kernel
For map and program introspection: bpftool
• List maps and programs
• Load a program, pin it
• Dump program instructions (eBPF or JIT-ed)
• Dump and edit map contents
• etc.
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 16/27
Program is Loaded: Introspection (Program on the Host)
Dump kernel-translated instructions
# bpftool prog dump xlated id 4
0: (b7) r0 = 0
1: (95) exit
Dump JIT-ed instructions
# bpftool prog dump jited id 4
0: push %rbp
1: mov %rsp,%rbp
4: sub $0x28,%rsp
b: sub $0x28,%rbp
f: mov %rbx,0x0(%rbp)
13: mov %r13,0x8(%rbp)
[...]
33: mov 0x18(%rbp),%r15
37: add $0x28,%rbp
3b: leaveq
3c: retq
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 17/27
Program is Loaded: Introspection (Offloaded Program)
Dumping instructions of an offloaded program works exactly the same:
# bpftool prog dump jited id 4
0: .0 immed[gprB_6, 0x3fff]
8: .1 alu[gprB_6, gprB_6, AND, *l$index1]
10: .2 immed[gprA_0, 0x0], gpr_wrboth
18: .3 immed[gprA_1, 0x0], gpr_wrboth
20: .4 br[.15000]
[...]
NFP support for disassembler available in latest version of libbfd (binutils-dev v2.31)
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 18/27
Attaching eBPF
In our examples, attaching was actually performed by tc and ip link right after program load
Netlink “extended ack” (extack) messages in the console
Example: RTNETLINK answers: Device or resource busy
Same thing for offloaded programs
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 19/27
Debugging at Runtime with bpf_trace_printk()
eBPF helper bpf_trace_printk() prints to /sys/kernel/debug/tracing/trace
const char fmt[] = ”First four bytes of packet: %xn”;
bpf_trace_printk(fmt, sizeof(fmt), *(uint32_t *)data);
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 20/27
Debugging at Runtime with Perf Events
Also, support for “perf event arrays”, more efficient
Example: dump data from packet
struct bpf_map_def SEC(”maps”) pa = {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(int),
.max_entries = 64,
};
int xdp_prog1(struct xdp_md *xdp)
{
int key = 0;
bpf_perf_event_output(xdp, &pa, 0x20ffffffffULL, &key, 0);
return XDP_PASS;
}
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 21/27
Debugging at Runtime: Miscellaneous
No eBPF debugger at this time
User space interpreters: uBPF, rbpf
(Minor differences, some features missing, no verifier)
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 22/27
Tools: eBPF Programming Environment
Libraries for managing eBPF programs: libbpf (kernel tree, tools/lib/bpf), libbcc (bcc tools)
strace: support for bpf() system call
strace -e bpf ip link set dev nfp_p0 xdpoffload obj prog.o
valgrind: upcoming version (3.14) with support for bpf() system call
valgrind bpftool prog show
…
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 23/27
Next Steps for eBPF Tooling
Netronome remains involved! We do or intend to…
Improve components
• Error messages
• Existing tool set
• Documentation
Improve packaging
• bpftool
• libbpf
Help keep tools up-to-date
Create new tools?
• Thinking about ways to run eBPF in a debugger
• Maybe some work to do on the side of libpcap
We are not alone: eBPF community increasing, more and more activity!
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 24/27
Summary
eBPF programs do not run in user space: debugging is not trivial
But:
Tooling is getting better and better: more tools, more complete
Possible to dump the instructions at all the stages of the process
(llvm-obdjump, bpftool)
Possible to get some output (bpf_trace_printk(), perf event maps) at runtime
Debugging offloaded programs is nearly the same as for programs on the host
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 25/27
More resources
Netronome’s eBPF – Getting Started Guide
https://www.netronome.com/documents/305/eBPF-Getting_Started_Guide.pdf
Partial F.A.Q for verifier output: Kernel documentation (filter.txt)
https://www.kernel.org/doc/Documentation/networking/filter.txt
Netronome’s resources on eBPF
https://www.netronome.com/technology/ebpf/
Netronome’s sample eBPF applications
https://github.com/Netronome/bpf-samples
Kernel source code
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/
Documentation on eBPF helper functions, generated from kernel comments
https://github.com/iovisor/bpf-docs/blob/master/bpf_helpers.rst
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 26/27
The End
Thank you!
Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 27/27

More Related Content

What's hot

A Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPFA Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPFoholiab
 
Low Overhead System Tracing with eBPF
Low Overhead System Tracing with eBPFLow Overhead System Tracing with eBPF
Low Overhead System Tracing with eBPFAkshay Kapoor
 
TinyML - 4 speech recognition
TinyML - 4 speech recognition TinyML - 4 speech recognition
TinyML - 4 speech recognition 艾鍗科技
 
1 Vampir Overview
1 Vampir Overview1 Vampir Overview
1 Vampir OverviewPTIHPA
 
An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
 An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
An Open Discussion of RISC-V BitManip, trends, and comparisons _ ClaireRISC-V International
 
Porting and Optimization of Numerical Libraries for ARM SVE
Porting and Optimization of Numerical Libraries for ARM SVEPorting and Optimization of Numerical Libraries for ARM SVE
Porting and Optimization of Numerical Libraries for ARM SVELinaro
 
Analyzing ECP Proxy Apps with the Profiling Tool Score-P
Analyzing ECP Proxy Apps with the Profiling Tool Score-PAnalyzing ECP Proxy Apps with the Profiling Tool Score-P
Analyzing ECP Proxy Apps with the Profiling Tool Score-PGeorge Markomanolis
 
ONNC - 0.9.1 release
ONNC - 0.9.1 releaseONNC - 0.9.1 release
ONNC - 0.9.1 releaseLuba Tang
 
Debugging With GNU Debugger GDB
Debugging With GNU Debugger GDBDebugging With GNU Debugger GDB
Debugging With GNU Debugger GDBkyaw thiha
 
New Process/Thread Runtime
New Process/Thread Runtime	New Process/Thread Runtime
New Process/Thread Runtime Linaro
 
GEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkGEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkAlexey Smirnov
 
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerPragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerMarina Kolpakova
 
Exploring the Programming Models for the LUMI Supercomputer
Exploring the Programming Models for the LUMI Supercomputer Exploring the Programming Models for the LUMI Supercomputer
Exploring the Programming Models for the LUMI Supercomputer George Markomanolis
 
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization ApproachesPragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization ApproachesMarina Kolpakova
 
Arm tools and roadmap for SVE compiler support
Arm tools and roadmap for SVE compiler supportArm tools and roadmap for SVE compiler support
Arm tools and roadmap for SVE compiler supportLinaro
 
07 processor basics
07 processor basics07 processor basics
07 processor basicsMurali M
 
Programming Languages & Tools for Higher Performance & Productivity
Programming Languages & Tools for Higher Performance & ProductivityProgramming Languages & Tools for Higher Performance & Productivity
Programming Languages & Tools for Higher Performance & ProductivityLinaro
 
May2010 hex-core-opt
May2010 hex-core-optMay2010 hex-core-opt
May2010 hex-core-optJeff Larkin
 

What's hot (20)

A Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPFA Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
 
Qemu JIT Code Generator and System Emulation
Qemu JIT Code Generator and System EmulationQemu JIT Code Generator and System Emulation
Qemu JIT Code Generator and System Emulation
 
Low Overhead System Tracing with eBPF
Low Overhead System Tracing with eBPFLow Overhead System Tracing with eBPF
Low Overhead System Tracing with eBPF
 
TinyML - 4 speech recognition
TinyML - 4 speech recognition TinyML - 4 speech recognition
TinyML - 4 speech recognition
 
1 Vampir Overview
1 Vampir Overview1 Vampir Overview
1 Vampir Overview
 
An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
 An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
 
Porting and Optimization of Numerical Libraries for ARM SVE
Porting and Optimization of Numerical Libraries for ARM SVEPorting and Optimization of Numerical Libraries for ARM SVE
Porting and Optimization of Numerical Libraries for ARM SVE
 
Analyzing ECP Proxy Apps with the Profiling Tool Score-P
Analyzing ECP Proxy Apps with the Profiling Tool Score-PAnalyzing ECP Proxy Apps with the Profiling Tool Score-P
Analyzing ECP Proxy Apps with the Profiling Tool Score-P
 
ONNC - 0.9.1 release
ONNC - 0.9.1 releaseONNC - 0.9.1 release
ONNC - 0.9.1 release
 
Debugging With GNU Debugger GDB
Debugging With GNU Debugger GDBDebugging With GNU Debugger GDB
Debugging With GNU Debugger GDB
 
New Process/Thread Runtime
New Process/Thread Runtime	New Process/Thread Runtime
New Process/Thread Runtime
 
GEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkGEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions Framework
 
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerPragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
 
Exploring the Programming Models for the LUMI Supercomputer
Exploring the Programming Models for the LUMI Supercomputer Exploring the Programming Models for the LUMI Supercomputer
Exploring the Programming Models for the LUMI Supercomputer
 
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization ApproachesPragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
 
Arm tools and roadmap for SVE compiler support
Arm tools and roadmap for SVE compiler supportArm tools and roadmap for SVE compiler support
Arm tools and roadmap for SVE compiler support
 
07 processor basics
07 processor basics07 processor basics
07 processor basics
 
Programming Languages & Tools for Higher Performance & Productivity
Programming Languages & Tools for Higher Performance & ProductivityProgramming Languages & Tools for Higher Performance & Productivity
Programming Languages & Tools for Higher Performance & Productivity
 
Getting started with AMD GPUs
Getting started with AMD GPUsGetting started with AMD GPUs
Getting started with AMD GPUs
 
May2010 hex-core-opt
May2010 hex-core-optMay2010 hex-core-opt
May2010 hex-core-opt
 

Similar to eBPF Tooling and Debugging Infrastructure

ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!Affan Syed
 
Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdbRoman Podoliaka
 
DCSF 19 eBPF Superpowers
DCSF 19 eBPF SuperpowersDCSF 19 eBPF Superpowers
DCSF 19 eBPF SuperpowersDocker, Inc.
 
Virtual platform
Virtual platformVirtual platform
Virtual platformsean chen
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCKernel TLV
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareBrendan Gregg
 
Efficient System Monitoring in Cloud Native Environments
Efficient System Monitoring in Cloud Native EnvironmentsEfficient System Monitoring in Cloud Native Environments
Efficient System Monitoring in Cloud Native EnvironmentsGergely Szabó
 
Profiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf ToolsProfiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf ToolsemBO_Conference
 
Cray XT Porting, Scaling, and Optimization Best Practices
Cray XT Porting, Scaling, and Optimization Best PracticesCray XT Porting, Scaling, and Optimization Best Practices
Cray XT Porting, Scaling, and Optimization Best PracticesJeff Larkin
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDPlcplcp1
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudAndrea Righi
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Ray Jenkins
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Valeriy Kravchuk
 
CorePy High-Productivity CellB.E. Programming
CorePy High-Productivity CellB.E. ProgrammingCorePy High-Productivity CellB.E. Programming
CorePy High-Productivity CellB.E. ProgrammingSlide_N
 
DEF CON 27 - KYLE GWINNUP - next generation process emulation with binee
DEF CON 27 - KYLE GWINNUP - next generation process emulation with bineeDEF CON 27 - KYLE GWINNUP - next generation process emulation with binee
DEF CON 27 - KYLE GWINNUP - next generation process emulation with bineeFelipe Prado
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing LandscapeSasha Goldshtein
 
HKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightHKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightLinaro
 
Systemtap
SystemtapSystemtap
SystemtapFeng Yu
 
Accelerated .NET Memory Dump Analysis training public slides
Accelerated .NET Memory Dump Analysis training public slidesAccelerated .NET Memory Dump Analysis training public slides
Accelerated .NET Memory Dump Analysis training public slidesDmitry Vostokov
 

Similar to eBPF Tooling and Debugging Infrastructure (20)

ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!
 
Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdb
 
DCSF 19 eBPF Superpowers
DCSF 19 eBPF SuperpowersDCSF 19 eBPF Superpowers
DCSF 19 eBPF Superpowers
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of Software
 
Efficient System Monitoring in Cloud Native Environments
Efficient System Monitoring in Cloud Native EnvironmentsEfficient System Monitoring in Cloud Native Environments
Efficient System Monitoring in Cloud Native Environments
 
Profiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf ToolsProfiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf Tools
 
Cray XT Porting, Scaling, and Optimization Best Practices
Cray XT Porting, Scaling, and Optimization Best PracticesCray XT Porting, Scaling, and Optimization Best Practices
Cray XT Porting, Scaling, and Optimization Best Practices
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDP
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloud
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
 
CorePy High-Productivity CellB.E. Programming
CorePy High-Productivity CellB.E. ProgrammingCorePy High-Productivity CellB.E. Programming
CorePy High-Productivity CellB.E. Programming
 
DEF CON 27 - KYLE GWINNUP - next generation process emulation with binee
DEF CON 27 - KYLE GWINNUP - next generation process emulation with bineeDEF CON 27 - KYLE GWINNUP - next generation process emulation with binee
DEF CON 27 - KYLE GWINNUP - next generation process emulation with binee
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
 
HKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightHKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with Coresight
 
Systemtap
SystemtapSystemtap
Systemtap
 
Dpdk applications
Dpdk applicationsDpdk applications
Dpdk applications
 
Accelerated .NET Memory Dump Analysis training public slides
Accelerated .NET Memory Dump Analysis training public slidesAccelerated .NET Memory Dump Analysis training public slides
Accelerated .NET Memory Dump Analysis training public slides
 

More from Netronome

Disaggregation a Primer: Optimizing design for Edge Cloud & Bare Metal applic...
Disaggregation a Primer: Optimizing design for Edge Cloud & Bare Metal applic...Disaggregation a Primer: Optimizing design for Edge Cloud & Bare Metal applic...
Disaggregation a Primer: Optimizing design for Edge Cloud & Bare Metal applic...Netronome
 
LFSMM AF XDP Queue I-DS
LFSMM AF XDP Queue I-DSLFSMM AF XDP Queue I-DS
LFSMM AF XDP Queue I-DSNetronome
 
LFSMM Verifier Optimizations and 1 M Instructions
LFSMM Verifier Optimizations and 1 M InstructionsLFSMM Verifier Optimizations and 1 M Instructions
LFSMM Verifier Optimizations and 1 M InstructionsNetronome
 
Using Network Acceleration for an Optimized Edge Cloud Server Architecture
Using Network Acceleration for an Optimized Edge Cloud Server ArchitectureUsing Network Acceleration for an Optimized Edge Cloud Server Architecture
Using Network Acceleration for an Optimized Edge Cloud Server ArchitectureNetronome
 
Offloading TC Rules on OVS Internal Ports
Offloading TC Rules on OVS Internal Ports Offloading TC Rules on OVS Internal Ports
Offloading TC Rules on OVS Internal Ports Netronome
 
Quality of Service Ingress Rate Limiting and OVS Hardware Offloads
Quality of Service Ingress Rate Limiting and OVS Hardware OffloadsQuality of Service Ingress Rate Limiting and OVS Hardware Offloads
Quality of Service Ingress Rate Limiting and OVS Hardware OffloadsNetronome
 
ODSA Sub-Project Launch
 ODSA Sub-Project Launch ODSA Sub-Project Launch
ODSA Sub-Project LaunchNetronome
 
Flexible and Scalable Domain-Specific Architectures
Flexible and Scalable Domain-Specific ArchitecturesFlexible and Scalable Domain-Specific Architectures
Flexible and Scalable Domain-Specific ArchitecturesNetronome
 
Unifying Network Filtering Rules for the Linux Kernel with eBPF
Unifying Network Filtering Rules for the Linux Kernel with eBPFUnifying Network Filtering Rules for the Linux Kernel with eBPF
Unifying Network Filtering Rules for the Linux Kernel with eBPFNetronome
 
Massively Parallel RISC-V Processing with Transactional Memory
Massively Parallel RISC-V Processing with Transactional MemoryMassively Parallel RISC-V Processing with Transactional Memory
Massively Parallel RISC-V Processing with Transactional MemoryNetronome
 
Offloading Linux LAG Devices Via Open vSwitch and TC
Offloading Linux LAG Devices Via Open vSwitch and TCOffloading Linux LAG Devices Via Open vSwitch and TC
Offloading Linux LAG Devices Via Open vSwitch and TCNetronome
 
Efficient JIT to 32-bit Arches
Efficient JIT to 32-bit ArchesEfficient JIT to 32-bit Arches
Efficient JIT to 32-bit ArchesNetronome
 
eBPF & Switch Abstractions
eBPF & Switch AbstractionseBPF & Switch Abstractions
eBPF & Switch AbstractionsNetronome
 
P4 Introduction
P4 Introduction P4 Introduction
P4 Introduction Netronome
 
Host Data Plane Acceleration: SmartNIC Deployment Models
Host Data Plane Acceleration: SmartNIC Deployment ModelsHost Data Plane Acceleration: SmartNIC Deployment Models
Host Data Plane Acceleration: SmartNIC Deployment ModelsNetronome
 
The Power of SmartNICs
The Power of SmartNICsThe Power of SmartNICs
The Power of SmartNICsNetronome
 
DPDK Support for New HW Offloads
DPDK Support for New HW OffloadsDPDK Support for New HW Offloads
DPDK Support for New HW OffloadsNetronome
 
Comprehensive XDP Off‌load-handling the Edge Cases
Comprehensive XDP Off‌load-handling the Edge CasesComprehensive XDP Off‌load-handling the Edge Cases
Comprehensive XDP Off‌load-handling the Edge CasesNetronome
 
Open vSwitch Offload: Conntrack and the Upstream Kernel
Open vSwitch Offload: Conntrack and the Upstream KernelOpen vSwitch Offload: Conntrack and the Upstream Kernel
Open vSwitch Offload: Conntrack and the Upstream KernelNetronome
 

More from Netronome (20)

Disaggregation a Primer: Optimizing design for Edge Cloud & Bare Metal applic...
Disaggregation a Primer: Optimizing design for Edge Cloud & Bare Metal applic...Disaggregation a Primer: Optimizing design for Edge Cloud & Bare Metal applic...
Disaggregation a Primer: Optimizing design for Edge Cloud & Bare Metal applic...
 
LFSMM AF XDP Queue I-DS
LFSMM AF XDP Queue I-DSLFSMM AF XDP Queue I-DS
LFSMM AF XDP Queue I-DS
 
LFSMM Verifier Optimizations and 1 M Instructions
LFSMM Verifier Optimizations and 1 M InstructionsLFSMM Verifier Optimizations and 1 M Instructions
LFSMM Verifier Optimizations and 1 M Instructions
 
Using Network Acceleration for an Optimized Edge Cloud Server Architecture
Using Network Acceleration for an Optimized Edge Cloud Server ArchitectureUsing Network Acceleration for an Optimized Edge Cloud Server Architecture
Using Network Acceleration for an Optimized Edge Cloud Server Architecture
 
Offloading TC Rules on OVS Internal Ports
Offloading TC Rules on OVS Internal Ports Offloading TC Rules on OVS Internal Ports
Offloading TC Rules on OVS Internal Ports
 
Quality of Service Ingress Rate Limiting and OVS Hardware Offloads
Quality of Service Ingress Rate Limiting and OVS Hardware OffloadsQuality of Service Ingress Rate Limiting and OVS Hardware Offloads
Quality of Service Ingress Rate Limiting and OVS Hardware Offloads
 
ODSA Sub-Project Launch
 ODSA Sub-Project Launch ODSA Sub-Project Launch
ODSA Sub-Project Launch
 
Flexible and Scalable Domain-Specific Architectures
Flexible and Scalable Domain-Specific ArchitecturesFlexible and Scalable Domain-Specific Architectures
Flexible and Scalable Domain-Specific Architectures
 
Unifying Network Filtering Rules for the Linux Kernel with eBPF
Unifying Network Filtering Rules for the Linux Kernel with eBPFUnifying Network Filtering Rules for the Linux Kernel with eBPF
Unifying Network Filtering Rules for the Linux Kernel with eBPF
 
Massively Parallel RISC-V Processing with Transactional Memory
Massively Parallel RISC-V Processing with Transactional MemoryMassively Parallel RISC-V Processing with Transactional Memory
Massively Parallel RISC-V Processing with Transactional Memory
 
Offloading Linux LAG Devices Via Open vSwitch and TC
Offloading Linux LAG Devices Via Open vSwitch and TCOffloading Linux LAG Devices Via Open vSwitch and TC
Offloading Linux LAG Devices Via Open vSwitch and TC
 
Efficient JIT to 32-bit Arches
Efficient JIT to 32-bit ArchesEfficient JIT to 32-bit Arches
Efficient JIT to 32-bit Arches
 
eBPF & Switch Abstractions
eBPF & Switch AbstractionseBPF & Switch Abstractions
eBPF & Switch Abstractions
 
eBPF/XDP
eBPF/XDP eBPF/XDP
eBPF/XDP
 
P4 Introduction
P4 Introduction P4 Introduction
P4 Introduction
 
Host Data Plane Acceleration: SmartNIC Deployment Models
Host Data Plane Acceleration: SmartNIC Deployment ModelsHost Data Plane Acceleration: SmartNIC Deployment Models
Host Data Plane Acceleration: SmartNIC Deployment Models
 
The Power of SmartNICs
The Power of SmartNICsThe Power of SmartNICs
The Power of SmartNICs
 
DPDK Support for New HW Offloads
DPDK Support for New HW OffloadsDPDK Support for New HW Offloads
DPDK Support for New HW Offloads
 
Comprehensive XDP Off‌load-handling the Edge Cases
Comprehensive XDP Off‌load-handling the Edge CasesComprehensive XDP Off‌load-handling the Edge Cases
Comprehensive XDP Off‌load-handling the Edge Cases
 
Open vSwitch Offload: Conntrack and the Upstream Kernel
Open vSwitch Offload: Conntrack and the Upstream KernelOpen vSwitch Offload: Conntrack and the Upstream Kernel
Open vSwitch Offload: Conntrack and the Upstream Kernel
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Recently uploaded (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

eBPF Tooling and Debugging Infrastructure

  • 1. © Netronome 2018 eBPF Tooling and Debugging Infrastructure Quentin Monnet Fall eBPF Webinar Series • 2018-10-09
  • 2. Injecting Programs into the Kernel eBPF programs are usually compiled from C (or Go, Rust, Lua…) to eBPF bytecode They are injected into the kernel with the bpf() system call Safety and termination are ensured by the kernel verifier Programs can be JIT (Just-In-Time) compiled Once loaded, programs can be attached to a hook in the kernel (socket, TC, XDP…) Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 2/27
  • 3. eBPF for Network Packet Processing Userspace Kernel Host JIT Host CPU NFP JIT eBPF bytecode C program bpf() syscall Verifier LLVM Agilio SmartNIC ndo_bpf() ndo_bpf() Hardware Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 3/27
  • 4. Agenda Short reminder about eBPF infrastructure and program loading… DONE Understand the basic tools available for working with eBPF Understand how to dump the eBPF instructions at the different stages of the process Learn how to avoid some common mistakes Learn where to find more resources for troubleshooting other issues Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 4/27
  • 5. eBPF for Network Packet Processing Userspace Kernel Host JIT Host CPU NFP JIT eBPF bytecode C program bpf() syscall Verifier LLVM Agilio SmartNIC ndo_bpf() ndo_bpf() Hardware Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 5/27
  • 6. From C to eBPF Bytecode: Tools Compile with clang $ clang -O2 -emit-llvm -c sample_ret0.c -o - | llc -march=bpf -mcpu=probe -filetype=obj -o sample_ret0.o Dump with llvm-objdump (v4.0+) $ llvm-objdump -d -r -print-imm-hex sample_ret0.o sample_ret0.o: file format ELF64-BPF Disassembly of section .text: func: 0: b7 00 00 00 00 00 00 00 r0 = 0 1: 95 00 00 00 00 00 00 00 exit If -g is passed to clang, llvm-objdump -S can dump the original C code Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 6/27
  • 7. From C to eBPF Bytecode: Common Mistakes Unroll loops next_iph_u16 = (u16 *)iph; #pragma clang loop unroll(full) for (i = 0; i < sizeof(*iph) >> 1; i++) csum += *next_iph_u16++; Force function inlining on older kernels (before v4.16) Functional errors will be detected only at load time by the verifier Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 7/27
  • 8. From C to eBPF, in Two Steps: eBPF Assembly Compile from C to eBPF assembly file $ clang -target bpf -S -o sample_ret0.S sample_ret0.c $ cat sample_ret0.S .text .globl func # -- Begin function func .p2align 3 func: # @func # %bb.0: r0 = 0 exit # -- End function … Hack… Then compile from assembly to eBPF bytecode (LLVM v6.0+) $ clang -target bpf -c -o sample_ret0.o sample_ret0.S Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 8/27
  • 9. eBPF for Network Packet Processing Userspace Kernel Host JIT Host CPU NFP JIT eBPF bytecode C program bpf() syscall Verifier LLVM Agilio SmartNIC ndo_bpf() ndo_bpf() Hardware Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 9/27
  • 10. Loading eBPF Program TC hook: create a qdisc and attach the program as a filter, with tc # tc qdisc add dev eth0 clsact # tc filter add dev eth0 ingress bpf object-file bpf_program.o section ”.text” direct-action # tc filter show dev eth0 ingress filter pref 49152 bpf chain 0 filter pref 49152 bpf chain 0 handle 0x1 sample_ret0.o:[.text] id 73 tag b07f8eff09a9a611 XDP: attach to the driver (or as “generic XDP”) with ip link # ip -force link set dev eth0 xdp object sample_ret0.o section ”.text” # ip link show dev eth0 11: eth0: <BROADCAST,NOARP> mtu 1500 xdpoffload qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 0e:41:b5:45:47:51 brd ff:ff:ff:ff:ff:ff prog/xdp id 74 tag 704bfda100a6df93 Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 10/27
  • 11. Loading eBPF: Common Mistakes tc, ip: Error fetching program/map! → Make sure to pass the correct section name (defaults to ”.text”) With tc, direct-action (da) option is recommended (mandatory for offload): makes TC consider return values as actions (pass, drop…) instead of queues id. RTNETLINK answers: Device or resource busy → -force option with ip link to overwrite a program previously loaded Make sure your version of iproute2 is recent enough If in doubt, download and compile the latest version For offload: v4.18 (iproute2-ss180813) recommended for perf map support (see also Netronome eBPF – Getting Started Guide) Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 11/27
  • 12. The Kernel eBPF Verifier: Checking Programs for Safety The verifier performs many checks on control flow graph and individual instructions It complains about: Erroneous syntax (unknown instruction, incorrect usage for the instruction) Too many instructions or maps or branches Back edges (i.e. loops) in the control flow graph Unreachable instructions Jump out of range Out of bounds memory access (data or stack, including passing stack pointers to functions) Access to forbidden context fields (read or write) Reading access to non-initialized memory (stack or registers) Use of forbidden helpers for the current type of program Use of GPL helpers in non-GPL program (mostly tracing) R0 not initialized before exiting the program Memory access with incorrect alignment Missing check on result from map_lookup_elem() before accessing map element … Problem: error messages are not always easy to understand. Examples… Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 12/27
  • 13. Extending Kernel eBPF Verifier for Offload The NFP driver hooks into the verifier to add its own checks, but output any error in the console just as the kernel verifier does Verifier Analysis: 0: (b7) r2 = 0x32 1: (07) r2 += -8 2: (b7) r1 = 0x0 3: (85) call 6 [nfp] unsupported function id: 6 Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 13/27
  • 14. eBPF for Network Packet Processing Userspace Kernel Host JIT Host CPU NFP JIT eBPF bytecode C program bpf() syscall Verifier LLVM Agilio SmartNIC ndo_bpf() ndo_bpf() Hardware Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 14/27
  • 15. JIT-compile eBPF Programs for the Hardware Most programs will be offloaded smoothly if they have passed the verifiers. Some error messages at JIT-compiling time cannot reuse the verifier buffer, they are sent to the kernel logs (in /var/log/kernel, or print with dmesg) [88613.915838] nfp 0000:04:00.0 nfp_p0: stack too large: program 576B > FW stack 512B Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 15/27
  • 16. Program is Loaded: Introspection We have passed the verifier! The program is loaded in the kernel For map and program introspection: bpftool • List maps and programs • Load a program, pin it • Dump program instructions (eBPF or JIT-ed) • Dump and edit map contents • etc. Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 16/27
  • 17. Program is Loaded: Introspection (Program on the Host) Dump kernel-translated instructions # bpftool prog dump xlated id 4 0: (b7) r0 = 0 1: (95) exit Dump JIT-ed instructions # bpftool prog dump jited id 4 0: push %rbp 1: mov %rsp,%rbp 4: sub $0x28,%rsp b: sub $0x28,%rbp f: mov %rbx,0x0(%rbp) 13: mov %r13,0x8(%rbp) [...] 33: mov 0x18(%rbp),%r15 37: add $0x28,%rbp 3b: leaveq 3c: retq Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 17/27
  • 18. Program is Loaded: Introspection (Offloaded Program) Dumping instructions of an offloaded program works exactly the same: # bpftool prog dump jited id 4 0: .0 immed[gprB_6, 0x3fff] 8: .1 alu[gprB_6, gprB_6, AND, *l$index1] 10: .2 immed[gprA_0, 0x0], gpr_wrboth 18: .3 immed[gprA_1, 0x0], gpr_wrboth 20: .4 br[.15000] [...] NFP support for disassembler available in latest version of libbfd (binutils-dev v2.31) Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 18/27
  • 19. Attaching eBPF In our examples, attaching was actually performed by tc and ip link right after program load Netlink “extended ack” (extack) messages in the console Example: RTNETLINK answers: Device or resource busy Same thing for offloaded programs Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 19/27
  • 20. Debugging at Runtime with bpf_trace_printk() eBPF helper bpf_trace_printk() prints to /sys/kernel/debug/tracing/trace const char fmt[] = ”First four bytes of packet: %xn”; bpf_trace_printk(fmt, sizeof(fmt), *(uint32_t *)data); Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 20/27
  • 21. Debugging at Runtime with Perf Events Also, support for “perf event arrays”, more efficient Example: dump data from packet struct bpf_map_def SEC(”maps”) pa = { .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, .key_size = sizeof(int), .value_size = sizeof(int), .max_entries = 64, }; int xdp_prog1(struct xdp_md *xdp) { int key = 0; bpf_perf_event_output(xdp, &pa, 0x20ffffffffULL, &key, 0); return XDP_PASS; } Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 21/27
  • 22. Debugging at Runtime: Miscellaneous No eBPF debugger at this time User space interpreters: uBPF, rbpf (Minor differences, some features missing, no verifier) Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 22/27
  • 23. Tools: eBPF Programming Environment Libraries for managing eBPF programs: libbpf (kernel tree, tools/lib/bpf), libbcc (bcc tools) strace: support for bpf() system call strace -e bpf ip link set dev nfp_p0 xdpoffload obj prog.o valgrind: upcoming version (3.14) with support for bpf() system call valgrind bpftool prog show … Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 23/27
  • 24. Next Steps for eBPF Tooling Netronome remains involved! We do or intend to… Improve components • Error messages • Existing tool set • Documentation Improve packaging • bpftool • libbpf Help keep tools up-to-date Create new tools? • Thinking about ways to run eBPF in a debugger • Maybe some work to do on the side of libpcap We are not alone: eBPF community increasing, more and more activity! Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 24/27
  • 25. Summary eBPF programs do not run in user space: debugging is not trivial But: Tooling is getting better and better: more tools, more complete Possible to dump the instructions at all the stages of the process (llvm-obdjump, bpftool) Possible to get some output (bpf_trace_printk(), perf event maps) at runtime Debugging offloaded programs is nearly the same as for programs on the host Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 25/27
  • 26. More resources Netronome’s eBPF – Getting Started Guide https://www.netronome.com/documents/305/eBPF-Getting_Started_Guide.pdf Partial F.A.Q for verifier output: Kernel documentation (filter.txt) https://www.kernel.org/doc/Documentation/networking/filter.txt Netronome’s resources on eBPF https://www.netronome.com/technology/ebpf/ Netronome’s sample eBPF applications https://github.com/Netronome/bpf-samples Kernel source code https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/ Documentation on eBPF helper functions, generated from kernel comments https://github.com/iovisor/bpf-docs/blob/master/bpf_helpers.rst Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 26/27
  • 27. The End Thank you! Fall eBPF Webinar Series | eBPF Tooling and Debugging Infrastructure 27/27