All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments
@ 2026-11-27 16:11 kernel test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-11-27 16:11 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

Unfiltered warning: this smatch report is sent as-is and has not been
reviewed for false positives, so please treat it with due skepticism.

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20261123223227.745345-2-almagui@kernel.org>
References: <20261123223227.745345-2-almagui@kernel.org>
TO: Alan Maguire <almagui@kernel.org>
TO: ast@kernel.org
TO: daniel@iogearbox.net
TO: andrii@kernel.org
CC: eddyz87@gmail.com
CC: memxor@gmail.com
CC: martin.lau@linux.dev
CC: song@kernel.org
CC: yonghong.song@linux.dev
CC: jolsa@kernel.org
CC: emil@etsalapatis.com
CC: ihor.solodrai@linux.dev
CC: john.fastabend@gmail.com
CC: bpf@vger.kernel.org
CC: Alan Maguire <almagui@kernel.org>

Hi Alan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on bpf-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Alan-Maguire/libbpf-Support-CO-RE-relocation-of-tracing-program-arguments/20261123-223221
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link:    https://lore.kernel.org/r/20261123223227.745345-2-almagui%40kernel.org
patch subject: [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments
:::::: branch date: 4 days ago
:::::: commit date: 4 days ago
config: arm-randconfig-2200-20261126 (https://download.01.org/0day-ci/archive/20261127/20261127170440.mE7JCAST-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 8.5.0
smatch: v0.5.0-9187-g5189e3fb

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/20261127170440.mE7JCAST-lkp@intel.com/

smatch warnings:
kernel/bpf/../../tools/lib/bpf/relo_core.c:1337 bpf_core_calc_relo() error: we previously assumed 'targ_spec' could be null (see line 1322)

vim +/targ_spec +1337 kernel/bpf/../../tools/lib/bpf/relo_core.c

2a6fa26be8e26a Alan Maguire       2026-11-23  1292  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1293  static int bpf_core_calc_relo(const char *prog_name,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1294  			      const struct bpf_core_relo *relo,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1295  			      int relo_idx,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1296  			      const struct bpf_core_spec *local_spec,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1297  			      const struct bpf_core_spec *targ_spec,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1298  			      struct bpf_core_relo_res *res)
b0588390dbcedc Alexei Starovoitov 2021-07-20  1299  {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1300  	int err = -EOPNOTSUPP;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1301  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1302  	res->orig_val = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1303  	res->new_val = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1304  	res->poison = false;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1305  	res->validate = true;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1306  	res->fail_memsz_adjust = false;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1307  	res->orig_sz = res->new_sz = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1308  	res->orig_type_id = res->new_type_id = 0;
2a6fa26be8e26a Alan Maguire       2026-11-23  1309  	res->widen_func_arg = false;
2a6fa26be8e26a Alan Maguire       2026-11-23  1310  	res->func_arg_signed = false;
2a6fa26be8e26a Alan Maguire       2026-11-23  1311  	res->func_arg_slot_off = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1312  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1313  	if (core_relo_is_field_based(relo->kind)) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1314  		err = bpf_core_calc_field_relo(prog_name, relo, local_spec,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1315  					       &res->orig_val, &res->orig_sz,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1316  					       &res->orig_type_id, &res->validate);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1317  		err = err ?: bpf_core_calc_field_relo(prog_name, relo, targ_spec,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1318  						      &res->new_val, &res->new_sz,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1319  						      &res->new_type_id, NULL);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1320  		if (err)
b0588390dbcedc Alexei Starovoitov 2021-07-20  1321  			goto done;
2a6fa26be8e26a Alan Maguire       2026-11-23 @1322  		if (relo->kind == BPF_CORE_FIELD_BYTE_OFFSET && targ_spec &&
2a6fa26be8e26a Alan Maguire       2026-11-23  1323  		    bpf_core_is_be_small_func_arg(targ_spec, &res->func_arg_signed)) {
2a6fa26be8e26a Alan Maguire       2026-11-23  1324  			/* context slots are 8-byte aligned */
2a6fa26be8e26a Alan Maguire       2026-11-23  1325  			res->widen_func_arg = true;
2a6fa26be8e26a Alan Maguire       2026-11-23  1326  			res->func_arg_slot_off = res->new_val & ~7ULL;
2a6fa26be8e26a Alan Maguire       2026-11-23  1327  		}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1328  		/* Validate if it's safe to adjust load/store memory size.
b0588390dbcedc Alexei Starovoitov 2021-07-20  1329  		 * Adjustments are performed only if original and new memory
b0588390dbcedc Alexei Starovoitov 2021-07-20  1330  		 * sizes differ.
b0588390dbcedc Alexei Starovoitov 2021-07-20  1331  		 */
b0588390dbcedc Alexei Starovoitov 2021-07-20  1332  		res->fail_memsz_adjust = false;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1333  		if (res->orig_sz != res->new_sz) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1334  			const struct btf_type *orig_t, *new_t;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1335  
74753e1462e773 Alexei Starovoitov 2021-12-01  1336  			orig_t = btf_type_by_id(local_spec->btf, res->orig_type_id);
74753e1462e773 Alexei Starovoitov 2021-12-01 @1337  			new_t = btf_type_by_id(targ_spec->btf, res->new_type_id);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1338  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1339  			/* There are two use cases in which it's safe to
b0588390dbcedc Alexei Starovoitov 2021-07-20  1340  			 * adjust load/store's mem size:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1341  			 *   - reading a 32-bit kernel pointer, while on BPF
b0588390dbcedc Alexei Starovoitov 2021-07-20  1342  			 *   size pointers are always 64-bit; in this case
b0588390dbcedc Alexei Starovoitov 2021-07-20  1343  			 *   it's safe to "downsize" instruction size due to
b0588390dbcedc Alexei Starovoitov 2021-07-20  1344  			 *   pointer being treated as unsigned integer with
b0588390dbcedc Alexei Starovoitov 2021-07-20  1345  			 *   zero-extended upper 32-bits;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1346  			 *   - reading unsigned integers, again due to
b0588390dbcedc Alexei Starovoitov 2021-07-20  1347  			 *   zero-extension is preserving the value correctly.
b0588390dbcedc Alexei Starovoitov 2021-07-20  1348  			 *
b0588390dbcedc Alexei Starovoitov 2021-07-20  1349  			 * In all other cases it's incorrect to attempt to
b0588390dbcedc Alexei Starovoitov 2021-07-20  1350  			 * load/store field because read value will be
b0588390dbcedc Alexei Starovoitov 2021-07-20  1351  			 * incorrect, so we poison relocated instruction.
b0588390dbcedc Alexei Starovoitov 2021-07-20  1352  			 */
b0588390dbcedc Alexei Starovoitov 2021-07-20  1353  			if (btf_is_ptr(orig_t) && btf_is_ptr(new_t))
b0588390dbcedc Alexei Starovoitov 2021-07-20  1354  				goto done;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1355  			if (btf_is_int(orig_t) && btf_is_int(new_t) &&
b0588390dbcedc Alexei Starovoitov 2021-07-20  1356  			    btf_int_encoding(orig_t) != BTF_INT_SIGNED &&
b0588390dbcedc Alexei Starovoitov 2021-07-20  1357  			    btf_int_encoding(new_t) != BTF_INT_SIGNED)
b0588390dbcedc Alexei Starovoitov 2021-07-20  1358  				goto done;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1359  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1360  			/* mark as invalid mem size adjustment, but this will
b0588390dbcedc Alexei Starovoitov 2021-07-20  1361  			 * only be checked for LDX/STX/ST insns
b0588390dbcedc Alexei Starovoitov 2021-07-20  1362  			 */
b0588390dbcedc Alexei Starovoitov 2021-07-20  1363  			res->fail_memsz_adjust = true;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1364  		}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1365  	} else if (core_relo_is_type_based(relo->kind)) {
4b443bc1785f28 Andrii Nakryiko    2021-12-12  1366  		err = bpf_core_calc_type_relo(relo, local_spec, &res->orig_val, &res->validate);
4b443bc1785f28 Andrii Nakryiko    2021-12-12  1367  		err = err ?: bpf_core_calc_type_relo(relo, targ_spec, &res->new_val, NULL);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1368  	} else if (core_relo_is_enumval_based(relo->kind)) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1369  		err = bpf_core_calc_enumval_relo(relo, local_spec, &res->orig_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1370  		err = err ?: bpf_core_calc_enumval_relo(relo, targ_spec, &res->new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1371  	}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1372  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1373  done:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1374  	if (err == -EUCLEAN) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1375  		/* EUCLEAN is used to signal instruction poisoning request */
b0588390dbcedc Alexei Starovoitov 2021-07-20  1376  		res->poison = true;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1377  		err = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1378  	} else if (err == -EOPNOTSUPP) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1379  		/* EOPNOTSUPP means unknown/unsupported relocation */
df3153758ddba5 Andrii Nakryiko    2026-06-24  1380  		pr_warn("prog '%s': relo #%d: unrecognized CO-RE relocation %s (%u) at insn #%u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1381  			prog_name, relo_idx, core_relo_kind_str(relo->kind),
b0588390dbcedc Alexei Starovoitov 2021-07-20  1382  			relo->kind, relo->insn_off / 8);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1383  	}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1384  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1385  	return err;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1386  }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1387  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread
* [PATCH bpf-next 0/7] libbpf, bpf: Utilize CO-RE for BPF program parameter presence, ordering
@ 2026-11-23 22:32 Alan Maguire
       [not found] ` <20261123223227.745345-2-almagui@kernel.org>
  0 siblings, 1 reply; 4+ 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] 4+ messages in thread

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 16:11 [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2026-11-23 22:32 [PATCH bpf-next 0/7] libbpf, bpf: Utilize CO-RE for BPF program parameter presence, ordering Alan Maguire
     [not found] ` <20261123223227.745345-2-almagui@kernel.org>
2026-11-23 22:53   ` [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments sashiko-bot
2026-11-23 23:23   ` bot+bpf-ci
2026-11-24 20:17     ` Andrey Grodzovsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.