Skip to content

BTF-defined BPF map definitions

Andrii Nakryiko bpf linux-perf-users netdev 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest11 patches 17 repliesIn review
  2. v18 patches 17 repliesSuperseded

Changes in v2 from the cover letter

- more BTF-sanity checks in parsing map definitions (Song);
- removed confusing usage of "attribute", switched to "field;
- split off elf_collect() refactor from btf loading refactor (Song);
- split selftests conversion into 3 patches (Stanislav):
1. test already relying on BTF;
2. tests w/ custom types as key/value (so benefiting from BTF);
3. all the rest tests (integers as key/value, special maps w/o BTF support).
- smaller code improvements (Song);

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/11libbpf: add common min/max macro to libbpf_internal.htools/lib/bpf/bpf.c tools/lib/bpf/bpf_prog_linfo.c tools/lib/bpf/btf.c +2 more+10 -150 replies
2/11libbpf: extract BTF loading logictools/lib/bpf/libbpf.c+55 -381 reply
3/11libbpf: streamline ELF parsing error-handlingtools/lib/bpf/libbpf.c+20 -241 reply
4/11libbpf: refactor map initializationtools/lib/bpf/libbpf.c+133 -1144 replies
5/11libbpf: identify maps by section index in addition to offsettools/lib/bpf/libbpf.c+25 -150 replies
6/11libbpf: split initialization and loading of BTFtools/lib/bpf/libbpf.c+24 -100 replies
7/11libbpf: allow specifying map definitions using BTFtools/lib/bpf/btf.h tools/lib/bpf/libbpf.c+345 -91 reply
8/11selftests/bpf: add test for BTF-defined mapstools/testing/selftests/bpf/progs/test_btf_newkv.c tools/testing/selftests/bpf/test_btf.c+76 -70 replies
9/11selftests/bpf: switch BPF_ANNOTATE_KV_PAIR tests to BTF-defined mapstools/testing/selftests/bpf/progs/netcnt_prog.c tools/testing/selftests/bpf/progs/test_map_lock.c tools/testing/selftests/bpf/progs/test_send_signal_kern.c +2 more+87 -722 replies
10/11selftests/bpf: convert tests w/ custom values to BTF-defined mapstools/testing/selftests/bpf/progs/bpf_flow.c tools/testing/selftests/bpf/progs/socket_cookie_prog.c tools/testing/selftests/bpf/progs/test_get_stack_rawtp.c +11 more+285 -1400 replies
11/11selftests/bpf: convert remaining selftests to BTF-defined mapstools/testing/selftests/bpf/progs/get_cgroup_id_kern.c tools/testing/selftests/bpf/progs/sample_map_ret0.c tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c +7 more+154 -660 replies

Reviews trailers per patch

9 of 11 patches have a Reviewed-by or Acked-by.

PatchSong Liu
1/11A-b
2/11A-b
3/11A-b
4/11A-b
5/11A-b
6/11A-b
7/11A-b
8/11A-b
9/11A-b
10/11
11/11

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 bpf-next 00/11] BTF-defined BPF map definitions

This patch set implements initial version (as discussed at LSF/MM2019 conference) of a new way to specify BPF maps, relying on BTF type information, which allows for easy extensibility, preserving forward and backward compatibility. See details and examples in description for patch #6.

[0] contains an outline of follow up extensions to be added after this basic set of features lands. They are useful by itself, but also allows to bring libbpf to feature-parity with iproute2 BPF loader. That should open a path forward for BPF loaders unification.

Patch #1 centralizes commonly used min/max macro in libbpf_internal.h. Patch #2 extracts .BTF and .BTF.ext loading loging from elf_collect(). Patch #3 simplifies elf_collect() error-handling logic.
Patch #4 refactors map initialization logic into user-provided maps and global data maps, in preparation to adding another way (BTF-defined maps). Patch #5 adds support for map definitions in multiple ELF sections and deprecates bpf_object__find_map_by_offset() API which doesn't appear to be used anymore and makes assumption that all map definitions reside in single ELF section.
Patch #6 splits BTF intialization from sanitization/loading into kernel to preserve original BTF at the time of map initialization.
Patch #7 adds support for BTF-defined maps.
Patch #8 adds new test for BTF-defined map definition.
Patches #9-11 convert test BPF map definitions to use BTF way.

[0] https://lore.kernel.org/bpf/CAEf4BzbfdG2ub7gCi0OYqBrUoChVHWsmOntWAkJt47=FE+km+A@mail.gmail.com/

v1->v2:
- more BTF-sanity checks in parsing map definitions (Song);
- removed confusing usage of "attribute", switched to "field;
- split off elf_collect() refactor from btf loading refactor (Song);
- split selftests conversion into 3 patches (Stanislav):
1. test already relying on BTF;
2. tests w/ custom types as key/value (so benefiting from BTF);
3. all the rest tests (integers as key/value, special maps w/o BTF support).
- smaller code improvements (Song);

rfc->v1:
- error out on unknown field by default (Stanislav, Jakub, Lorenz);

Andrii Nakryiko (11):
libbpf: add common min/max macro to libbpf_internal.h
libbpf: extract BTF loading logic
libbpf: streamline ELF parsing error-handling
libbpf: refactor map initialization
libbpf: identify maps by section index in addition to offset
libbpf: split initialization and loading of BTF
libbpf: allow specifying map definitions using BTF selftests/bpf: add test for BTF-defined maps selftests/bpf: switch BPF_ANNOTATE_KV_PAIR tests to BTF-defined maps selftests/bpf: convert tests w/ custom values to BTF-defined maps selftests/bpf: convert remaining selftests to BTF-defined maps

 tools/lib/bpf/bpf.c                           |   7 +-
 tools/lib/bpf/bpf_prog_linfo.c                |   5 +-
 tools/lib/bpf/btf.c                           |   3 -
 tools/lib/bpf/btf.h                           |   1 +
 tools/lib/bpf/btf_dump.c                      |   3 -
 tools/lib/bpf/libbpf.c                        | 781 +++++++++++++-----
 tools/lib/bpf/libbpf_internal.h               |   7 +
 tools/testing/selftests/bpf/progs/bpf_flow.c  |  18 +-
 .../selftests/bpf/progs/get_cgroup_id_kern.c  |  18 +-
 .../testing/selftests/bpf/progs/netcnt_prog.c |  22 +-
 .../selftests/bpf/progs/sample_map_ret0.c     |  18 +-
 .../selftests/bpf/progs/socket_cookie_prog.c  |  11 +-
 .../bpf/progs/sockmap_verdict_prog.c          |  36 +-
 .../selftests/bpf/progs/test_btf_newkv.c      |  73 ++
 .../bpf/progs/test_get_stack_rawtp.c          |  27 +-
 .../selftests/bpf/progs/test_global_data.c    |  27 +-
 tools/testing/selftests/bpf/progs/test_l4lb.c |  45 +-
 .../selftests/bpf/progs/test_l4lb_noinline.c  |  45 +-
 .../selftests/bpf/progs/test_map_in_map.c     |  20 +-
 .../selftests/bpf/progs/test_map_lock.c       |  22 +-
 .../testing/selftests/bpf/progs/test_obj_id.c |   9 +-
 .../bpf/progs/test_select_reuseport_kern.c    |  45 +-
 .../bpf/progs/test_send_signal_kern.c         |  22 +-
 .../bpf/progs/test_skb_cgroup_id_kern.c       |   9 +-
 .../bpf/progs/test_sock_fields_kern.c         |  60 +-
 .../selftests/bpf/progs/test_spin_lock.c      |  33 +-
 .../bpf/progs/test_stacktrace_build_id.c      |  44 +-
 .../selftests/bpf/progs/test_stacktrace_map.c |  40 +-
 .../testing/selftests/bpf/progs/test_tc_edt.c |   9 +-
 .../bpf/progs/test_tcp_check_syncookie_kern.c |   9 +-
 .../selftests/bpf/progs/test_tcp_estats.c     |   9 +-
 .../selftests/bpf/progs/test_tcpbpf_kern.c    |  18 +-
 .../selftests/bpf/progs/test_tcpnotify_kern.c |  18 +-
 tools/testing/selftests/bpf/progs/test_xdp.c  |  18 +-
 .../selftests/bpf/progs/test_xdp_noinline.c   |  60 +-
 tools/testing/selftests/bpf/test_btf.c        |  10 +-
 .../selftests/bpf/test_queue_stack_map.h      |  20 +-
 .../testing/selftests/bpf/test_sockmap_kern.h |  72 +-
 38 files changed, 1199 insertions(+), 495 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/test_btf_newkv.c
Signature · 1 line
2.17.1