History

bpf: introduce BPF_PROG_TEST_RUN command

development and testing of networking bpf programs is quite cumbersome. Despite availability of user space bpf interpreters the kernel is the ultimate authority and execution environment. Current test frameworks for TC include creation of netns, veth, qdiscs and use of various packet generators just to test functionality of a bpf program. XDP testing is even more complicated, since qemu needs to be started with gro/gso disabled and precise queue configuration, transferring of xdp program from host into guest, attaching to virtio/eth0 and generating traffic from the host while capturing the results from the guest. Moreover analyzing performance bottlenecks in XDP program is impossible in virtio environment, since cost of running the program is tiny comparing to the overhead of virtio packet processing, so performance testing can only be done on physical nic with another server generating traffic. Furthermore ongoing changes to user space control plane of production applications cannot be run on the test servers leaving bpf programs stubbed out for testing. Last but not least, the upstream llvm changes are validated by the bpf backend testsuite which has no ability to test the code generated. To improve this situation introduce BPF_PROG_TEST_RUN command to test and performance benchmark bpf programs. Joint work with Daniel Borkmann.

Alexei Starovoitov committed 9 years ago

Commit 1cf1cae1 parent 98cd1557 files · +223 −3Browse files

Showing the changes to include/uapi/linux (1 of 7 files). Show all

Unified · Split

include/uapi/linux/bpf.h+12−0
@@ -81,6 +81,7 @@ enum bpf_cmd { · 80 unmodified lines
81 BPF_OBJ_GET,81 BPF_OBJ_GET,
82 BPF_PROG_ATTACH,82 BPF_PROG_ATTACH,
83 BPF_PROG_DETACH,83 BPF_PROG_DETACH,
84 BPF_PROG_TEST_RUN,
84};85};
85 86
86enum bpf_map_type {87enum bpf_map_type {
@@ -189,6 +190,17 @@ union bpf_attr { · 102 unmodified lines
189 __u32 attach_type;190 __u32 attach_type;
190 __u32 attach_flags;191 __u32 attach_flags;
191 };192 };
193
194 struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
195 __u32 prog_fd;
196 __u32 retval;
197 __u32 data_size_in;
198 __u32 data_size_out;
199 __aligned_u64 data_in;
200 __aligned_u64 data_out;
201 __u32 repeat;
202 __u32 duration;
203 } test;
192} __attribute__((aligned(8)));204} __attribute__((aligned(8)));
193 205
194/* BPF helper function descriptions:206/* BPF helper function descriptions: