selftests/bpf: Fix tests for llvm23 true signature
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
- v2 Latest2 patches 3 repliesApplied 2/2
- v13 patches 5 repliesSuperseded
Changes in v2 from the cover letter
- v1: https://lore.kernel.org/bpf/[email protected]/
- Do not use bpf array map or bpf global var. Use __sink() instead.
Patches in v2 All 2 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | selftests/bpf: Keep int return type for tailcall subprogstools/ tools/ tools/ +3 more | +57 | 3 replies | Applied |
| 2/2 | selftests/bpf: Adjust fexit_bpf2bpf ctx layout for llvm23 true signaturetools/ | +11 | 0 replies | Applied |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.
Cover letter [PATCH bpf-next v2 0/2] selftests/bpf: Fix tests for llvm23 true signature
LLVM23 ([1]) records the 'true' function signature in BTF, i.e. the signature inferred after optimization rather than the one written in C. This caused two kinds of selftest failures (see below).
Case 1: keep int return type for tailcall subprogs
The verifier requires any subprog that issues a bpf_tail_call to return an 'int' (see check_btf_func() in kernel/bpf/check_btf.c, which rejects it with "tail_call is only allowed in functions that return 'int'").
Several tailcall subprogs do 'return 0' (or another constant) whose result no caller uses. With llvm23 the compiler folds the constant and, since the return value is dead, optimizes the subprog to effectively return 'void' and records 'void' in BTF, so the program fails to load.
Use barrier_var() and __sink() to prevent returned value from being optimized.
Case 2: adjust tracing prog ctx layout for the true signature
test_pkt_access_subprog2() has an unused argument that llvm optimizes away. Before llvm23 the BTF signature did not match the optimized assembly, so the verifier fell back to MAX_BPF_FUNC_REG_ARGS (5) u64 arguments and the fexit return value sat after args[5]. With llvm23 the true signature has a single argument, so the return value moves to the slot after args[1]. Select the matching ctx struct based on __clang_major__ so the test works with both old and new llvm.
[1] https://github.com/llvm/llvm-project/pull/198426
Changelogs:
v1 -> v2:
- v1: https://lore.kernel.org/bpf/[email protected]/
- Do not use bpf array map or bpf global var. Use __sink() instead.
Yonghong Song (2):
selftests/bpf: Keep int return type for tailcall subprogs selftests/bpf: Adjust fexit_bpf2bpf ctx layout for llvm23 true
signature
.../selftests/bpf/progs/fexit_bpf2bpf.c | 13 ++++++++-- .../selftests/bpf/progs/tailcall_bpf2bpf2.c | 5 +++- .../bpf/progs/tailcall_bpf2bpf_hierarchy1.c | 13 ++++++---- .../bpf/progs/tailcall_bpf2bpf_hierarchy2.c | 24 +++++++++++++------ .../bpf/progs/tailcall_bpf2bpf_hierarchy3.c | 13 +++++++--- .../progs/tailcall_bpf2bpf_hierarchy_fentry.c | 13 +++++++--- .../selftests/bpf/progs/verifier_sock.c | 9 +++++-- 7 files changed, 68 insertions(+), 22 deletions(-)
Signature · 1 line
2.53.0-Meta