Message ID | 20240102190055.1602698-1-andrii@kernel.org (mailing list archive) |
---|---|
Headers | show |
Series | Libbpf-side __arg_ctx fallback support | expand |
On Tue, Jan 2, 2024 at 11:01 AM Andrii Nakryiko <andrii@kernel.org> wrote: > > Support __arg_ctx global function argument tag semantics even on older kernels > that don't natively support it through btf_decl_tag("arg:ctx"). > > Patch #1 does a bunch of internal renaming to make internal function naming > consistent. We were doing it lazily up until now, but mixing single and double > underscored names are confusing, so let's bite a bullet and get it over the > finish line in one go. > > Patches #3-#7 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 #5 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 #9 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. > Oops, I forgot to add version history. It's basically: 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: name internal functions consistently > 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 > > tools/lib/bpf/libbpf.c | 1055 ++++++++++------- > tools/lib/bpf/libbpf_internal.h | 24 + > .../bpf/progs/test_global_func_ctx_args.c | 49 + > 3 files changed, 725 insertions(+), 403 deletions(-) > > -- > 2.34.1 >
On Tue, 2024-01-02 at 11:00 -0800, Andrii Nakryiko wrote: > Support __arg_ctx global function argument tag semantics even on older kernels > that don't natively support it through btf_decl_tag("arg:ctx"). > > Patch #1 does a bunch of internal renaming to make internal function naming > consistent. We were doing it lazily up until now, but mixing single and double > underscored names are confusing, so let's bite a bullet and get it over the > finish line in one go. > > Patches #3-#7 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 #5 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 #9 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. I've read through the patch-set and it seems to be fine, as far as my (limited) understanding of the code base goes. Left a few nitpicks. [...]