mbox series

[bpf-next,v4,0/7] Sockmap iterator

Message ID 20200907144701.44867-1-lmb@cloudflare.com
Headers show
Series Sockmap iterator | expand

Message

Lorenz Bauer Sept. 7, 2020, 2:46 p.m. UTC
Martin pointed out that a struct sock pointer may not be a full socket.
It's therefore invalid to accept such a pointer in lieu of PTR_TO_SOCKET.
Instead, we can allow passing it instead of PTR_TO_SOCK_COMMON. The sockmap
helpers are then adjusted to accept PTR_TO_SOCK_COMMON. This requires no
changes to the sockmap code itself since it already checks for fullsocks.

Changes in v4:
- Alias struct sock* to PTR_TO_SOCK_COMMON instead of PTR_TO_SOCKET (Martin)

Changes in v3:
- Use PTR_TO_BTF_ID in iterator context (Yonghong, Martin)
- Use rcu_dereference instead of rcu_dereference_raw (Jakub)
- Fix various test nits (Jakub, Andrii)

Changes in v2:
- Remove unnecessary sk_fullsock checks (Jakub)
- Nits for test output (Jakub)
- Increase number of sockets in tests to 64 (Jakub)
- Handle ENOENT in tests (Jakub)
- Actually test SOCKHASH iteration (myself)
- Fix SOCKHASH iterator initialization (myself)

v1: https://lore.kernel.org/bpf/20200828094834.23290-1-lmb@cloudflare.com/
v2: https://lore.kernel.org/bpf/20200901103210.54607-1-lmb@cloudflare.com/

Lorenz Bauer (7):
  bpf: Allow passing BTF pointers as PTR_TO_SOCK_COMMON
  net: sockmap: Remove unnecessary sk_fullsock checks
  net: Allow iterating sockmap and sockhash
  bpf: sockmap: accept sock_common pointer when updating
  selftests: bpf: Ensure that BTF sockets cannot be released
  selftests: bpf: Add helper to compare socket cookies
  selftests: bpf: Test copying a sockmap via bpf_iter

 kernel/bpf/verifier.c                         |  63 ++--
 net/core/sock_map.c                           | 284 +++++++++++++++++-
 .../bpf/prog_tests/reference_tracking.c       |  20 +-
 .../selftests/bpf/prog_tests/sockmap_basic.c  | 138 ++++++++-
 tools/testing/selftests/bpf/progs/bpf_iter.h  |   9 +
 .../selftests/bpf/progs/bpf_iter_sockmap.c    |  57 ++++
 .../selftests/bpf/progs/bpf_iter_sockmap.h    |   3 +
 .../bpf/progs/test_sk_ref_track_invalid.c     |  20 ++
 8 files changed, 549 insertions(+), 45 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_sockmap.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_sockmap.h
 create mode 100644 tools/testing/selftests/bpf/progs/test_sk_ref_track_invalid.c