From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>, KP Singh <kpsingh@kernel.org>
Cc: "Toke Høiland-Jørgensen" <toke@redhat.com>,
netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: [PATCH bpf-next v3 0/8] Add support for transmitting packets using XDP in bpf_prog_run()
Date: Sat, 11 Dec 2021 19:41:34 +0100 [thread overview]
Message-ID: <20211211184143.142003-1-toke@redhat.com> (raw)
This series adds support for transmitting packets using XDP in
bpf_prog_run(), by enabling the xdp_do_redirect() callback so XDP programs
can perform "real" redirects to devices or maps, using an opt-in flag when
executing the program.
The primary use case for this is testing the redirect map types and the
ndo_xdp_xmit driver operation without generating external traffic. But it
turns out to also be useful for creating a programmable traffic generator.
The last patch adds a sample traffic generator to bpf/samples, which
can transmit up to 11.5 Mpps/core on my test machine.
To transmit the frames, the new mode instantiates a page_pool structure in
bpf_prog_run() and initialises the pages with the data passed in by
userspace. These pages can then be redirected using the normal redirection
mechanism, and the existing page_pool code takes care of returning and
recycling them. The setup is optimised for high performance with a high
number of repetitions to support stress testing and the traffic generator
use case; see patch 6 for details.
The series is structured as follows: Patches 1-2 adds a few features to
page_pool that are needed for the usage in bpf_prog_run(). Similarly,
patches 3-5 performs a couple of preparatory refactorings of the XDP
redirect and memory management code. Patch 6 adds the support to
bpf_prog_run() itself, patch 7 adds a selftest, and patch 8 adds the
traffic generator example to samples/bpf.
v3:
- Reorder patches to make sure they all build individually (Patchwork)
- Remove a couple of unused variables (Patchwork)
- Remove unlikely() annotation in slow path and add back John's ACK that I
accidentally dropped for v2 (John)
v2:
- Split up up __xdp_do_redirect to avoid passing two pointers to it (John)
- Always reset context pointers before each test run (John)
- Use get_mac_addr() from xdp_sample_user.h instead of rolling our own (Kumar)
- Fix wrong offset for metadata pointer
Toke Høiland-Jørgensen (8):
xdp: Allow registering memory model without rxq reference
page_pool: Add callback to init pages when they are allocated
page_pool: Store the XDP mem id
xdp: Move conversion to xdp_frame out of map functions
xdp: add xdp_do_redirect_frame() for pre-computed xdp_frames
bpf: Add XDP_REDIRECT support to XDP for bpf_prog_run()
selftests/bpf: Add selftest for XDP_REDIRECT in bpf_prog_run()
samples/bpf: Add xdp_trafficgen sample
include/linux/bpf.h | 20 +-
include/linux/filter.h | 4 +
include/net/page_pool.h | 11 +-
include/net/xdp.h | 3 +
include/uapi/linux/bpf.h | 2 +
kernel/bpf/Kconfig | 1 +
kernel/bpf/cpumap.c | 8 +-
kernel/bpf/devmap.c | 32 +-
net/bpf/test_run.c | 217 ++++++++-
net/core/filter.c | 73 ++-
net/core/page_pool.c | 6 +-
net/core/xdp.c | 94 ++--
samples/bpf/.gitignore | 1 +
samples/bpf/Makefile | 4 +
samples/bpf/xdp_redirect.bpf.c | 34 ++
samples/bpf/xdp_trafficgen_user.c | 421 ++++++++++++++++++
tools/include/uapi/linux/bpf.h | 2 +
.../bpf/prog_tests/xdp_do_redirect.c | 74 +++
.../bpf/progs/test_xdp_do_redirect.c | 34 ++
19 files changed, 947 insertions(+), 94 deletions(-)
create mode 100644 samples/bpf/xdp_trafficgen_user.c
create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c
create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_do_redirect.c
--
2.34.0
next reply other threads:[~2021-12-11 18:43 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-11 18:41 Toke Høiland-Jørgensen [this message]
2021-12-11 18:41 ` [PATCH bpf-next v3 1/8] xdp: Allow registering memory model without rxq reference Toke Høiland-Jørgensen
2021-12-11 18:41 ` [PATCH bpf-next v3 2/8] page_pool: Add callback to init pages when they are allocated Toke Høiland-Jørgensen
2021-12-11 18:41 ` [PATCH bpf-next v3 3/8] page_pool: Store the XDP mem id Toke Høiland-Jørgensen
2021-12-11 18:41 ` [PATCH bpf-next v3 4/8] xdp: Move conversion to xdp_frame out of map functions Toke Høiland-Jørgensen
2021-12-11 18:41 ` [PATCH bpf-next v3 5/8] xdp: add xdp_do_redirect_frame() for pre-computed xdp_frames Toke Høiland-Jørgensen
2021-12-11 18:41 ` [PATCH bpf-next v3 6/8] bpf: Add XDP_REDIRECT support to XDP for bpf_prog_run() Toke Høiland-Jørgensen
2021-12-12 2:43 ` Alexei Starovoitov
2021-12-13 16:26 ` Toke Høiland-Jørgensen
2021-12-14 0:02 ` Alexei Starovoitov
2021-12-14 0:36 ` Toke Høiland-Jørgensen
2021-12-14 3:45 ` Alexei Starovoitov
2021-12-14 11:46 ` Toke Høiland-Jørgensen
2021-12-11 18:41 ` [PATCH bpf-next v3 7/8] selftests/bpf: Add selftest for XDP_REDIRECT in bpf_prog_run() Toke Høiland-Jørgensen
2021-12-11 18:41 ` [PATCH bpf-next v3 8/8] samples/bpf: Add xdp_trafficgen sample Toke Høiland-Jørgensen
2021-12-12 2:47 ` Alexei Starovoitov
2021-12-13 16:28 ` Toke Høiland-Jørgensen
2021-12-14 0:05 ` Alexei Starovoitov
2021-12-14 0:37 ` Toke Høiland-Jørgensen
2021-12-14 3:28 ` Alexei Starovoitov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211211184143.142003-1-toke@redhat.com \
--to=toke@redhat.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).