Skip to content

Add arena argument support to kfuncs and struct_ops

Kumar Kartikeya Dwivedi bpf 5 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest14 patches 3 repliesApplied 14/14
  2. v413 patches 13 repliesSuperseded
  3. v39 patches 21 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v29 patches4 repliesSuperseded
v19 patches4 repliesSuperseded

Changes in v5 from the cover letter

v4: https://lore.kernel.org/bpf/[email protected]

* Remove the redundant patch-8 capability comment and duplicate nullable kfunc test coverage. (Eduard)
* Introduce the final bpf_tramp_arena_base() interface directly with function-model argument flags, avoiding temporary slot bitmaps and arena_nullable state; simplify struct_ops pointer validation. (Eduard)
* Simplify kfunc arena nullability classification by using the common nullable path for both arena suffixes while leaving the function model to distinguish JIT NULL preservation. (Amery)
* Keep bpf_prog_has_arena_ctx_arg() in bpf_verifier.h from its introduction so trampoline and verifier users share one inline definition, avoiding BPF_JIT/BPF_SYSCALL link dependencies. (Eduard, BPF CI Bot)
* Reject both tracing and extension attachments to struct_ops programs with arena context arguments, and add fentry, fexit, and freplace rejection tests. (Eduard, Sashiko)

Patches in v5 All 14 applied

#Subject and filesSizeRepliesApplied
1/14bpf: Rename 'early' BTF checking as a preparation phaseinclude/linux/bpf_verifier.h kernel/bpf/check_btf.c kernel/bpf/verifier.c+12 -100 repliesApplied
2/14bpf: Split subprogram and kfunc collectionkernel/bpf/verifier.c+32 -90 repliesApplied
3/14bpf: Collect kfuncs after resolving program resourceskernel/bpf/verifier.c+6 -50 repliesApplied
4/14bpf: Support __arena and __arena__nullable kfunc argument suffixesDocumentation/bpf/kfuncs.rst include/linux/bpf.h include/linux/filter.h +3 more+100 -50 repliesApplied
5/14bpf: Support __arena and __arena__nullable on struct_ops argumentsDocumentation/bpf/kfuncs.rst include/linux/bpf.h include/linux/bpf_verifier.h +4 more+133 -221 replyApplied
6/14bpf, x86: JIT __arena kfunc argument rebasingarch/x86/net/bpf_jit_comp.c+50 -00 repliesApplied
7/14bpf, x86: Convert struct_ops arena arguments in the trampolinearch/x86/net/bpf_jit_comp.c+51 -60 repliesApplied
8/14selftests/bpf: Add kfunc __arena and __arena__nullable argument teststools/testing/selftests/bpf/prog_tests/verifier.c tools/testing/selftests/bpf/progs/arena_kfunc.c tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +1 more+290 -00 repliesApplied
9/14selftests/bpf: Add JIT-sequence tests for __arena kfunc argumentstools/testing/selftests/bpf/prog_tests/verifier.c tools/testing/selftests/bpf/progs/arena_kfunc_jit.c+101 -00 repliesApplied
10/14selftests/bpf: Add struct_ops __arena and __arena__nullable argument teststools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c tools/testing/selftests/bpf/progs/struct_ops_arena.c tools/testing/selftests/bpf/progs/struct_ops_arena_fail.c +3 more+217 -00 repliesApplied
11/14bpf, x86: Fix stack-passed arguments for indirect trampolinesarch/x86/net/bpf_jit_comp.c+8 -70 repliesApplied
12/14selftests/bpf: Test stack-passed struct_ops arena argumentstools/testing/selftests/bpf/progs/struct_ops_arena.c tools/testing/selftests/bpf/test_kmods/bpf_testmod.c tools/testing/selftests/bpf/test_kmods/bpf_testmod.h +1 more+39 -00 repliesApplied
13/14bpf: Reject tracing/freplace progs for struct_ops with arena argskernel/bpf/verifier.c+10 -01 replyApplied
14/14selftests/bpf: Test attach rejection for struct_ops arena programstools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c tools/testing/selftests/bpf/progs/struct_ops_arena_attach.c+79 -01 replyApplied

Reviews trailers per patch

12 of 14 patches have a Reviewed-by or Acked-by.

PatchAmery HungEduard Zingerman
1/14R-b
2/14R-b
3/14R-b
4/14A-b
5/14A-b
6/14A-b
7/14A-b
8/14A-b
9/14A-b
10/14A-b
11/14T-b
12/14T-b
13/14A-b
14/14A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [PATCH bpf-next v5 00/14] Add arena argument support to kfuncs and struct_ops

This is a continuation of patches in [0], with mostly minor changes and reordering. The motivation is covered in that link. A major change is moving to two tags (__arena and __arena__nullable) and moving the changes to JIT to emit more optimized sequences.

Please see commit logs for details.

[0]: https://lore.kernel.org/bpf/[email protected]

Changelog:
----------
v4 -> v5
v4: https://lore.kernel.org/bpf/[email protected]

* Remove the redundant patch-8 capability comment and duplicate nullable kfunc test coverage. (Eduard)
* Introduce the final bpf_tramp_arena_base() interface directly with function-model argument flags, avoiding temporary slot bitmaps and arena_nullable state; simplify struct_ops pointer validation. (Eduard)
* Simplify kfunc arena nullability classification by using the common nullable path for both arena suffixes while leaving the function model to distinguish JIT NULL preservation. (Amery)
* Keep bpf_prog_has_arena_ctx_arg() in bpf_verifier.h from its introduction so trampoline and verifier users share one inline definition, avoiding BPF_JIT/BPF_SYSCALL link dependencies. (Eduard, BPF CI Bot)
* Reject both tracing and extension attachments to struct_ops programs with arena context arguments, and add fentry, fexit, and freplace rejection tests. (Eduard, Sashiko)

v3 -> v4
v3: https://lore.kernel.org/bpf/[email protected]

* Rename __arena_nullable to __arena__nullable and prioritize the composite suffix over __nullable during argument classification. (Sashiko, Eduard)
* Resolve instructions before collecting subprograms and kfuncs so kfunc prototype validation can use associated arena state.
* Move the arena kfunc and JIT-sequence test entry points into prog_tests/verifier.c. (Eduard)
* Match the generated L0 target and call in nullable JIT assertions. (Eduard)
* Route arena kfunc validation through the common argument-checking path. (Amery)
* Reuse btf_func_model argument flags for struct_ops arena arguments instead of maintaining separate trampoline slot metadata. (Eduard)
* Check the generic-trampoline arena argument invariant at link time and warn once on violations. (Eduard)
* Reject tracing attachments to struct_ops programs with arena context arguments whose indirect trampolines convert the pointers. (Sashiko)

v2 -> v3
v2: https://lore.kernel.org/bpf/[email protected]

* Rebase onto current bpf-next to resolve conflicts.

v1 -> v2
v1: https://lore.kernel.org/bpf/[email protected]

* Fix documentation to only mention x86 for now. (Sashiko)
* Move arg bitmap from insn_aux_data to kfunc descriptor. (Eduard)

Kumar Kartikeya Dwivedi (5):
bpf: Rename 'early' BTF checking as a preparation phase
bpf: Split subprogram and kfunc collection
bpf: Collect kfuncs after resolving program resources
bpf: Reject tracing/freplace progs for struct_ops with arena args selftests/bpf: Test attach rejection for struct_ops arena programs

Tejun Heo (9):
bpf: Support __arena and __arena__nullable kfunc argument suffixes
bpf: Support __arena and __arena__nullable on struct_ops arguments bpf, x86: JIT __arena kfunc argument rebasing
bpf, x86: Convert struct_ops arena arguments in the trampoline selftests/bpf: Add kfunc __arena and __arena__nullable argument tests selftests/bpf: Add JIT-sequence tests for __arena kfunc arguments selftests/bpf: Add struct_ops __arena and __arena__nullable argument
tests
bpf, x86: Fix stack-passed arguments for indirect trampolines selftests/bpf: Test stack-passed struct_ops arena arguments

 Documentation/bpf/kfuncs.rst                  |  39 +++
 arch/x86/net/bpf_jit_comp.c                   | 122 ++++++++-
 include/linux/bpf.h                           |  15 ++
 include/linux/bpf_verifier.h                  |  14 +-
 include/linux/filter.h                        |   1 +
 kernel/bpf/bpf_struct_ops.c                   |  56 +++--
 kernel/bpf/btf.c                              |  28 ++-
 kernel/bpf/check_btf.c                        |  14 +-
 kernel/bpf/core.c                             |   5 +
 kernel/bpf/trampoline.c                       |  37 +++
 kernel/bpf/verifier.c                         | 125 ++++++++--
 .../bpf/prog_tests/test_struct_ops_arena.c    | 128 ++++++++++
 .../selftests/bpf/prog_tests/verifier.c       |   6 +
 .../testing/selftests/bpf/progs/arena_kfunc.c | 234 ++++++++++++++++++
 .../selftests/bpf/progs/arena_kfunc_jit.c     |  98 ++++++++
 .../selftests/bpf/progs/struct_ops_arena.c    | 115 +++++++++
 .../bpf/progs/struct_ops_arena_attach.c       |  25 ++
 .../bpf/progs/struct_ops_arena_fail.c         |  20 ++
 .../selftests/bpf/test_kmods/bpf_testmod.c    |  82 ++++++
 .../selftests/bpf/test_kmods/bpf_testmod.h    |   6 +
 .../bpf/test_kmods/bpf_testmod_kfunc.h        |  12 +
 21 files changed, 1123 insertions(+), 59 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c
 create mode 100644 tools/testing/selftests/bpf/progs/arena_kfunc.c
 create mode 100644 tools/testing/selftests/bpf/progs/arena_kfunc_jit.c
 create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena.c
 create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena_attach.c
 create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_arena_fail.c

base-commit: 51476f6a06ef55cecf785ae1622c638fa8cfb846

Signature · 1 line
2.53.0-Meta