bpf: implement bpf iterator for map elements
Status from this message: Applied, Thanks
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest13 patches 1 replyApplied
- v313 patches 2 repliesSuperseded
- v213 patches 2 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 13 patches | 7 replies | Superseded |
Changes in v4 from the cover letter
. fix a kasan failure triggered by a failed bpf_iter link_create,
not just free_link but need cleanup_link. (Alexei)
Patches in v4 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/13 | bpf: refactor bpf_iter_reg to have separate seq_info memberinclude/ kernel/ kernel/ +6 more | +64 | 0 replies | |
| 2/13 | bpf: refactor to provide aux info to bpf_iter_init_seq_priv_tfs/ include/ include/ +4 more | +15 | 0 replies | |
| 3/13 | bpf: support readonly/readwrite buffers in verifierinclude/ kernel/ kernel/ | +104 | 0 replies | |
| 4/13 | bpf: implement bpf iterator for map elementsinclude/ include/ kernel/ +2 more | +128 | 0 replies | |
| 5/13 | bpf: implement bpf iterator for hash mapskernel/ kernel/ | +217 | 0 replies | |
| 6/13 | bpf: implement bpf iterator for array mapskernel/ kernel/ | +142 | 0 replies | |
| 7/13 | bpf: implement bpf iterator for sock local storage mapnet/ | +206 | 0 replies | |
| 8/13 | tools/libbpf: add support for bpf map element iteratortools/ tools/ tools/ +1 more | +14 | 0 replies | |
| 9/13 | tools/bpftool: add bpftool support for bpf map element iteratortools/ tools/ tools/ | +62 | 0 replies | |
| 10/13 | selftests/bpf: add test for bpf hash map iteratorstools/ tools/ tools/ | +337 | 0 replies | |
| 11/13 | selftests/bpf: add test for bpf array map iteratorstools/ tools/ tools/ | +247 | 0 replies | |
| 12/13 | selftests/bpf: add a test for bpf sk_storage_map iteratortools/ tools/ | +106 | 0 replies | |
| 13/13 | selftests/bpf: add a test for out of bound rdonly buf accesstools/ tools/ | +57 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.
Cover letter [PATCH bpf-next v4 00/13] bpf: implement bpf iterator for map elements
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
Signature · 1 line
2.24.1