Skip to content

Add new-style bpf_object__open APIs

Andrii Nakryiko bpf netdev 3 versions Applied

Status from this message: Applied. Thanks

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest4 patches 4 repliesApplied
  2. v23 patches 2 repliesSuperseded
  3. v13 patches 1 replySuperseded

Changes in v3 from the cover letter

- fix LIBBPF_OPTS() to ensure zero-initialization of padded bytes;
- pass through name override and relaxed maps flag for open_file() (Toke);
- fix bpf_object__name() to actually return object name;
- don't bother parsing and verifying version section (John);

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/4libbpf: stop enforcing kern_version, populate it for userstools/lib/bpf/libbpf.c tools/lib/bpf/libbpf.h tools/testing/selftests/bpf/progs/test_attach_probe.c +3 more+23 -832 replies
2/4libbpf: add bpf_object__open_{file,mem} w/ extensible optstools/lib/bpf/libbpf.c tools/lib/bpf/libbpf.h tools/lib/bpf/libbpf.map +1 more+146 -222 replies
3/4libbpf: fix bpf_object__name() to actually return object nametools/lib/bpf/libbpf.c+1 -10 replies
4/4selftests/bpf: switch tests to new bpf_object__open_{file,mem}() APIstools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/prog_tests/attach_probe.c tools/testing/selftests/bpf/prog_tests/reference_tracking.c+59 -80 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 bpf-next 0/4] Add new-style bpf_object__open APIs

Add bpf_object__open_file() and bpf_object__open_mem() APIs that use a new approach to providing future-proof non-ABI-breaking API changes. It relies on APIs accepting optional self-describing "opts" struct, containing its own size, filled out and provided by potentially outdated (as well as newer-than-libbpf) user application. A set of internal helper macros (OPTS_VALID, OPTS_HAS, and OPTS_GET) streamline and simplify a graceful handling forward and backward compatibility for user applications dynamically linked against different versions of libbpf shared library.

Users of libbpf are provided with convenience macro LIBBPF_OPTS that takes care of populating correct structure size and zero-initializes options struct, which helps avoid obscure issues of unitialized padding. Uninitialized padding in a struct might turn into garbage-populated new fields understood by future versions of libbpf.

Patch #1 removes enforcement of kern_version in libbpf and always populates correct one on behalf of users.
Patch #2 defines necessary infrastructure for options and two new open APIs relying on it.
Patch #3 fixes bug in bpf_object__name().
Patch #4 switches two of test_progs' tests to use new APIs as a validation that they work as expected.

v2->v3:
- fix LIBBPF_OPTS() to ensure zero-initialization of padded bytes;
- pass through name override and relaxed maps flag for open_file() (Toke);
- fix bpf_object__name() to actually return object name;
- don't bother parsing and verifying version section (John);

v1->v2:
- use better approach for tracking last field in opts struct;
- convert few tests to new APIs for validation;
- fix bug with using offsetof(last_field) instead of offsetofend(last_field).

Andrii Nakryiko (4):
libbpf: stop enforcing kern_version, populate it for users
libbpf: add bpf_object__open_{file,mem} w/ extensible opts
libbpf: fix bpf_object__name() to actually return object name selftests/bpf: switch tests to new bpf_object__open_{file,mem}() APIs

 tools/lib/bpf/libbpf.c                        | 183 +++++++++---------
 tools/lib/bpf/libbpf.h                        |  48 ++++-
 tools/lib/bpf/libbpf.map                      |   3 +
 tools/lib/bpf/libbpf_internal.h               |  32 +++
 tools/testing/selftests/bpf/Makefile          |   2 +-
 .../selftests/bpf/prog_tests/attach_probe.c   |  49 ++++-
 .../bpf/prog_tests/reference_tracking.c       |  16 +-
 .../selftests/bpf/progs/test_attach_probe.c   |   1 -
 .../bpf/progs/test_get_stack_rawtp.c          |   1 -
 .../selftests/bpf/progs/test_perf_buffer.c    |   1 -
 .../selftests/bpf/progs/test_stacktrace_map.c |   1 -
 11 files changed, 226 insertions(+), 111 deletions(-)
Signature · 1 line
2.17.1