From: Alan Maguire <almagui@kernel.org>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org
Cc: eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev,
song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org,
emil@etsalapatis.com, ihor.solodrai@linux.dev,
john.fastabend@gmail.com, bpf@vger.kernel.org,
Alan Maguire <almagui@kernel.org>
Subject: [PATCH bpf-next 0/7] libbpf, bpf: Utilize CO-RE for BPF program parameter presence, ordering
Date: Mon, 23 Nov 2026 22:32:20 +0000 [thread overview]
Message-ID: <20261123223227.745345-1-almagui@kernel.org> (raw)
Currently the BPF_PROG() family of macros greatly facilitates
BPF tracing/LSM program writing by allowing specification
of function, tracepoint or LSM hook arguments directly by
name and type. These are then mapped to a context struct
consisting of a u64 array, with one value for each argument,
with by-value structs > 8 bytes taking two slots.
By instead creating a structure with named members, we can
bring a Compile Once, Run Everywhere experience to parameter
specifications via a new BPF_PROG_CORE() macro. This will
better handle cases like the following:
Problem: A tracing program only needs to use one parameter
from a multi-parameter kernel function signature, but verification
can fail if the function signature changes due to added or removed
parameters which are irrelevant to the case in hand.
Solution: Only specify the needed parameter in BPF_PROG_CORE()
Example:
/*
* Prototype for filename_unlinkat is:
* int filename_unlinkat(int dfd, struct filename * name);
*/
SEC("fentry/filename_unlinkat")
int BPF_PROG_CORE(handle, struct filename *, name)
{
if (bpf_func_arg_exists(name))
...
Problem: Ordering of parameters changes for a BPF LSM program
Solution: Again use BPF_PROG_CORE() which is resilient to
ordering changes as these become CO-RE relocations in the
context structure. Return values should be tagged with
__bpf_func_ret .
Problem: A parameter type changes
Solution: Use ___<new> named variants with old and new
types:
int BPF_PROG_CORE(handle, struct vm_area_struct *vma,
struct mm_area *vma___new)
{
if (bpf_func_arg_exists(vma___new))
...
else if (bpf_func_arg_exists(vma)
Because the solution is purely in libbpf, the support needs
no kernel changes, aside from the light skeleton case,
where CO-RE relocation is done in-kernel (support for the
latter is added in patch 2). Patch 5 provides a test
that programs can use to see if support is present.
Support covers fentry, fexit, fmod_ret, fsession, tp_btf,
lsm_cgroup and BPF LSM programs.
In short, we are making use of BPF CO-RE to extend a CO-RE
experience to program parameter ordering, presence and
handling of parameter type changes.
Limitations: tp_btf programs require >= 5.10 kernel since
it is the first kernel that makes tp_btf parameter names
available, while on big-endian (s390x) platforms, signed values
smaller than 8 bytes cannot be read.
This support requires BTF declaration tag support in clang/gcc
to work; because gcc does not support declaration tags on types
we add a marker within the struct itself.
Patch 1 adds libbpf support.
Patch 2 adds kernel-based lskel support.
Patch 3 tests tracing program support.
Patch 4 tests BPF LSM support.
Patch 5 provides a test BPF program writers can use -
bpf_func_args_supported() - to probe for support.
Patch 6 tests that probe.
Patch 7 documents the support.
Alan Maguire (7):
libbpf: Support CO-RE relocation of tracing program arguments
bpf: Support CO-RE relocation of tracing program arguments
selftests/bpf: Test CO-RE relocation of tracing program arguments
selftests/bpf: Test CO-RE relocation of BPF LSM program arguments
libbpf: Report function argument relocation support via type existence
selftests/bpf: Test detection of function argument relocation support
Documentation/bpf: Describe CO-RE relocation of function arguments
Documentation/bpf/libbpf/libbpf_overview.rst | 190 ++++++++
Documentation/bpf/llvm_reloc.rst | 95 ++++
include/linux/bpf.h | 2 +
kernel/bpf/btf.c | 38 ++
kernel/bpf/check_btf.c | 1 +
tools/lib/bpf/bpf_tracing.h | 195 ++++++++
tools/lib/bpf/libbpf.c | 142 +++++-
tools/lib/bpf/relo_core.c | 458 +++++++++++++++++-
tools/lib/bpf/relo_core.h | 29 ++
tools/testing/selftests/bpf/Makefile.skel | 3 +-
.../selftests/bpf/prog_tests/func_args_core.c | 325 +++++++++++++
.../selftests/bpf/progs/func_args_core.c | 241 +++++++++
.../selftests/bpf/progs/func_args_core_lsm.c | 156 ++++++
.../bpf/progs/func_args_core_lsm_cgroup.c | 40 ++
14 files changed, 1905 insertions(+), 10 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/func_args_core.c
create mode 100644 tools/testing/selftests/bpf/progs/func_args_core.c
create mode 100644 tools/testing/selftests/bpf/progs/func_args_core_lsm.c
create mode 100644 tools/testing/selftests/bpf/progs/func_args_core_lsm_cgroup.c
--
2.56.0
next reply other threads:[~2026-11-23 22:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 22:32 Alan Maguire [this message]
2026-11-23 22:32 ` [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments Alan Maguire
2026-11-23 22:53 ` sashiko-bot
2026-11-23 23:23 ` bot+bpf-ci
2026-11-23 22:32 ` [PATCH bpf-next 2/7] bpf: " Alan Maguire
2026-11-23 22:52 ` sashiko-bot
2026-11-23 22:32 ` [PATCH bpf-next 3/7] selftests/bpf: Test " Alan Maguire
2026-11-23 22:43 ` sashiko-bot
2026-11-23 22:32 ` [PATCH bpf-next 4/7] selftests/bpf: Test CO-RE relocation of BPF LSM " Alan Maguire
2026-11-23 22:41 ` sashiko-bot
2026-11-23 22:32 ` [PATCH bpf-next 5/7] libbpf: Report function argument relocation support via type existence Alan Maguire
2026-11-23 22:38 ` sashiko-bot
2026-11-23 22:32 ` [PATCH bpf-next 6/7] selftests/bpf: Test detection of function argument relocation support Alan Maguire
2026-11-23 22:36 ` sashiko-bot
2026-11-23 22:32 ` [PATCH bpf-next 7/7] Documentation/bpf: Describe CO-RE relocation of function arguments Alan Maguire
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=20261123223227.745345-1-almagui@kernel.org \
--to=almagui@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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