Skip to content

Libbpf-side __arg_ctx fallback support

Andrii Nakryiko bpf 3 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest9 patches 13 repliesApplied 9/9
  2. v29 patches 18 repliesSuperseded
  3. v18 patches 7 repliesSuperseded

Changes in v3 from the cover letter

- drop renaming patch (Alexei, Eduard);
- use memfd_create() instead of /dev/null for placeholder FD (Eduard);
- add one more test for validating BTF rewrite logic (Eduard);
- fixed wrong -errno usage, reshuffled some BTF rewrite bits (Eduard);

Patches in v3 All 9 applied

#Subject and filesSizeRepliesApplied
1/9libbpf: make uniform use of btf__fd() accessor inside libbpftools/lib/bpf/libbpf.c+1 -10 repliesApplied
2/9libbpf: use explicit map reuse flag to skip map creation stepstools/lib/bpf/libbpf.c+1 -10 repliesApplied
3/9libbpf: don't rely on map->fd as an indicator of map being createdtools/lib/bpf/libbpf.c+27 -150 repliesApplied
4/9libbpf: use stable map placeholder FDstools/lib/bpf/libbpf.c tools/lib/bpf/libbpf_internal.h+77 -380 repliesApplied
5/9libbpf: move exception callbacks assignment logic into relocation steptools/lib/bpf/libbpf.c+85 -800 repliesApplied
6/9libbpf: move BTF loading step after relocation steptools/lib/bpf/libbpf.c+1 -10 repliesApplied
7/9libbpf: implement __arg_ctx fallback logictools/lib/bpf/libbpf.c+252 -412 repliesApplied
8/9selftests/bpf: add arg:ctx cases to test_global_funcs teststools/testing/selftests/bpf/progs/test_global_func_ctx_args.c+49 -00 repliesApplied
9/9selftests/bpf: add __arg_ctx BTF rewrite testtools/testing/selftests/bpf/prog_tests/test_global_funcs.c+106 -00 repliesApplied

Reviews trailers per patch

8 of 9 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchJiri OlsaEduard Zingerman
SeriesA-b
1/9A-b
2/9A-b
3/9A-b
4/9A-b
5/9A-b
6/9A-b
7/9A-b
8/9A-b
9/9

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

Read the v3 thread

Cover letter [PATCH v3 bpf-next 0/9] Libbpf-side __arg_ctx fallback support

Support __arg_ctx global function argument tag semantics even on older kernels that don't natively support it through btf_decl_tag("arg:ctx").

Patches #2-#6 are preparatory work to allow to postpone BTF loading into the kernel until after all the BPF program relocations (including global func appending to main programs) are done. Patch #4 is perhaps the most important and establishes pre-created stable placeholder FDs, so that relocations can embed valid map FDs into ldimm64 instructions.

Once BTF is done after relocation, what's left is to adjust BTF information to have each main program's copy of each used global subprog to point to its own adjusted FUNC -> FUNC_PROTO type chain (if they use __arg_ctx) in such a way as to satisfy type expectations of BPF verifier regarding the PTR_TO_CTX argument definition. See patch #8 for details.

Patch #8 adds few more __arg_ctx use cases (edge cases like multiple arguments having __arg_ctx, etc) to test_global_func_ctx_args.c, to make it simple to validate that this logic indeed works on old kernels. It does. But just to be 100% sure patch #9 adds a test validating that libbpf uploads func_info with properly modified BTF data.

v2->v3:
- drop renaming patch (Alexei, Eduard);
- use memfd_create() instead of /dev/null for placeholder FD (Eduard);
- add one more test for validating BTF rewrite logic (Eduard);
- fixed wrong -errno usage, reshuffled some BTF rewrite bits (Eduard);
v1->v2:
- do internal functions renaming in patch #1 (Alexei);
- extract cloning of FUNC -> FUNC_PROTO information into separate function

    (Alexei);

Andrii Nakryiko (9):
libbpf: make uniform use of btf__fd() accessor inside libbpf
libbpf: use explicit map reuse flag to skip map creation steps
libbpf: don't rely on map->fd as an indicator of map being created
libbpf: use stable map placeholder FDs
libbpf: move exception callbacks assignment logic into relocation step
libbpf: move BTF loading step after relocation step
libbpf: implement __arg_ctx fallback logic
selftests/bpf: add arg:ctx cases to test_global_funcs tests selftests/bpf: add __arg_ctx BTF rewrite test

 tools/lib/bpf/libbpf.c                        | 570 +++++++++++++-----
 tools/lib/bpf/libbpf_internal.h               |  14 +
 .../bpf/prog_tests/test_global_funcs.c        | 106 ++++
 .../bpf/progs/test_global_func_ctx_args.c     |  49 ++
 4 files changed, 599 insertions(+), 140 deletions(-)
Signature · 1 line
2.34.1