Skip to content

Implement XDP bpf_redirect

John Fastabend netdev 1 version In review

Get series with b4
b4 am 20170717160759.24315.7464.stgit@john-Precision-Tower-5810

Versions newest first

  1. v1 Latest12 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/12ixgbe: NULL xdp_tx rings on resource cleanupdrivers/net/ethernet/intel/ixgbe/ixgbe_lib.c+6 -20 replies
2/12net: xdp: support xdp generic on virtual devicesnet/core/dev.c+113 -950 replies
3/12xdp: add bpf_redirect helper functioninclude/linux/filter.h include/linux/netdevice.h include/uapi/linux/bpf.h +1 more+63 -00 replies
4/12xdp: sample program for new bpf_redirect helpersamples/bpf/Makefile samples/bpf/xdp_redirect_kern.c samples/bpf/xdp_redirect_user.c+187 -00 replies
5/12net: implement XDP_REDIRECT for xdp genericinclude/linux/filter.h net/core/dev.c net/core/filter.c+47 -20 replies
6/12ixgbe: add initial support for xdp redirectdrivers/net/ethernet/intel/ixgbe/ixgbe_main.c+40 -10 replies
7/12xdp: add trace event for xdp redirectdrivers/net/ethernet/intel/ixgbe/ixgbe_main.c include/linux/filter.h include/trace/events/xdp.h +1 more+43 -70 replies
8/12bpf: add devmap, a map for storing net device referencesinclude/linux/bpf_types.h include/uapi/linux/bpf.h kernel/bpf/Makefile +3 more+294 -00 replies
9/12bpf: add bpf_redirect_map helper routineinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/devmap.c +2 more+78 -12 replies
10/12xdp: Add batching support to redirect mapdrivers/net/ethernet/intel/ixgbe/ixgbe_main.c include/linux/bpf.h include/linux/filter.h +3 more+166 -150 replies
11/12net: add notifier hooks for devmap bpf mapinclude/linux/filter.h kernel/bpf/devmap.c kernel/bpf/verifier.c+75 -23 replies
12/12xdp: bpf redirect with map sample programsamples/bpf/Makefile samples/bpf/xdp_redirect_map_kern.c samples/bpf/xdp_redirect_map_user.c +1 more+194 -00 replies

Reviews trailers per patch

All 12 patches have a Reviewed-by or Acked-by.

PatchDaniel BorkmannJesper Dangaard BrouerAndy Gospodarek
1/12A-b A-b
2/12A-b A-b T-b
3/12A-b A-b
4/12A-b A-b T-b
5/12A-b A-b T-b
6/12A-b A-b
7/12A-b A-b
8/12A-b A-b
9/12A-b
10/12A-b
11/12A-b A-b
12/12A-b A-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v1 thread

Cover letter [net-next PATCH 00/12] Implement XDP bpf_redirect

This series adds two new XDP helper routines bpf_redirect() and bpf_redirect_map(). The first variant bpf_redirect() is meant to be used the same way it is currently being used by the cls_bpf classifier. An xdp packet will be redirected immediately when this is called.

The other variant bpf_redirect_map(map, key, flags) uses a new map type called devmap. A devmap uses integers as keys and net_devices as values. The user provies key/ifindex pairs to update the map with new net_devices. This provides two benefits over the normal variant 'bpf_redirect()'. First the datapath bpf program is abstracted away from using hard-coded ifindex values. Allowing a single bpf program to be run any many different environments. Second, and perhaps more important, the map enables batching packet transmits. The map plus small driver changes allows for batching all send requests across a NAPI poll loop. This allows driver writers to optimize the driver xmit path and only call expensive operations once for a batch of xdp_buffs.

The devmap was designed to support possible future work for multicast and broadcast as follow-up patches.

To see, in more detail, how to leverage the new helpers and map from the userspace side please review these two patches,

xdp: sample program for new bpf_redirect helper
xdp: bpf redirect with map sample program

Performance numbers provided by Jesper are the following, tested using the ixgbe driver with CPU E5-1650 v4 @ 3.60GHz:

13,939,674 pkt/s = XDP_DROP without touching memory 14,290,650 pkt/s = xdp1: XDP_DROP with reading packet data
13,221,812 pkt/s = xdp2: XDP_TX with swap mac (writes into pkt)
7,596,576 pkt/s = xdp_redirect: XDP_REDIRECT with swap mac (like XDP_TX)
13,058,435 pkt/s = xdp_redirect_map:XDP_REDIRECT with swap mac + devmap

A big thanks to everyone who helped with this series. Jesper provided fixes, debugging, code review, performance benchmarks! Daniel provided lots of useful feedback and code review. And last but not least Andy provided useful feedback related to supporting additional drivers, generic xdp implementation, testing, etc. Any other feedback is welcome but I believe at this point these are ready to be merged!

Whats left... get the rest of the drivers developers to implement this in all the drivers.

---

John Fastabend (12):
ixgbe: NULL xdp_tx rings on resource cleanup
net: xdp: support xdp generic on virtual devices
xdp: add bpf_redirect helper function
xdp: sample program for new bpf_redirect helper
net: implement XDP_REDIRECT for xdp generic
ixgbe: add initial support for xdp redirect
xdp: add trace event for xdp redirect
bpf: add devmap, a map for storing net device references
bpf: add bpf_redirect_map helper routine
xdp: Add batching support to redirect map
net: add notifier hooks for devmap bpf map
xdp: bpf redirect with map sample program

 drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c  |    8 
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |   63 ++++
 include/linux/bpf.h                           |    5 
 include/linux/bpf_types.h                     |    3 
 include/linux/filter.h                        |   14 +
 include/linux/netdevice.h                     |   11 +
 include/trace/events/xdp.h                    |   31 ++
 include/uapi/linux/bpf.h                      |   10 +
 kernel/bpf/Makefile                           |    3 
 kernel/bpf/devmap.c                           |  431 +++++++++++++++++++++++++
 kernel/bpf/verifier.c                         |   12 +
 net/core/dev.c                                |  226 ++++++++-----
 net/core/filter.c                             |  170 ++++++++++
 samples/bpf/Makefile                          |    8 
 samples/bpf/xdp_redirect_kern.c               |   81 +++++
 samples/bpf/xdp_redirect_map_kern.c           |   83 +++++
 samples/bpf/xdp_redirect_map_user.c           |  105 ++++++
 samples/bpf/xdp_redirect_user.c               |  102 ++++++
 tools/testing/selftests/bpf/bpf_helpers.h     |    2 
 tools/testing/selftests/bpf/test_maps.c       |   15 +
 20 files changed, 1282 insertions(+), 101 deletions(-)
 create mode 100644 kernel/bpf/devmap.c
 create mode 100644 samples/bpf/xdp_redirect_kern.c
 create mode 100644 samples/bpf/xdp_redirect_map_kern.c
 create mode 100644 samples/bpf/xdp_redirect_map_user.c
 create mode 100644 samples/bpf/xdp_redirect_user.c