RFC Add support for XDP in egress path
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v5 RFC Latest12 patches 14 repliesIn review
- v4 RFC11 patches 26 repliesSuperseded
- v112 patches 45 repliesSuperseded
Changes in v5 from the cover letter
- updated cover letter
- moved running of ebpf program from ndo_{start,xdp}_xmit to core code. Accordingly, dropped all tun and vhost related changes.
- added egress support to bpftool
Patches in v5 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/12 | net: Add XDP setup and query commands for Tx programsinclude/ net/ net/ | +27 | 0 replies | |
| 2/12 | net: Add BPF_XDP_EGRESS as a bpf_attach_typeinclude/ net/ net/ +1 more | +16 | 3 replies | |
| 3/12 | xdp: Add xdp_txq_info to xdp_buffinclude/ include/ net/ +1 more | +24 | 0 replies | |
| 4/12 | net: Add IFLA_XDP_EGRESS for XDP programs in the egress pathinclude/ include/ net/ +1 more | +99 | 0 replies | |
| 5/12 | net: core: rename netif_receive_generic_xdp to do_generic_xdp_corenet/ | +25 | 1 reply | |
| 6/12 | net: core: Rename do_xdp_generic to do_xdp_generic_rxdrivers/ include/ net/ | +7 | 0 replies | |
| 7/12 | dev: set egress XDP programinclude/ net/ | +32 | 0 replies | |
| 8/12 | dev: Support xdp in the Tx path for packets as an skbinclude/ net/ | +62 | 0 replies | |
| 9/12 | dev: Support xdp in the Tx path for xdp_framesinclude/ kernel/ net/ | +87 | 6 replies | |
| 10/12 | libbpf: Add egress XDP supporttools/ tools/ tools/ +1 more | +67 | 0 replies | |
| 11/12 | bpftool: Add support for XDP egresstools/ tools/ tools/ | +55 | 0 replies | |
| 12/12 | samples/bpf: add XDP egress support to xdp1samples/ | +31 | 1 reply |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.
Cover letter [PATCH RFC-v5 bpf-next 00/12] Add support for XDP in egress path
From: David Ahern <[email protected]>
This series adds support for XDP in the egress path by introducing a new XDP attachment type, BPF_XDP_EGRESS, and adding a UAPI to if_link.h for attaching the program to a netdevice and reporting the program. bpf programs can be run on all packets in the Tx path - skbs or redirected xdp frames. The intent is to emulate the current RX path for XDP as much as possible to maintain consistency and symmetry in the 2 paths with their APIs.
This is a missing primitive for XDP allowing solutions to build small, targeted programs properly distributed in the networking path allowing, for example, an egress firewall/ACL/traffic verification or packet manipulation and encapping an entire ethernet frame whether it is locally generated traffic, forwarded via the slow path (ie., full stack processing) or xdp redirected frames.
Nothing about running a program in the Tx path requires driver specific resources like the Rx path has. Thus, programs can be run in core code and attached to the net_device struct similar to skb mode. The existing XDP_FLAGS_*_MODE are not relevant at the moment, so none can be set in the attach. XDP_FLAGS_HW_MODE can be used in the future (e.g., the work on offloading programs from a VM).
The locations chosen to run the egress program - __netdev_start_xmit before the call to ndo_start_xmit and bq_xmit_all before invoking ndo_xdp_xmit - allow follow on patch sets to handle tx queueing and setting the queue index if multi-queue with consistency in handling both packet formats.
A few of the patches trace back to work done on offloading programs from a VM by Jason Wang and Prashant Bole.
Automated tests will be added to tools/testing/selftests/bpf in the next revision.
v5:
- updated cover letter
- moved running of ebpf program from ndo_{start,xdp}_xmit to core code. Accordingly, dropped all tun and vhost related changes.
- added egress support to bpftool
v4:
- updated cover letter
- patches related to code movement between tuntap, headers and vhost are dropped; previous RFC ran the XDP program in vhost context vs this set which runs them before queueing to vhost. As a part of this moved invocation of egress program to tun_net_xmit and tun_xdp_xmit.
- renamed do_xdp_generic to do_xdp_generic_rx to emphasize is called in the Rx path; added rx argument to do_xdp_generic_core since it is used for both directions and needs to know which queue values to set in xdp_buff
v3:
- reworked the patches - splitting patch 1 from RFC v2 into 3, combining patch 2 from RFC v2 into the first 3, combining patches 6 and 7 from RFC v2 into 1 since both did a trivial rename and export. Reordered the patches such that kernel changes are first followed by libbpf and an enhancement to a sample.
- moved small xdp related helper functions from tun.c to tun.h to make tun_ptr_free usable from the tap code. This is needed to handle the case of tap builtin and tun built as a module.
- pkt_ptrs added to struct tun_file and passed to tun_consume_packets rather than declaring pkts as an array on the stack.
v2:
- New XDP attachment type: Jesper, Toke and Alexei discussed whether to introduce a new program type. Since this set adds a way to attach regular XDP program to the tx path, as per Alexei's suggestion, a new attachment type BPF_XDP_EGRESS is introduced.
- libbpf API changes:
Alexei had suggested _opts() style of API extension. Considering it two new libbpf APIs are introduced which are equivalent to existing APIs. New ones can be extended easily. Please see individual patches for details. xdp1 sample program is modified to use new APIs.
- tun: Some patches from previous set are removed as they are irrelevant in this series. They will in introduced later.
[1]: https://netdevconf.info/0x13/session.html?xdp-offload-with-virtio-net
David Ahern (12):
net: Add XDP setup and query commands for Tx programs
net: Add BPF_XDP_EGRESS as a bpf_attach_type
xdp: Add xdp_txq_info to xdp_buff
net: Add IFLA_XDP_EGRESS for XDP programs in the egress path
net: core: rename netif_receive_generic_xdp to do_generic_xdp_core
net: core: Rename do_xdp_generic to do_xdp_generic_rx
dev: set egress XDP program
dev: Support xdp in the Tx path for packets as an skb
dev: Support xdp in the Tx path for xdp_frames
libbpf: Add egress XDP support
bpftool: Add support for XDP egress
samples/bpf: add XDP egress support to xdp1
drivers/net/tun.c | 4 +- include/linux/netdevice.h | 23 ++- include/net/xdp.h | 5 + include/uapi/linux/bpf.h | 3 + include/uapi/linux/if_link.h | 3 + kernel/bpf/devmap.c | 19 ++- net/core/dev.c | 258 +++++++++++++++++++++++------ net/core/filter.c | 23 +++ net/core/rtnetlink.c | 96 ++++++++++- samples/bpf/xdp1_user.c | 38 ++++- tools/bpf/bpftool/main.h | 2 +- tools/bpf/bpftool/net.c | 49 +++++- tools/bpf/bpftool/netlink_dumper.c | 12 +- tools/include/uapi/linux/bpf.h | 3 + tools/include/uapi/linux/if_link.h | 3 + tools/lib/bpf/libbpf.c | 2 + tools/lib/bpf/libbpf.h | 9 +- tools/lib/bpf/libbpf.map | 2 + tools/lib/bpf/netlink.c | 63 ++++++- 19 files changed, 528 insertions(+), 89 deletions(-)
Signature · 1 line
2.21.1 (Apple Git-122.3)