BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/7] libbpf, bpf: Utilize CO-RE for BPF program parameter presence, ordering
@ 2026-11-23 22:32 Alan Maguire
  2026-11-23 22:32 ` [PATCH bpf-next 5/7] libbpf: Report function argument relocation support via type existence Alan Maguire
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Alan Maguire @ 2026-11-23 22:32 UTC (permalink / raw)
  To: ast, daniel, andrii
  Cc: eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil,
	ihor.solodrai, john.fastabend, bpf, Alan Maguire

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-11-23 23:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 22:32 [PATCH bpf-next 0/7] libbpf, bpf: Utilize CO-RE for BPF program parameter presence, ordering Alan Maguire
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
     [not found] ` <20261123223227.745345-5-almagui@kernel.org>
2026-11-23 22:41   ` [PATCH bpf-next 4/7] selftests/bpf: Test CO-RE relocation of BPF LSM program arguments sashiko-bot
     [not found] ` <20261123223227.745345-4-almagui@kernel.org>
2026-11-23 22:43   ` [PATCH bpf-next 3/7] selftests/bpf: Test CO-RE relocation of tracing " sashiko-bot
     [not found] ` <20261123223227.745345-3-almagui@kernel.org>
2026-11-23 22:52   ` [PATCH bpf-next 2/7] bpf: Support " sashiko-bot
     [not found] ` <20261123223227.745345-2-almagui@kernel.org>
2026-11-23 22:53   ` [PATCH bpf-next 1/7] libbpf: " sashiko-bot
2026-11-23 23:23   ` bot+bpf-ci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox