New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for transmitting packets using XDP in bpf_prog_run() #2224
Conversation
Master branch: eee9a6d |
Master branch: 8b4ff5f |
e4a3b49
to
dfb1d44
Compare
Master branch: 080a70b |
dfb1d44
to
225ecf3
Compare
Master branch: 0bf4054 |
225ecf3
to
22522b1
Compare
Master branch: 78c1f8d |
22522b1
to
cd4d511
Compare
Master branch: da54ab1 |
cd4d511
to
26ca47d
Compare
Master branch: 866de40 |
26ca47d
to
707955f
Compare
Master branch: 942df4d |
707955f
to
33c3303
Compare
Master branch: db52f57 |
33c3303
to
ae1d288
Compare
Master branch: 222c98c |
ae1d288
to
7d7b5f9
Compare
Master branch: d5284de |
7d7b5f9
to
297f9c8
Compare
Master branch: 29f2e5b |
297f9c8
to
14bd636
Compare
Master branch: fda684f |
14bd636
to
174a950
Compare
Master branch: 8d0f9e7 |
174a950
to
6b3fc94
Compare
Master branch: 666af70 |
b99847b
to
fc9567b
Compare
Master branch: 733719e |
fc9567b
to
9c3c8f8
Compare
733719e
to
229fae3
Compare
Master branch: 229fae3 |
9c3c8f8
to
a1156ae
Compare
Master branch: 229fae3 |
a1156ae
to
529cabc
Compare
Master branch: 229fae3 |
529cabc
to
9524c31
Compare
Master branch: e94fac3 |
9524c31
to
6fe3396
Compare
The functions that register an XDP memory model take a struct xdp_rxq as parameter, but the RXQ is not actually used for anything other than pulling out the struct xdp_mem_info that it embeds. So refactor the register functions and export variants that just take a pointer to the xdp_mem_info. This is in preparation for enabling XDP_REDIRECT in bpf_prog_run(), using a page_pool instance that is not connected to any network device. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Add a new callback function to page_pool that, if set, will be called every time a new page is allocated. This will be used from bpf_test_run() to initialise the page data with the data provided by userspace when running XDP programs with redirect turned on. Acked-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Store the XDP mem ID inside the page_pool struct so it can be retrieved later for use in bpf_prog_run(). Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
All map redirect functions except XSK maps convert xdp_buff to xdp_frame before enqueueing it. So move this conversion of out the map functions and into xdp_do_redirect(). This removes a bit of duplicated code, but more importantly it makes it possible to support caller-allocated xdp_frame structures, which will be added in a subsequent commit. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Master branch: f742fc6 |
Add an xdp_do_redirect_frame() variant which supports pre-computed xdp_frame structures. This will be used in bpf_prog_run() to avoid having to write to the xdp_frame structure when the XDP program doesn't modify the frame boundaries. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
This adds support for doing real redirects when an XDP program returns XDP_REDIRECT in bpf_prog_run(). To achieve this, we create a page pool instance while setting up the test run, and feed pages from that into the XDP program. The setup cost of this is amortised over the number of repetitions specified by userspace. To support performance testing use case, we further optimise the setup step so that all pages in the pool are pre-initialised with the packet data, and pre-computed context and xdp_frame objects stored at the start of each page. This makes it possible to entirely avoid touching the page content on each XDP program invocation, and enables sending up to 11.5 Mpps/core on my test box. Because the data pages are recycled by the page pool, and the test runner doesn't re-initialise them for each run, subsequent invocations of the XDP program will see the packet data in the state it was after the last time it ran on that particular page. This means that an XDP program that modifies the packet before redirecting it has to be careful about which assumptions it makes about the packet content, but that is only an issue for the most naively written programs. Previous uses of bpf_prog_run() for XDP returned the modified packet data and return code to userspace, which is a different semantic then this new redirect mode. For this reason, the caller has to set the new BPF_F_TEST_XDP_DO_REDIRECT flag when calling bpf_prog_run() to opt in to the different semantics. Enabling this flag is only allowed if not setting ctx_out and data_out in the test specification, since it means frames will be redirected somewhere else, so they can't be returned. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
This adds a selftest for the XDP_REDIRECT facility in bpf_prog_run, that redirects packets into a veth and counts them using an XDP program on the other side of the veth pair. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
This adds an XDP-based traffic generator sample which uses the DO_REDIRECT flag of bpf_prog_run(). It works by building the initial packet in userspace and passing it to the kernel where an XDP program redirects the packet to the target interface. The traffic generator supports two modes of operation: one that just sends copies of the same packet as fast as it can without touching the packet data at all, and one that rewrites the destination port number of each packet, making the generated traffic span a range of port numbers. The dynamic mode is included to demonstrate how the bpf_prog_run() facility enables building a completely programmable packet generator using XDP. Using the dynamic mode has about a 10% overhead compared to the static mode, because the latter completely avoids touching the page data. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
6fe3396
to
f04ec5b
Compare
Master branch: f742fc6 |
Master branch: d27a662 |
Pull request for series with
subject: Add support for transmitting packets using XDP in bpf_prog_run()
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861