BPF List
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>,
	<martin.lau@kernel.org>
Cc: <andrii@kernel.org>, <kernel-team@meta.com>
Subject: [PATCH v3 bpf-next 0/9] Libbpf-side __arg_ctx fallback support
Date: Wed, 3 Jan 2024 17:38:38 -0800	[thread overview]
Message-ID: <20240104013847.3875810-1-andrii@kernel.org> (raw)

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(-)

-- 
2.34.1


             reply	other threads:[~2024-01-04  1:38 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-04  1:38 Andrii Nakryiko [this message]
2024-01-04  1:38 ` [PATCH v3 bpf-next 1/9] libbpf: make uniform use of btf__fd() accessor inside libbpf Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 2/9] libbpf: use explicit map reuse flag to skip map creation steps Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 3/9] libbpf: don't rely on map->fd as an indicator of map being created Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 4/9] libbpf: use stable map placeholder FDs Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 5/9] libbpf: move exception callbacks assignment logic into relocation step Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 6/9] libbpf: move BTF loading step after " Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 7/9] libbpf: implement __arg_ctx fallback logic Andrii Nakryiko
2024-01-04  5:39   ` Alexei Starovoitov
2024-01-04 18:37     ` Andrii Nakryiko
2024-01-04 18:52       ` Alexei Starovoitov
2024-01-04 20:58         ` Andrii Nakryiko
2024-01-05  1:33           ` Alexei Starovoitov
2024-01-05  3:57             ` Andrii Nakryiko
2024-01-05  5:42               ` Alexei Starovoitov
2024-01-08 23:45                 ` Andrii Nakryiko
2024-01-09  1:49                   ` Alexei Starovoitov
2024-01-09 17:17                     ` Andrii Nakryiko
2024-01-10  1:58                       ` Alexei Starovoitov
2024-01-10 19:02                         ` Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 8/9] selftests/bpf: add arg:ctx cases to test_global_funcs tests Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 9/9] selftests/bpf: add __arg_ctx BTF rewrite test Andrii Nakryiko
2024-01-04  2:33 ` [PATCH v3 bpf-next 0/9] Libbpf-side __arg_ctx fallback support Eduard Zingerman
2024-01-04  8:13 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240104013847.3875810-1-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox