Skip to content

bpf, arm64: __arena kfunc and struct_ops arguments

Puranjay Mohan bpf 2 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. v2 Latest7 patches 1 replyApplied 7/7
  2. v17 patches 16 repliesSuperseded

Changes in v2 from the cover letter

- patch 2: fix the decode masks for the new extended-register predicates, 0x7F200000 -> 0x7FE00000. opt in bits 23:22 is part of the opcode here rather than a shift type, and any value other than 00 is unallocated (Xu Kuohai). Also noted in the commit message. No functional change: the masks only feed aarch64_insn_is_*_ext(), which has no in-tree callers, while the encoder uses aarch64_insn_get_*_ext_value().
- patch 4: comment why the conversion in the stack-argument loop is not guarded by for_call_origin (Xu Kuohai).
- collect Reviewed-by/Acked-by from Xu Kuohai.
- rebase onto current bpf-next.

Patches in v2 All 7 applied

#Subject and filesSizeRepliesApplied
1/7bpf, arm64: Fix stack-passed arguments for indirect trampolinesarch/arm64/net/bpf_jit_comp.c+13 -60 repliesApplied
2/7arm64: insn: Add encoder for ADD/SUB (extended register)arch/arm64/include/asm/insn.h arch/arm64/lib/insn.c+83 -00 repliesApplied
3/7bpf, arm64: JIT __arena kfunc argument rebasingarch/arm64/net/bpf_jit.h arch/arm64/net/bpf_jit_comp.c+53 -00 repliesApplied
4/7bpf, arm64: Convert struct_ops arena arguments in the trampolineDocumentation/bpf/kfuncs.rst arch/arm64/net/bpf_jit_comp.c+80 -181 replyApplied
5/7selftests/bpf: Add arm64 JIT-sequence tests for __arena kfunc argumentstools/testing/selftests/bpf/progs/arena_kfunc_jit.c+20 -00 repliesApplied
6/7selftests/bpf: Enable __arena argument tests on arm64tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c tools/testing/selftests/bpf/progs/arena_kfunc.c+14 -50 repliesApplied
7/7selftests/bpf: Test a multi-slot argument before a struct_ops arena argumenttools/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+48 -00 repliesApplied

Reviews trailers per patch

All 7 patches have a Reviewed-by or Acked-by.

PatchXu Kuohai
1/7R-b
2/7R-b
3/7R-b
4/7R-b
5/7A-b
6/7A-b
7/7A-b

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

Read the v2 thread

Cover letter [PATCH bpf-next v2 0/7] bpf, arm64: __arena kfunc and struct_ops arguments

The x86-64 JIT recently gained support for the __arena and __arena__nullable argument suffixes on kfuncs and struct_ops stubs. This adds the arm64 side and flips bpf_jit_supports_arena_args() on, so the verifier stops rejecting these programs on arm64.

Patch 1 is an independent fix. save_args() reads stack-passed arguments at FP + 32, which only holds when the trampoline is entered through the fentry call and two frame records are pushed. A struct_ops trampoline is entered via blr and pushes one frame fewer, so its stack arguments start at FP + 16 and every one of them was read two slots off. No struct_ops member passed arguments on the stack until the test added by commit 2d4de9a493a0, which is why this went unnoticed. It carries a Fixes tag and can be taken separately; note that the test covering it only runs on arm64 once the rest of this series lands.

Patch 2 adds an ADD/SUB (extended register) encoder to the insn library, so the JIT can zero-extend and add in one instruction.

Patches 3 and 4 are the JIT work. A kfunc argument is rebased onto the arena base at the call site:

add xN, x28, wN, uxtw

and a nullable one skips the add so NULL stays NULL:

        mov     wN, wN
        cbz     wN, 1f
        add     xN, x28, wN, uxtw

1:

A struct_ops callback converts in the other direction, in the trampoline while saving arguments into the BPF ctx, with the low half of the arena base kept in x11:

        sub     w10, wsrc, w11
        str     x10, [sp, #slot]

Patches 5 and 6 add arm64 JIT-sequence assertions and drop the x86-64 gating from the existing arena argument tests. Patch 7 is arch-neutral:
it adds a struct_ops member whose first argument is a 16-byte struct passed by value, so the arena pointer does not land at the ctx slot its argument index suggests. Nothing covered that before, and it is the case patch 4 has to get right.

Changelog:
V1: https://lore.kernel.org/bpf/[email protected]/
Changes in v2:
- patch 2: fix the decode masks for the new extended-register predicates, 0x7F200000 -> 0x7FE00000. opt in bits 23:22 is part of the opcode here rather than a shift type, and any value other than 00 is unallocated (Xu Kuohai). Also noted in the commit message. No functional change: the masks only feed aarch64_insn_is_*_ext(), which has no in-tree callers, while the encoder uses aarch64_insn_get_*_ext_value().
- patch 4: comment why the conversion in the stack-argument loop is not guarded by for_call_origin (Xu Kuohai).
- collect Reviewed-by/Acked-by from Xu Kuohai.
- rebase onto current bpf-next.

Puranjay Mohan (6):
bpf, arm64: Fix stack-passed arguments for indirect trampolines bpf, arm64: JIT __arena kfunc argument rebasing
bpf, arm64: Convert struct_ops arena arguments in the trampoline selftests/bpf: Add arm64 JIT-sequence tests for __arena kfunc
arguments
selftests/bpf: Enable __arena argument tests on arm64 selftests/bpf: Test a multi-slot argument before a struct_ops arena
argument

Tejun Heo (1):
arm64: insn: Add encoder for ADD/SUB (extended register)

 Documentation/bpf/kfuncs.rst                  |   6 +-
 arch/arm64/include/asm/insn.h                 |  23 +++
 arch/arm64/lib/insn.c                         |  60 +++++++
 arch/arm64/net/bpf_jit.h                      |  11 ++
 arch/arm64/net/bpf_jit_comp.c                 | 147 +++++++++++++++---
 .../bpf/prog_tests/test_struct_ops_arena.c    |  10 +-
 .../testing/selftests/bpf/progs/arena_kfunc.c |   9 ++
 .../selftests/bpf/progs/arena_kfunc_jit.c     |  20 +++
 .../selftests/bpf/progs/struct_ops_arena.c    |  24 +++
 .../selftests/bpf/test_kmods/bpf_testmod.c    |  15 ++
 .../selftests/bpf/test_kmods/bpf_testmod.h    |   8 +
 .../bpf/test_kmods/bpf_testmod_kfunc.h        |   1 +
 12 files changed, 308 insertions(+), 26 deletions(-)

base-commit: 806c1a185215382fab5a7fafc74e30070b2fb043

Signature · 1 line
2.53.0-Meta