All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v3 0/3] xdp: Use a default map for xdp_redirect helper
@ 2019-03-01 14:12 Toke Høiland-Jørgensen
  2019-03-01 14:12 ` [PATCH net-next v3 3/3] xdp: Add devmap_idx map type for looking up devices by ifindex Toke Høiland-Jørgensen
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Toke Høiland-Jørgensen @ 2019-03-01 14:12 UTC (permalink / raw)
  To: David Miller
  Cc: netdev, Jesper Dangaard Brouer, Daniel Borkmann,
	Alexei Starovoitov, Jakub Kicinski

This series changes the xdp_redirect helper to use a hidden default map. The
redirect_map() helper also uses the map structure to batch packets, which
results in a significant (around 50%) performance boost for the _map variant.
However, the xdp_redirect() API is simpler if one just wants to redirect to
another interface, which means people tend to use this interface and then wonder
why they getter worse performance than expected.

This series seeks to close this performance difference between the two APIs. It
achieves this by changing xdp_redirect() to use a hidden devmap for looking up
destination interfaces, thus gaining the batching benefit with no visible
difference from the user API point of view.

Allocation of the default map is done dynamically as programs using the
xdp_redirect helper are loaded and attached to interfaces, and the maps are
freed again when no longer needed. Because of tail calls, this requires two
levels of refcounting: One global level that keeps track of whether any XDP
programs using the xdp_redirect() helper are loaded in the system at all. And
another that keeps track of whether any programs that could potentially result
in a call to xdp_redirect (i.e., either programs using the helper, or programs
using tail calls) are loaded in a given namespace.

The default maps are dynamically sized to the nearest power-of-two size that can
contain all interfaces present in each interface. If allocation fails, the user
action that triggered the allocation (either attaching an XDP program, or moving
an interface with a program attached) is rejected. If new interfaces appear in
a namespace which causes the default map to become too small, a new one is
allocated with the correct size; this allocation is the only one that cannot
lead to a rejection of the userspace action, so if it fails a warning is emitted
instead.

The first patch in the series refactors devmap.c to prepare for the subsequent
patches. The second patch adds the default map handling using the existing
array-based devmap structure. The third patch adds a new map type (devmap_idx)
that hashes devices on ifindex.

Changelog:

v2 -> v3:
- Fix compile warnings when CONFIG_BPF_SYSCALL is unset (as pointed out by the
  kbuild test bot).

v1 -> v2:
- Add refcounting to only allocate default maps when needed
- Using said refcounting, also deallocate default maps
- Add dynamic sizing of default maps
- Handle moving of interfaces between namespaces
- Split out refactoring of devmap.c to separate patch
- Use hashmap semantics for update_elem of devmap_idx type maps

---

Toke Høiland-Jørgensen (3):
      xdp: Refactor devmap code in preparation for subsequent additions
      xdp: Always use a devmap for XDP_REDIRECT to a device
      xdp: Add devmap_idx map type for looking up devices by ifindex


 include/linux/bpf.h                     |   46 ++
 include/linux/bpf_types.h               |    1 
 include/linux/filter.h                  |    2 
 include/net/net_namespace.h             |    2 
 include/net/netns/xdp.h                 |   11 +
 include/trace/events/xdp.h              |    3 
 include/uapi/linux/bpf.h                |    1 
 kernel/bpf/devmap.c                     |  609 +++++++++++++++++++++++++++----
 kernel/bpf/syscall.c                    |   27 +
 kernel/bpf/verifier.c                   |   14 +
 net/core/dev.c                          |   59 +++
 net/core/filter.c                       |   69 +---
 tools/bpf/bpftool/map.c                 |    1 
 tools/include/uapi/linux/bpf.h          |    1 
 tools/lib/bpf/libbpf_probes.c           |    1 
 tools/testing/selftests/bpf/test_maps.c |   16 +
 16 files changed, 720 insertions(+), 143 deletions(-)


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2019-03-05  9:53 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-01 14:12 [PATCH net-next v3 0/3] xdp: Use a default map for xdp_redirect helper Toke Høiland-Jørgensen
2019-03-01 14:12 ` [PATCH net-next v3 3/3] xdp: Add devmap_idx map type for looking up devices by ifindex Toke Høiland-Jørgensen
2019-03-01 14:12 ` [PATCH net-next v3 1/3] xdp: Refactor devmap code in preparation for subsequent additions Toke Høiland-Jørgensen
2019-03-02  1:08   ` Jakub Kicinski
2019-03-04 12:47     ` Toke Høiland-Jørgensen
2019-03-04 17:08       ` Jakub Kicinski
2019-03-04 17:37         ` Toke Høiland-Jørgensen
2019-03-01 14:12 ` [PATCH net-next v3 2/3] xdp: Always use a devmap for XDP_REDIRECT to a device Toke Høiland-Jørgensen
2019-03-02  2:09   ` Jakub Kicinski
2019-03-04 11:58     ` Toke Høiland-Jørgensen
2019-03-04 17:44       ` Jakub Kicinski
2019-03-04 19:05         ` Toke Høiland-Jørgensen
2019-03-04 22:15           ` Jakub Kicinski
2019-03-04 22:28             ` Toke Høiland-Jørgensen
2019-03-04 22:49               ` Jakub Kicinski
2019-03-05  9:53                 ` Toke Høiland-Jørgensen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.