Skip to content

Minimize annotations for arena programs

Emil Tsalapatis bpf sashiko-reviews 3 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. v3 Latest6 patches 1 replyApplied 6/6
  2. v25 patches 11 repliesSuperseded
  3. v15 patches 0 repliesSuperseded

Patches in v3 All 6 applied

#Subject and filesSizeRepliesApplied
1/6selftests/bpf: libarena: Add "arena" BTF type tag to __arena qualifiertools/testing/selftests/bpf/libarena/include/bpf_arena_common.h+1 -10 repliesApplied
2/6verifier: parse BTF type tags for function argumentskernel/bpf/btf.c+85 -351 replyApplied
3/6bpf: Allow subprogs to return arena pointerskernel/bpf/btf.c kernel/bpf/verifier.c+54 -160 repliesApplied
4/6selftests/bpf: Remove __arg_arena from the codebasetools/testing/selftests/bpf/bpf_arena_htab.h tools/testing/selftests/bpf/bpf_arena_strsearch.h tools/testing/selftests/bpf/libarena/include/bpf_arena_common.h +10 more+84 -1010 repliesApplied
5/6selftests/bpf: libarena: Directly return arena pointers from functionstools/testing/selftests/bpf/libarena/include/libarena/buddy.h tools/testing/selftests/bpf/libarena/include/libarena/common.h tools/testing/selftests/bpf/libarena/src/buddy.bpf.c +1 more+14 -160 repliesApplied
6/6selftests/bpf: Add tests for the new type-tag based __arena identifiertools/testing/selftests/bpf/progs/verifier_arena.c+67 -00 repliesApplied

Reviews trailers per patch

4 of 6 patches have a Reviewed-by or Acked-by.

PatchEduard Zingerman
1/6
2/6A-b
3/6A-b
4/6A-b
5/6A-b
6/6

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

Read the v3 thread

Cover letter [PATCH bpf-next v3 0/6] Minimize annotations for arena programs

BPF programs must currently include code to address two limitations of function signatures that include arena types. First, arena arguments must be annotated with __arg_arena in the function signature in addition to __arena. Second, it is currently not allowed to return an arena pointer from a subprog, even though it is safe to do so. These limitations require extra annotations and typecasts respectively, and have proven sources of confusion to programmers.

The patchset improves arena-related function signatures in two ways. First, it removes the need for __arg_arena in function signatures. Second, it allows subprogs to directly return arena pointers to their caller.

To do this we add a new type tag to the existing __arena annotation. The annotation is currently an alias for __attribute__((address_space(1))), which is not discoverable from BTF alone and so cannot be used to determine whether a pointer variable is an arena pointer during verification. With the new type tag, we can determine whether either the arguments and or the return value of a function belong in an arena.

We test the new code by modifying libarena to take advantage of these relaxed limitations.

CHANGELOG
=========

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

- Added Acks by Eduard
- Complete the __arg_arena removal by removing them from htab (Alexei)
- Add a test in verifier_arena_globals1.c to confirm the new __arena attribute works as expected in function argument and return types
- Reject type tags on non-pointer types, currently only possible in handcrafted BTF (Eduard)
- Undo inaccurate change on verifier comment (AI)
- Fix error return value for invalid BTF return types during BTF parsing (Eduard)

v1 -> v2 (lore.kernel.org/bpf/[email protected]/)

- Rebased to fix conflict
- Removed the typedef foo * foo_t typedefs. Those were necessary to avoid annotating each instance of the type with __arena. The new version of the patch instead removes typedefs and uses __arena everywhere directly (see patch 4/5 for more details).
- Reorganized the patchset to frontload all kernel-side changes and place the libarena changes at the end.

Emil Tsalapatis (6):
selftests/bpf: libarena: Add "arena" BTF type tag to __arena qualifier
verifier: parse BTF type tags for function arguments
bpf: Allow subprogs to return arena pointers selftests/bpf: Remove __arg_arena from the codebase selftests/bpf: libarena: Directly return arena pointers from functions selftests/bpf: Add tests for the new type-tag based __arena identifier

 kernel/bpf/btf.c                              | 178 +++++++++++++-----
 kernel/bpf/verifier.c                         |   4 +
 tools/testing/selftests/bpf/bpf_arena_htab.h  |  11 +-
 .../selftests/bpf/bpf_arena_strsearch.h       |   4 +-
 .../bpf/libarena/include/bpf_arena_common.h   |   5 +-
 .../libarena/include/bpf_arena_spin_lock.h    |   6 +-
 .../bpf/libarena/include/libarena/asan.h      |   6 +-
 .../bpf/libarena/include/libarena/buddy.h     |  23 +--
 .../bpf/libarena/include/libarena/common.h    |   3 +-
 .../libarena/selftests/st_asan_buddy.bpf.c    |   4 +-
 .../bpf/libarena/selftests/st_asan_common.h   |   2 +-
 .../bpf/libarena/selftests/st_buddy.bpf.c     |   2 +-
 .../selftests/bpf/libarena/src/asan.bpf.c     |  38 ++--
 .../selftests/bpf/libarena/src/buddy.bpf.c    |  96 +++++-----
 .../selftests/bpf/libarena/src/common.bpf.c   |  10 +-
 .../selftests/bpf/progs/arena_spin_lock.c     |   1 +
 .../selftests/bpf/progs/verifier_arena.c      |  67 +++++++
 17 files changed, 298 insertions(+), 162 deletions(-)
Signature · 1 line
2.54.0