Skip to content
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

Closed
wants to merge 9 commits into from

Conversation

kernel-patches-bot
Copy link

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

@kernel-patches-bot
Copy link
Author

Master branch: eee9a6d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 8b4ff5f
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 080a70b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 0bf4054
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 78c1f8d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: da54ab1
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 866de40
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 942df4d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: db52f57
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 222c98c
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: d5284de
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 29f2e5b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: fda684f
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 8d0f9e7
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=588861
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 666af70
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=593713
version: 2

@kernel-patches-bot
Copy link
Author

Master branch: 733719e
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=593713
version: 2

@kernel-patches-bot
Copy link
Author

Master branch: 229fae3
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=593713
version: 2

@kernel-patches-bot
Copy link
Author

Master branch: 229fae3
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=594173
version: 3

@kernel-patches-bot
Copy link
Author

Master branch: 229fae3
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=594173
version: 3

@kernel-patches-bot
Copy link
Author

Master branch: e94fac3
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=594173
version: 3

Nobody and others added 5 commits December 13, 2021 14:31
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>
@kernel-patches-bot
Copy link
Author

Master branch: f742fc6
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=594173
version: 3

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>
@thefallentree thefallentree deleted the series/588861=>bpf-next branch December 13, 2021 22:45
@kernel-patches-bot
Copy link
Author

Master branch: f742fc6
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=594173
version: 3

@kernel-patches-bot
Copy link
Author

Master branch: d27a662
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=594173
version: 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants