All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v4 00/13] bpf: implement bpf iterator for map elements
@ 2020-07-23 18:41 Yonghong Song
  2020-07-23 18:41 ` [PATCH bpf-next v4 01/13] bpf: refactor bpf_iter_reg to have separate seq_info member Yonghong Song
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: Yonghong Song @ 2020-07-23 18:41 UTC (permalink / raw)
  To: bpf, netdev
  Cc: Alexei Starovoitov, Daniel Borkmann, kernel-team, Martin KaFai Lau

Bpf iterator has been implemented for task, task_file,
bpf_map, ipv6_route, netlink, tcp and udp so far.

For map elements, there are two ways to traverse all elements from
user space:
  1. using BPF_MAP_GET_NEXT_KEY bpf subcommand to get elements
     one by one.
  2. using BPF_MAP_LOOKUP_BATCH bpf subcommand to get a batch of
     elements.
Both these approaches need to copy data from kernel to user space
in order to do inspection.

This patch implements bpf iterator for map elements.
User can have a bpf program in kernel to run with each map element,
do checking, filtering, aggregation, modifying values etc.
without copying data to user space.

Patch #1 and #2 are refactoring. Patch #3 implements readonly/readwrite
buffer support in verifier. Patches #4 - #7 implements map element
support for hash, percpu hash, lru hash lru percpu hash, array,
percpu array and sock local storage maps. Patches #8 - #9 are libbpf
and bpftool support. Patches #10 - #13 are selftests for implemented
map element iterators.

Changelogs:
  v3 -> v4:
    . fix a kasan failure triggered by a failed bpf_iter link_create,
      not just free_link but need cleanup_link. (Alexei)
  v2 -> v3:
    . rebase on top of latest bpf-next
  v1 -> v2:
    . support to modify map element values. (Alexei)
    . map key/values can be used with helper arguments
      for those arguments with ARG_PTR_TO_MEM or
      ARG_PTR_TO_INIT_MEM register type. (Alexei)
    . remove usused variable. (kernel test robot)

Yonghong Song (13):
  bpf: refactor bpf_iter_reg to have separate seq_info member
  bpf: refactor to provide aux info to bpf_iter_init_seq_priv_t
  bpf: support readonly/readwrite buffers in verifier
  bpf: implement bpf iterator for map elements
  bpf: implement bpf iterator for hash maps
  bpf: implement bpf iterator for array maps
  bpf: implement bpf iterator for sock local storage map
  tools/libbpf: add support for bpf map element iterator
  tools/bpftool: add bpftool support for bpf map element iterator
  selftests/bpf: add test for bpf hash map iterators
  selftests/bpf: add test for bpf array map iterators
  selftests/bpf: add a test for bpf sk_storage_map iterator
  selftests/bpf: add a test for out of bound rdonly buf access

 fs/proc/proc_net.c                            |   2 +-
 include/linux/bpf.h                           |  42 +-
 include/linux/proc_fs.h                       |   3 +-
 include/uapi/linux/bpf.h                      |   7 +
 kernel/bpf/arraymap.c                         | 138 ++++++
 kernel/bpf/bpf_iter.c                         |  85 +++-
 kernel/bpf/btf.c                              |  13 +
 kernel/bpf/hashtab.c                          | 194 ++++++++
 kernel/bpf/map_iter.c                         |  62 ++-
 kernel/bpf/prog_iter.c                        |   8 +-
 kernel/bpf/task_iter.c                        |  18 +-
 kernel/bpf/verifier.c                         |  91 +++-
 net/core/bpf_sk_storage.c                     | 206 ++++++++
 net/ipv4/tcp_ipv4.c                           |  12 +-
 net/ipv4/udp.c                                |  12 +-
 net/ipv6/route.c                              |   8 +-
 net/netlink/af_netlink.c                      |   8 +-
 .../bpftool/Documentation/bpftool-iter.rst    |  18 +-
 tools/bpf/bpftool/bash-completion/bpftool     |  18 +-
 tools/bpf/bpftool/iter.c                      |  33 +-
 tools/include/uapi/linux/bpf.h                |   7 +
 tools/lib/bpf/bpf.c                           |   1 +
 tools/lib/bpf/bpf.h                           |   3 +-
 tools/lib/bpf/libbpf.c                        |  10 +-
 tools/lib/bpf/libbpf.h                        |   3 +-
 .../selftests/bpf/prog_tests/bpf_iter.c       | 442 ++++++++++++++++++
 .../bpf/progs/bpf_iter_bpf_array_map.c        |  40 ++
 .../bpf/progs/bpf_iter_bpf_hash_map.c         | 100 ++++
 .../bpf/progs/bpf_iter_bpf_percpu_array_map.c |  46 ++
 .../bpf/progs/bpf_iter_bpf_percpu_hash_map.c  |  50 ++
 .../bpf/progs/bpf_iter_bpf_sk_storage_map.c   |  34 ++
 .../selftests/bpf/progs/bpf_iter_test_kern5.c |  35 ++
 32 files changed, 1687 insertions(+), 62 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_bpf_array_map.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_bpf_hash_map.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_bpf_percpu_array_map.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_bpf_percpu_hash_map.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_bpf_sk_storage_map.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_test_kern5.c

-- 
2.24.1


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

end of thread, other threads:[~2020-07-24  5:12 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23 18:41 [PATCH bpf-next v4 00/13] bpf: implement bpf iterator for map elements Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 01/13] bpf: refactor bpf_iter_reg to have separate seq_info member Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 02/13] bpf: refactor to provide aux info to bpf_iter_init_seq_priv_t Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 03/13] bpf: support readonly/readwrite buffers in verifier Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 04/13] bpf: implement bpf iterator for map elements Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 05/13] bpf: implement bpf iterator for hash maps Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 06/13] bpf: implement bpf iterator for array maps Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 07/13] bpf: implement bpf iterator for sock local storage map Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 08/13] tools/libbpf: add support for bpf map element iterator Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 09/13] tools/bpftool: add bpftool " Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 10/13] selftests/bpf: add test for bpf hash map iterators Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 11/13] selftests/bpf: add test for bpf array " Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 12/13] selftests/bpf: add a test for bpf sk_storage_map iterator Yonghong Song
2020-07-23 18:41 ` [PATCH bpf-next v4 13/13] selftests/bpf: add a test for out of bound rdonly buf access Yonghong Song
2020-07-24  5:11 ` [PATCH bpf-next v4 00/13] bpf: implement bpf iterator for map elements Alexei Starovoitov

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.