bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next 00/12] bpf: Support by-value struct and __int128 arguments
@ 2026-09-04  5:09 Yonghong Song
  2026-09-04  5:10 ` [PATCH bpf-next 01/12] selftests/bpf: Add a test for an __int128 by-value argument Yonghong Song
                   ` (11 more replies)
  0 siblings, 12 replies; 27+ messages in thread
From: Yonghong Song @ 2026-09-04  5:09 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Eduard Zingerman, kernel-team

A global function or a kfunc taking a struct or union by value is rejected
today:

  Arg#1 type STRUCT in tar() is not supported yet.
  Unrecognized R2 type STRUCT

and an __int128 argument is accepted but mis-counted: the compiler passes
it in two registers while the verifier gives it one, so every argument
after it is checked against the wrong register and the program is rejected
for a register its source never names.

The compiler passes such a value in one argument register per eightbyte,
so a value of at most 16 bytes arrives in one or two consecutive
registers. This series teaches the verifier to describe that: sub->args[]
gains one entry per argument slot rather than one per BTF parameter, and
the kfunc argument walk counts slots the same way. A value may only be
composed of scalars, as a pointer would reach the callee as an opaque
scalar, losing the provenance and reference tracking that make it safe to
use. A global function still has no stack arguments, so all of its slots
have to fit in the argument registers.

For a kfunc the two calling conventions have to agree, and they do not
always. Where the BPF convention splits a value between the last argument
register and the stack, SysV moves the whole of it to the stack and gives
the register to the argument that follows, while AAPCS64 rounds the
register number up to an even one for a 16-byte aligned value and gives no
register to anything once one has gone to the stack. The JITs move the
eightbytes the two conventions place differently, and
bpf_jit_supports_kfunc_arg_slot() asks the JIT whether it can, defaulting
to no, so such an argument is refused on an architecture that has not
implemented the placement:

  Function f arg#5 type STRUCT cannot be passed at argument slot 5 on this
  architecture

Patch 1 records the __int128 failure as it stands today, which patch 4
turns into a success. Patches 2 to 4 index the arguments of a global
function by slot and accept a by-value struct and an __int128. Patch 5
does the same for a kfunc call. Patches 6 to 9 place the arguments per the
kernel calling convention in the x86-64 and arm64 JITs. Patches 10 to 12
are the tests.

Tested on x86-64 and arm64 with test_progs. The by-value struct tests are
built with clang, as GCC passes an aggregate by invisible reference, and
some of them need __BPF_FEATURE_STACK_ARGUMENT.

Yonghong Song (12):
  selftests/bpf: Add a test for an __int128 by-value argument
  bpf: Index global function arguments by argument slot
  bpf: Support by-value struct arguments up to 16 bytes
  bpf: Support __int128 as a by-value function argument
  bpf: Support by-value struct and __int128 kfunc arguments
  bpf: Add a JIT helper for the outgoing stack of kfunc calls
  bpf, x86: Place kfunc arguments per the SysV calling convention
  bpf: Record a 16-byte argument alignment in the function model
  bpf, arm64: Place kfunc arguments per AAPCS64
  selftests/bpf: Add C tests for by-value arguments up to 16 bytes
  selftests/bpf: Add inline-asm tests for by-value arguments
  selftests/bpf: Add tests for by-value kfunc arguments

 arch/arm64/net/bpf_jit_comp.c                 | 112 +++++++++-
 arch/x86/net/bpf_jit_comp.c                   | 185 +++++++++++++++-
 include/linux/bpf.h                           |   3 +
 include/linux/bpf_verifier.h                  |   1 +
 include/linux/filter.h                        |   3 +
 kernel/bpf/btf.c                              |  98 +++++++--
 kernel/bpf/core.c                             |  42 ++++
 kernel/bpf/verifier.c                         | 200 ++++++++++++++++--
 .../selftests/bpf/prog_tests/aggregate_arg.c  |  11 +
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/aggregate_arg_func.c  | 155 ++++++++++++++
 .../selftests/bpf/progs/aggregate_arg_kfunc.c | 106 ++++++++++
 .../testing/selftests/bpf/progs/arena_kfunc.c |  16 ++
 .../selftests/bpf/progs/stack_arg_fail.c      |  10 -
 .../selftests/bpf/progs/verifier_int128_arg.c | 195 +++++++++++++++++
 .../selftests/bpf/test_kmods/bpf_testmod.c    |  40 ++++
 .../bpf/test_kmods/bpf_testmod_kfunc.h        |  22 ++
 17 files changed, 1151 insertions(+), 50 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/aggregate_arg.c
 create mode 100644 tools/testing/selftests/bpf/progs/aggregate_arg_func.c
 create mode 100644 tools/testing/selftests/bpf/progs/aggregate_arg_kfunc.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_int128_arg.c

-- 
2.53.0-Meta


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

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

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04  5:09 [PATCH bpf-next 00/12] bpf: Support by-value struct and __int128 arguments Yonghong Song
2026-09-04  5:10 ` [PATCH bpf-next 01/12] selftests/bpf: Add a test for an __int128 by-value argument Yonghong Song
2026-09-04  5:10 ` [PATCH bpf-next 02/12] bpf: Index global function arguments by argument slot Yonghong Song
2026-09-04  5:10 ` [PATCH bpf-next 03/12] bpf: Support by-value struct arguments up to 16 bytes Yonghong Song
2026-09-04  5:23   ` sashiko-bot
2026-09-04  6:09   ` bot+bpf-ci
2026-09-04  5:10 ` [PATCH bpf-next 04/12] bpf: Support __int128 as a by-value function argument Yonghong Song
2026-09-04  5:32   ` sashiko-bot
2026-09-04  6:09   ` bot+bpf-ci
2026-09-04  5:10 ` [PATCH bpf-next 05/12] bpf: Support by-value struct and __int128 kfunc arguments Yonghong Song
2026-09-04  6:18   ` sashiko-bot
2026-09-04  6:24   ` bot+bpf-ci
2026-09-04  5:10 ` [PATCH bpf-next 06/12] bpf: Add a JIT helper for the outgoing stack of kfunc calls Yonghong Song
2026-09-04  5:25   ` sashiko-bot
2026-09-04  5:10 ` [PATCH bpf-next 07/12] bpf, x86: Place kfunc arguments per the SysV calling convention Yonghong Song
2026-09-04  5:36   ` sashiko-bot
2026-09-04 23:58   ` Alexei Starovoitov
2026-09-04  5:10 ` [PATCH bpf-next 08/12] bpf: Record a 16-byte argument alignment in the function model Yonghong Song
2026-09-04  6:09   ` bot+bpf-ci
2026-09-04  5:10 ` [PATCH bpf-next 09/12] bpf, arm64: Place kfunc arguments per AAPCS64 Yonghong Song
2026-09-04  6:09   ` bot+bpf-ci
2026-09-04  5:10 ` [PATCH bpf-next 10/12] selftests/bpf: Add C tests for by-value arguments up to 16 bytes Yonghong Song
2026-09-04  5:19   ` sashiko-bot
2026-09-04  6:09   ` bot+bpf-ci
2026-09-04  5:10 ` [PATCH bpf-next 11/12] selftests/bpf: Add inline-asm tests for by-value arguments Yonghong Song
2026-09-04  6:09   ` bot+bpf-ci
2026-09-04  5:11 ` [PATCH bpf-next 12/12] selftests/bpf: Add tests for by-value kfunc arguments Yonghong Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).