SlideShare a Scribd company logo
©2016 Open-NFP 1
BPF and XDP Explained
Nic Viljoen
©2017 Open-NFP 2
Objectives of the Webinar
Give user a basic understanding of the architecture of eBPF
▪ What is it
▪ The programming model
▪ The kernel hooks
Give user a basic understanding of XDP
▪ What is it/Where is it
▪ How to use it (beginner level!)
▪ How to offload it
©2016 Open-NFP 3
What is eBPF?
eBPF is a simple way to extend the functionality of the kernel
at runtime
▪ Effectively a small kernel based machine
▪ 10 64bit registers
▪ 512 byte stack
▪ Data structures known as maps (unlimited size)
▪ 4K BPF instructions (Bytecode)
▪ Verifier to ensure kernel safe
▪ no loops, not more than 4K insns, not more than 64 maps etc…
▪ Can be JITed to ensure maximum performance
©2016 Open-NFP 4
Used Within Hyperscale-Not a Toy!
Those who have publically stated they are using BPF or are
planning to use BPF include
▪ Facebook-Load Balancing, Security
▪ Netflix-Network Monitoring
▪ Cilium Project
▪ Cloudflare-Security
▪ OVS-Virtual Switching
Due to its upstream safety and kernel support BPF
provides a safe, flexible and scalable networking tool
©2016 Open-NFP 5
The Programming Model
LLVM is used to compile from
supported languages
▪ C
▪ Go
▪ P4
When Programs are loaded
▪ Verifier is called-ensure safety
▪ Program is JITed-ensure perf
▪ Can also be offloaded
▪ nfp_bpf_jit upstream
LL VM
NFP
verifier.c
bpf_prog.go
bpf_prog.elf
bpf syscall
USER
JIT nfp_bfp_jit.c
Host CPU
KERNEL
HARDWARE
bpf_prog.p4
bpf_prog.c
©2016 Open-NFP 6
Maps-What They Are
Maps are key value stores
▪ Can be accessed from kernel or user space
▪ Used for interaction between kernel and user space programs
Number of different types of maps
▪ Used for interaction between kernel and user space programs
bpf_user.c
bpf_kern.c
Map
©2017 Open-NFP 7
Maps-How to use them
Creating Maps
▪ Option 1: create map with syscall
▪ bpf(BPF_MAP_CREATE, &bpf_attr, sizeof(bpf_attr))
▪ Option 2: define a struct bpf_map_def with an elf section
__attribute__ SEC(“maps”)-also uses syscall!
Option 1 Option 2
THIS IS AN OVERSIMPLIFICATION
©2017 Open-NFP 8
eBPF Bytecode: Quick Overview
eBPF Bytecode: op:8, dst_reg:4, src_reg:4, off:16, imm:32
▪ op code is divided into the sections
▪ Operation code (4bits) e.g BPF_MOV, BPF_JNE
▪ Source bit (1 bit) BPF_X (use src_reg and dst_reg) or BPF_K
(use dst_reg and 32 bit imm)
▪ instruction class (3 bits) e.g BPF_ALU, BPF_ALU64, BPF_JMP
▪ BPF_MOV | BPF_X | BPF_ALU64, 0x6, 0x1, 0x0000, 0x00000000
▪ Move contents of register 1 to register 6
▪ BPF_JNE | BPF_K | BPF_JMP, 0x1, 0x0, 0x0011, 0x00008100
▪ Jump 11 insns forward-can also jump backwards-if contents of
register 1 is not equal to 0x00008100
©2017 Open-NFP 9
BPF Kernel Hooks
Many hooks with different purposes
▪ kprobes
▪ socket filters-tcpdump-old school!
▪ seccomp
▪ netfilter (new)
▪ TC
▪ XDP(no skb-super fast!)
XDP will be our focus for the rest of this talk
©2017 Open-NFP 10
XDP
BPF hook in the driver
▪ Allows for high speed processing before skb is attached to packet
▪ Currently 4 return codes: XDP_ABORT, XDP_DROP, XDP_PASS,
XDP_TX
▪ XDP_REDIRECT in the pipeline
▪ Usecases include DDoS protection and load balancing
▪ Includes maximum of 256 bytes of prepend
▪ Metadata is just pointers to start of packet and end
©2017 Open-NFP 11
Program Example (xdp1_kern.c)
Simple drop example
▪ Note the use of standard header infrastructure
▪ Associated user space program maintaining a set of counters
▪ I am not going to go through line by line-for more detail check out
Andy and Jesper’s awesome tutorial-in links
▪ Will come back to this example later on…
This can be found in the recent (4.8+) kernels at
linux/samples/bpf
©2017 Open-NFP 12
Optimizing XDP
A simple checklist-not comprehensive!
▪ Ensure BPF JIT is enabled
▪ Pin queues to interfaces
▪ Set ringsize to an optimal level for your NIC and application
▪ To gain some idea of your NIC’s driver based XDP performance
check simple XDP_DROP and XDP_TX programs
▪ Many people use single core performance as a reasonable
benchmark
▪ To do this use the ethtool -X command
▪ You will NOT get the simple program performance if you build
something complex (Duh)
©2017 Open-NFP 13
Offloading XDP
Netronome have upstreamed the initial version of the
nfp_bpf_jit
▪ More to come!
©2017 Open-NFP 14
Offload Architecture
user space
kernel space
BPF syscall
● program
● type (sk filter, kprobe, cls, xdp)
● license
● ...
verifier
fd
host JIT
tc
TC
cls_bpf
modification
XDP
ctrl
offload
object
fd, skip_* flags
verification
fd, skip_* flags
driver
RX TXXDP
ndo
setup
tc
HW JIT /
translator
stats
&
maps
BPF
prog
©2017 Open-NFP 15
References
Kernel Docs: https://www.kernel.org/doc/Documentation/networking/filter.txt
Initial XDP Presentation: https://github.com/iovisor/bpf-docs/blob/master/
Express_Data_Path.pdf
More Docs: http://prototype-kernel.readthedocs.io/en/latest/README.html
Andy and Jesper’s Talk: https://netdevconf.org/2.1/slides/apr7/gospodarek-
Netdev2.1-XDP-for-the-Rest-of-Us_Final.pdf
Reading List: https://qmonnet.github.io/whirl-offload/2016/09/01/dive-into-bpf/
Search: google.com :)
©2016 Open-NFP 16
ANY QUESTIONS?
Thanks!

More Related Content

What's hot (20)

PDF
OpenContrail, Real Speed: Offloading vRouter
Open-NFP
 
PDF
Whitebox Switches Deployment Experience
APNIC
 
PDF
Data Plane and VNF Acceleration Mini Summit
Open-NFP
 
PPTX
Compiling P4 to XDP, IOVISOR Summit 2017
Cheng-Chun William Tu
 
PPTX
2016 NCTU P4 Workshop
Yi Tseng
 
PDF
[Webinar Slides] Programming the Network Dataplane in P4
Open Networking Summits
 
PDF
LF_DPDK17_GRO/GSO Libraries: Bring Significant Performance Gains to DPDK-base...
LF_DPDK
 
PDF
LinuxCon 2015 Stateful NAT with OVS
Thomas Graf
 
PPTX
Disaggregation a Primer: Optimizing design for Edge Cloud & Bare Metal applic...
Netronome
 
PDF
Comprehensive XDP Off‌load-handling the Edge Cases
Netronome
 
PDF
The Next Generation Firewall for Red Hat Enterprise Linux 7 RC
Thomas Graf
 
PDF
Cilium - BPF & XDP for containers
Docker, Inc.
 
PDF
Ebpf ovsconf-2016
Cheng-Chun William Tu
 
PDF
Programmable data plane at terabit speeds
Barefoot Networks
 
PDF
Linux Native, HTTP Aware Network Security
Thomas Graf
 
PDF
20170925 onos and p4
Yi Tseng
 
PDF
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Thomas Graf
 
PDF
Linux Kernel Cryptographic API and Use Cases
Kernel TLV
 
PDF
eBPF - Rethinking the Linux Kernel
Thomas Graf
 
PDF
Host Data Plane Acceleration: SmartNIC Deployment Models
Netronome
 
OpenContrail, Real Speed: Offloading vRouter
Open-NFP
 
Whitebox Switches Deployment Experience
APNIC
 
Data Plane and VNF Acceleration Mini Summit
Open-NFP
 
Compiling P4 to XDP, IOVISOR Summit 2017
Cheng-Chun William Tu
 
2016 NCTU P4 Workshop
Yi Tseng
 
[Webinar Slides] Programming the Network Dataplane in P4
Open Networking Summits
 
LF_DPDK17_GRO/GSO Libraries: Bring Significant Performance Gains to DPDK-base...
LF_DPDK
 
LinuxCon 2015 Stateful NAT with OVS
Thomas Graf
 
Disaggregation a Primer: Optimizing design for Edge Cloud & Bare Metal applic...
Netronome
 
Comprehensive XDP Off‌load-handling the Edge Cases
Netronome
 
The Next Generation Firewall for Red Hat Enterprise Linux 7 RC
Thomas Graf
 
Cilium - BPF & XDP for containers
Docker, Inc.
 
Ebpf ovsconf-2016
Cheng-Chun William Tu
 
Programmable data plane at terabit speeds
Barefoot Networks
 
Linux Native, HTTP Aware Network Security
Thomas Graf
 
20170925 onos and p4
Yi Tseng
 
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Thomas Graf
 
Linux Kernel Cryptographic API and Use Cases
Kernel TLV
 
eBPF - Rethinking the Linux Kernel
Thomas Graf
 
Host Data Plane Acceleration: SmartNIC Deployment Models
Netronome
 

Similar to Transparent eBPF Offload: Playing Nice with the Linux Kernel (20)

PDF
eBPF/XDP
Netronome
 
PPTX
eBPF Basics
Michael Kehoe
 
PPTX
Dataplane programming with eBPF: architecture and tools
Stefano Salsano
 
PDF
Meetup 2009
HuaiEnTseng
 
PDF
Introduction to eBPF and XDP
lcplcp1
 
PDF
DEF CON 27 - JEFF DILEO - evil e bpf in depth
Felipe Prado
 
PPTX
Understanding eBPF in a Hurry!
Ray Jenkins
 
PDF
BPF Hardware Offload Deep Dive
Netronome
 
PDF
eBPF — Divulging The Hidden Super Power.pdf
SGBSeo
 
PDF
P4, EPBF, and Linux TC Offload
Open-NFP
 
PDF
ebpf and IO Visor: The What, how, and what next!
Affan Syed
 
PDF
story_of_bpf-1.pdf
hegikip775
 
PDF
BPF - in-kernel virtual machine
Alexei Starovoitov
 
PDF
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
Thomas Graf
 
PDF
Cilium - Network and Application Security with BPF and XDP Thomas Graf, Cova...
Docker, Inc.
 
PPTX
eBPF Workshop
Michael Kehoe
 
PDF
eBPF — Divulging The Hidden Super Power.pdf
seo18
 
PDF
Introduction to eBPF
RogerColl2
 
PDF
eBPF Tooling and Debugging Infrastructure
Netronome
 
PDF
The Open Source Ecosystem for eBPF in Kubernetes
All Things Open
 
eBPF/XDP
Netronome
 
eBPF Basics
Michael Kehoe
 
Dataplane programming with eBPF: architecture and tools
Stefano Salsano
 
Meetup 2009
HuaiEnTseng
 
Introduction to eBPF and XDP
lcplcp1
 
DEF CON 27 - JEFF DILEO - evil e bpf in depth
Felipe Prado
 
Understanding eBPF in a Hurry!
Ray Jenkins
 
BPF Hardware Offload Deep Dive
Netronome
 
eBPF — Divulging The Hidden Super Power.pdf
SGBSeo
 
P4, EPBF, and Linux TC Offload
Open-NFP
 
ebpf and IO Visor: The What, how, and what next!
Affan Syed
 
story_of_bpf-1.pdf
hegikip775
 
BPF - in-kernel virtual machine
Alexei Starovoitov
 
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
Thomas Graf
 
Cilium - Network and Application Security with BPF and XDP Thomas Graf, Cova...
Docker, Inc.
 
eBPF Workshop
Michael Kehoe
 
eBPF — Divulging The Hidden Super Power.pdf
seo18
 
Introduction to eBPF
RogerColl2
 
eBPF Tooling and Debugging Infrastructure
Netronome
 
The Open Source Ecosystem for eBPF in Kubernetes
All Things Open
 
Ad

Recently uploaded (20)

PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Ad

Transparent eBPF Offload: Playing Nice with the Linux Kernel

  • 1. ©2016 Open-NFP 1 BPF and XDP Explained Nic Viljoen
  • 2. ©2017 Open-NFP 2 Objectives of the Webinar Give user a basic understanding of the architecture of eBPF ▪ What is it ▪ The programming model ▪ The kernel hooks Give user a basic understanding of XDP ▪ What is it/Where is it ▪ How to use it (beginner level!) ▪ How to offload it
  • 3. ©2016 Open-NFP 3 What is eBPF? eBPF is a simple way to extend the functionality of the kernel at runtime ▪ Effectively a small kernel based machine ▪ 10 64bit registers ▪ 512 byte stack ▪ Data structures known as maps (unlimited size) ▪ 4K BPF instructions (Bytecode) ▪ Verifier to ensure kernel safe ▪ no loops, not more than 4K insns, not more than 64 maps etc… ▪ Can be JITed to ensure maximum performance
  • 4. ©2016 Open-NFP 4 Used Within Hyperscale-Not a Toy! Those who have publically stated they are using BPF or are planning to use BPF include ▪ Facebook-Load Balancing, Security ▪ Netflix-Network Monitoring ▪ Cilium Project ▪ Cloudflare-Security ▪ OVS-Virtual Switching Due to its upstream safety and kernel support BPF provides a safe, flexible and scalable networking tool
  • 5. ©2016 Open-NFP 5 The Programming Model LLVM is used to compile from supported languages ▪ C ▪ Go ▪ P4 When Programs are loaded ▪ Verifier is called-ensure safety ▪ Program is JITed-ensure perf ▪ Can also be offloaded ▪ nfp_bpf_jit upstream LL VM NFP verifier.c bpf_prog.go bpf_prog.elf bpf syscall USER JIT nfp_bfp_jit.c Host CPU KERNEL HARDWARE bpf_prog.p4 bpf_prog.c
  • 6. ©2016 Open-NFP 6 Maps-What They Are Maps are key value stores ▪ Can be accessed from kernel or user space ▪ Used for interaction between kernel and user space programs Number of different types of maps ▪ Used for interaction between kernel and user space programs bpf_user.c bpf_kern.c Map
  • 7. ©2017 Open-NFP 7 Maps-How to use them Creating Maps ▪ Option 1: create map with syscall ▪ bpf(BPF_MAP_CREATE, &bpf_attr, sizeof(bpf_attr)) ▪ Option 2: define a struct bpf_map_def with an elf section __attribute__ SEC(“maps”)-also uses syscall! Option 1 Option 2 THIS IS AN OVERSIMPLIFICATION
  • 8. ©2017 Open-NFP 8 eBPF Bytecode: Quick Overview eBPF Bytecode: op:8, dst_reg:4, src_reg:4, off:16, imm:32 ▪ op code is divided into the sections ▪ Operation code (4bits) e.g BPF_MOV, BPF_JNE ▪ Source bit (1 bit) BPF_X (use src_reg and dst_reg) or BPF_K (use dst_reg and 32 bit imm) ▪ instruction class (3 bits) e.g BPF_ALU, BPF_ALU64, BPF_JMP ▪ BPF_MOV | BPF_X | BPF_ALU64, 0x6, 0x1, 0x0000, 0x00000000 ▪ Move contents of register 1 to register 6 ▪ BPF_JNE | BPF_K | BPF_JMP, 0x1, 0x0, 0x0011, 0x00008100 ▪ Jump 11 insns forward-can also jump backwards-if contents of register 1 is not equal to 0x00008100
  • 9. ©2017 Open-NFP 9 BPF Kernel Hooks Many hooks with different purposes ▪ kprobes ▪ socket filters-tcpdump-old school! ▪ seccomp ▪ netfilter (new) ▪ TC ▪ XDP(no skb-super fast!) XDP will be our focus for the rest of this talk
  • 10. ©2017 Open-NFP 10 XDP BPF hook in the driver ▪ Allows for high speed processing before skb is attached to packet ▪ Currently 4 return codes: XDP_ABORT, XDP_DROP, XDP_PASS, XDP_TX ▪ XDP_REDIRECT in the pipeline ▪ Usecases include DDoS protection and load balancing ▪ Includes maximum of 256 bytes of prepend ▪ Metadata is just pointers to start of packet and end
  • 11. ©2017 Open-NFP 11 Program Example (xdp1_kern.c) Simple drop example ▪ Note the use of standard header infrastructure ▪ Associated user space program maintaining a set of counters ▪ I am not going to go through line by line-for more detail check out Andy and Jesper’s awesome tutorial-in links ▪ Will come back to this example later on… This can be found in the recent (4.8+) kernels at linux/samples/bpf
  • 12. ©2017 Open-NFP 12 Optimizing XDP A simple checklist-not comprehensive! ▪ Ensure BPF JIT is enabled ▪ Pin queues to interfaces ▪ Set ringsize to an optimal level for your NIC and application ▪ To gain some idea of your NIC’s driver based XDP performance check simple XDP_DROP and XDP_TX programs ▪ Many people use single core performance as a reasonable benchmark ▪ To do this use the ethtool -X command ▪ You will NOT get the simple program performance if you build something complex (Duh)
  • 13. ©2017 Open-NFP 13 Offloading XDP Netronome have upstreamed the initial version of the nfp_bpf_jit ▪ More to come!
  • 14. ©2017 Open-NFP 14 Offload Architecture user space kernel space BPF syscall ● program ● type (sk filter, kprobe, cls, xdp) ● license ● ... verifier fd host JIT tc TC cls_bpf modification XDP ctrl offload object fd, skip_* flags verification fd, skip_* flags driver RX TXXDP ndo setup tc HW JIT / translator stats & maps BPF prog
  • 15. ©2017 Open-NFP 15 References Kernel Docs: https://www.kernel.org/doc/Documentation/networking/filter.txt Initial XDP Presentation: https://github.com/iovisor/bpf-docs/blob/master/ Express_Data_Path.pdf More Docs: http://prototype-kernel.readthedocs.io/en/latest/README.html Andy and Jesper’s Talk: https://netdevconf.org/2.1/slides/apr7/gospodarek- Netdev2.1-XDP-for-the-Rest-of-Us_Final.pdf Reading List: https://qmonnet.github.io/whirl-offload/2016/09/01/dive-into-bpf/ Search: google.com :)
  • 16. ©2016 Open-NFP 16 ANY QUESTIONS? Thanks!