bpf: Follow up by-value struct and __int128 argument support
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
- v4 Latest9 patches 0 repliesApplied 9/9
- v311 patches 8 repliesSuperseded
- v211 patches 3 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 5 patches | 7 replies | Superseded |
Changes in v4 from the cover letter
- v3: https://lore.kernel.org/bpf/[email protected]/
- Drop v3 patches 10 and 11 (16-byte aligned kfunc stack argument
on x86-64); no kfunc in the tree needs it.
- Drop byte-order based ctx indexing for the __int128 struct argument; tests on BPF functions use BPF_PROG2(). (patches 6, 7
and 9)
- Run the test on BPF functions on s390x too. The functions taking stack arguments are built only for x86 and arm64. (patch 7)
- Say that patch 4 also fixes the s390 trampoline on a BPF function taking a 16-byte argument. (patch 4)
Patches in v4 All 9 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/9 | bpf, x86: Pass a trampoline's stack arguments by the calling conventionarch/ | +15 | 0 replies | Applied |
| 2/9 | selftests/bpf: Test trampoline stack args in a program that can tail calltools/ tools/ tools/ | +141 | 0 replies | Applied |
| 3/9 | selftests/bpf: Test by-value __int128 kfunc arguments at an odd slottools/ tools/ tools/ | +110 | 0 replies | Applied |
| 4/9 | bpf: Describe a BPF function to its trampoline as one u64 per slotkernel/ | +31 | 0 replies | Applied |
| 5/9 | bpf, x86: Place trampoline arguments by the x86-64 calling conventionarch/ | +96 | 0 replies | Applied |
| 6/9 | selftests/bpf: Test trampoline args around a 16-byte aligned stack argtools/ tools/ tools/ | +107 | 0 replies | Applied |
| 7/9 | selftests/bpf: Test trampoline args of a BPF function at an odd slottools/ tools/ tools/ | +195 | 0 replies | Applied |
| 8/9 | bpf: Refuse a trampoline on an unreliable static function with stack argskernel/ | +34 | 0 replies | Applied |
| 9/9 | selftests/bpf: Test trampolines on more BPF functions with stack argstools/ tools/ tools/ | +120 | 0 replies | Applied |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.
Cover letter [PATCH bpf-next v4 0/9] bpf: Follow up by-value struct and __int128 argument support
This is a follow-up to the series "bpf: Support by-value struct and __int128 arguments" [1], which placed kfunc arguments by the kernel calling convention in the x86-64 and arm64 JITs, and made the arm64 trampoline place an argument aligned to 16 bytes: an __int128, or an aggregate holding one. This series covers what was left, and a few problems found on the way:
- The x86-64 trampoline. x86-64 starts such an argument passed on the stack at a 16-byte aligned slot, which can leave an empty slot before it, but the trampoline copied the stack arguments as if there were none. A bpf program attached to such a function read the wrong values from the empty slot on, and with fexit, where the trampoline calls the traced function itself, that function got its stack arguments one slot off as well.
- A trampoline on a BPF function. BPF code calls one with argument slot N where the kernel convention passes its Nth u64 argument, but the trampolines placed the arguments by their types: arm64 left a register empty before a 16-byte argument, x86-64 would not split one between r9 and the stack, and s390 took one as a pointer to it. Such a function is now described to its trampoline as one u64 per slot.
- The x86-64 trampoline on a function of a program that can tail call pushed the tail call counter pointer between the stack arguments and the return address.
- A static function whose BTF is unreliable could still take stack arguments, while its trampoline saved and restored only five registers. Attaching to such a function is now refused.
- Tests with an __int128 at an odd slot, where arm64 leaves a register or a stack slot empty. On arm64 such a kfunc gets BTF only with the pahole patch [2], now in pahole master after v1.32, so these tests were not part of [1].
Patch 1 keeps the x86-64 trampoline's tail call counter pointer clear of the stack arguments, and patch 2 tests it. Patch 3 adds the odd-slot kfunc tests. Patch 4 describes a BPF function to its trampoline as one u64 per slot, and patch 5 places the x86-64 trampoline arguments by the calling convention. Patches 6 and 7 test trampolines on kernel functions and on BPF functions with an argument after a 16-byte aligned one, the latter on s390x as well. Patch 8 refuses a trampoline on an unreliable static function with stack arguments, and patch 9 tests it, along with a BPF function whose 16-byte argument x86-64 splits between r9 and the stack.
[1] https://lore.kernel.org/bpf/[email protected]/
[2] https://lore.kernel.org/dwarves/[email protected]/
Changelogs:
v3 -> v4:
- v3: https://lore.kernel.org/bpf/[email protected]/
- Drop v3 patches 10 and 11 (16-byte aligned kfunc stack argument
on x86-64); no kfunc in the tree needs it.
- Drop byte-order based ctx indexing for the __int128 struct argument; tests on BPF functions use BPF_PROG2(). (patches 6, 7
and 9)
- Run the test on BPF functions on s390x too. The functions taking stack arguments are built only for x86 and arm64. (patch 7)
- Say that patch 4 also fixes the s390 trampoline on a BPF function taking a 16-byte argument. (patch 4)
v2 -> v3:
- v2: https://lore.kernel.org/bpf/[email protected]/
- Index the two halves of a struct holding an __int128 in ctx by the byte order, so the tracing tests also hold on a big-endian
kernel. (patches 6, 7 and 9)
- Say that only x86-64 BPF code splits a 16-byte argument between r9 and the stack; on arm64 nothing is split. (patches 4 and 9)
v1 -> v2:
- v1: https://lore.kernel.org/bpf/[email protected]/
- Replace the bpf_tgt_prog flag of v1 patch 2, which only bpf_jit_place_args() looked at, with a model of one u64 per argument slot for a BPF function, built in bpf_check_attach_target(). This also fixes the arm64 trampoline, which took a 16-byte argument split between x7 and the stack as wholly in registers, without any arch change. (patch 4)
- Refuse a trampoline on a static function whose BTF is unreliable but which takes stack arguments. (patches 8 and 9)
- New: keep the x86-64 trampoline's tail call counter pointer in a slot of its frame instead of pushing it between the stack
arguments and the return address. (patches 1 and 2)
- New: pass a kfunc's 16-byte aligned stack argument 16-byte aligned in the x86-64 JIT, with bpf_jit_stack_slots_to_align() and bpf_jit_plan_slot_moves() in kernel/bpf/core.c. (patches 10 and
11)
- Reword the x86-64 placement patch and the BPF function test for
the new model. (patches 5 and 7)
Yonghong Song (9):
bpf, x86: Pass a trampoline's stack arguments by the calling
convention
selftests/bpf: Test trampoline stack args in a program that can tail
call
selftests/bpf: Test by-value __int128 kfunc arguments at an odd slot
bpf: Describe a BPF function to its trampoline as one u64 per slot bpf, x86: Place trampoline arguments by the x86-64 calling convention selftests/bpf: Test trampoline args around a 16-byte aligned stack arg selftests/bpf: Test trampoline args of a BPF function at an odd slot
bpf: Refuse a trampoline on an unreliable static function with stack
args
selftests/bpf: Test trampolines on more BPF functions with stack args
arch/x86/net/bpf_jit_comp.c | 211 +++++++++-------- kernel/bpf/verifier.c | 66 +++++- .../selftests/bpf/prog_tests/tracing_struct.c | 217 +++++++++++++++++- .../selftests/bpf/progs/aggregate_arg_kfunc.c | 71 ++++++ .../progs/tracing_stack_arg_tailcall_tgt.c | 59 +++++ .../progs/tracing_stack_arg_tailcall_tracer.c | 23 ++ .../bpf/progs/tracing_struct_int128.c | 45 ++++ .../bpf/progs/tracing_struct_int128_tgt.c | 101 ++++++++ .../bpf/progs/tracing_struct_int128_tracer.c | 77 +++++++ .../selftests/bpf/test_kmods/bpf_testmod.c | 69 ++++++ .../bpf/test_kmods/bpf_testmod_kfunc.h | 13 ++ 11 files changed, 848 insertions(+), 104 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/tracing_stack_arg_tailcall_tgt.c create mode 100644 tools/testing/selftests/bpf/progs/tracing_stack_arg_tailcall_tracer.c create mode 100644 tools/testing/selftests/bpf/progs/tracing_struct_int128_tgt.c create mode 100644 tools/testing/selftests/bpf/progs/tracing_struct_int128_tracer.c
Signature · 1 line
2.53.0-Meta