[dpdk-dev] [PATCH v5 0/8] add framework to load and execute BPF code

Ferruh Yigit ferruh.yigit at intel.com
Wed May 9 19:11:55 CEST 2018


On 5/4/2018 1:45 PM, Konstantin Ananyev wrote:
> BPF is used quite intensively inside Linux (and BSD) kernels
> for various different purposes and proved to be extremely useful.
> 
> BPF inside DPDK might also be used in a lot of places
> for a lot of similar things.
>  As an example to:
> - packet filtering/tracing (aka tcpdump)
> - packet classification
> - statistics collection
> - HW/PMD live-system debugging/prototyping - trace HW descriptors,
>   internal PMD SW state, etc.
> - Comeup with your own idea
> 
> All of that in a dynamic, user-defined and extensible manner.
> 
> So these series introduce new library - librte_bpf.
> librte_bpf provides API to load and execute BPF bytecode within
> user-space dpdk app.
> It supports basic set of features from eBPF spec.
> Also it introduces basic framework to load/unload BPF-based filters
> on eth devices (right now via SW RX/TX callbacks).
> 
> How to try it:
> ===============
> 
> 1) run testpmd as usual and start your favorite forwarding case.
> 2) build bpf program you'd like to load
> (you'll need clang v3.7 or above):
> $ cd test/bpf
> $ clang -O2 -target bpf -c t1.c
> 
> 3) load bpf program(s):
> testpmd> bpf-load rx|tx <portid> <queueid> <load-flags> <bpf-prog-filename>
> 
> <load-flags>:  [-][J][M]
> J - use JIT generated native code, otherwise BPF interpreter will be used.
> M - assume input parameter is a pointer to rte_mbuf,
>     otherwise assume it is a pointer to first segment's data.
> 
> Few examples:
> 
> # to load (not JITed) dummy.o at TX queue 0, port 0:
> testpmd> bpf-load tx 0 0 - ./dpdk.org/test/bpf/dummy.o
> #to load (and JIT compile) t1.o at RX queue 0, port 1:
> testpmd> bpf-load rx 1 0 J ./dpdk.org/test/bpf/t1.o
> 
> #to load and JIT t3.o (note that it expects mbuf as an input):
> testpmd> bpf-load rx 2 0 JM ./dpdk.org/test/bpf/t3.o
> 
> 4) observe changed traffic behavior
> Let say with the examples above:
>  - dummy.o  does literally nothing, so no changes should be here,
>    except some possible slowdown.
>  - t1.o - should force to drop all packets that doesn't match:
>    'dst 1.2.3.4 && udp && dst port 5000' filter.
>  - t3.o - should dump to stdout ARP packets.
> 
> 5) unload some or all bpf programs:
> testpmd> bpf-unload tx 0 0
> 
> 6) continue with step 3) or exit
> 
> Not currently supported features:
> =================================
> - cBPF
> - tail-pointer call
> - eBPF MAP
> - JIT for non X86_64 targets
> - skb
> - function calls for 32-bit apps
> - mbuf pointer as input parameter for 32-bit apps
> 
> v2:
>  - add meson build
>  - add freebsd build
>  - use new logging API
>  - using rte_malloc() for cbi allocation
>  - add extra logic into bpf_validate()
> 
> v3:
>  - add new test-case for it
>  - update docs
>  - update MAINTAINERS
> 
> v4:
>  - add more tests to cover BPF ISA
>  - fix few issues
> 
> v5:
>  - revert changes in tap_bpf.h
>  - rename eBPF related defines
>  - apply Thomas and Marco and Marco comments
> 
> Konstantin Ananyev (8):
>   bpf: add BPF loading and execution framework
>   bpf: add more logic into bpf_validate()
>   bpf: add JIT compilation for x86_64 ISA
>   bpf: introduce basic RX/TX BPF filters
>   testpmd: new commands to load/unload BPF filters
>   test: add few eBPF samples
>   test: introduce functional test for librte_bpf
>   doc: add bpf library related info

Not able to verify build for other architectures but x86 looks fine.

Some minor comments sent to the individual patches.

Taking into account that this is new library not effecting other pieces and
added as experimental with document and unit test provided:

For series,
Acked-by: Ferruh Yigit <ferruh.yigit at intel.com>


More information about the dev mailing list