Skip to content

__jited test tag to check disassembly after jit

Eduard Zingerman bpf 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 Latest8 patches 2 repliesApplied 9/9
  2. v24 patches 4 repliesSuperseded
  3. v14 patches 21 repliesSuperseded

Changes in v3 from the cover letter

- changed macro name from __jit_x86 to __jited with __arch_* to specify disassembly arch (Yonghong);
- __jited matches disassembly lines consequently with "..." allowing to skip some number of lines (Andrii);
- __xlated matches disassembly lines consequently, same as __jited;
- "{{...}}" regex brackets instead of __regex macro;
- bug fixes for old commits.

Patches in v3 All 9 applied

#Subject and filesSizeRepliesApplied
1/8selftests/bpf: less spam in the log for message matchingtools/testing/selftests/bpf/test_loader.c+2 -10 repliesApplied
2/8selftests/bpf: correctly move 'log' upon successful matchtools/testing/selftests/bpf/test_loader.c+1 -10 repliesApplied
3/8selftests/bpf: fix to avoid __msg tag de-duplication by clangtools/testing/selftests/bpf/progs/bpf_misc.h tools/testing/selftests/bpf/progs/verifier_spill_fill.c tools/testing/selftests/bpf/test_loader.c+48 -220 repliesApplied
4/8selftests/bpf: replace __regex macro with "{{...}}" patternstools/testing/selftests/bpf/progs/bpf_misc.h tools/testing/selftests/bpf/progs/dynptr_fail.c tools/testing/selftests/bpf/progs/rbtree_fail.c +2 more+115 -700 repliesApplied
5/8selftests/bpf: utility function to get program disassembly after jittools/testing/selftests/bpf/.gitignore tools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/jit_disasm_helpers.c +1 more+291 -22 repliesApplied
6/8selftests/bpf: __jited test tag to check disassembly after jittools/testing/selftests/bpf/progs/bpf_misc.h tools/testing/selftests/bpf/test_loader.c+161 -230 repliesApplied
6/8selftests/bpf: __jited_x86 test tag to check x86 assembly after jittools/testing/selftests/bpf/progs/bpf_misc.h tools/testing/selftests/bpf/test_loader.c+161 -230 repliesApplied
7/8selftests/bpf: validate jit behaviour for tail callstools/testing/selftests/bpf/prog_tests/verifier.c tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c+107 -00 repliesApplied
8/8selftests/bpf: validate __xlated same way as __jitedtools/testing/selftests/bpf/progs/verifier_nocsr.c tools/testing/selftests/bpf/test_loader.c+57 -40 repliesApplied

Reviews trailers per patch

1 of 9 patches has a Reviewed-by or Acked-by.

PatchYonghong Song
1/8
2/8
3/8
4/8
5/8A-b
6/8
6/8
7/8
8/8

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/8] __jited test tag to check disassembly after jit

Some of the logic in the BPF jits might be non-trivial. It might be useful to allow testing this logic by comparing generated native code with expected code template. This patch set adds a macro __jited() that could be used for test_loader based tests in a following manner:

    SEC("tp")
    __arch_x86_64
    __jited("   endbr64")
    __jited("   nopl    (%rax,%rax)")
    __jited("   xorq    %rax, %rax")
    ...
    __naked void some_test(void) { ... }

Also add a test for jit code generated for tail calls handling to demonstrate the feature.

The feature uses LLVM libraries to do the disassembly.
At selftests compilation time Makefile detects if these libraries are available. When libraries are not available tests using __jit_x86() are skipped.
Current CI environment does not include llvm development libraries, but changes to add these are trivial.

This was previously discussed here:
https://lore.kernel.org/bpf/[email protected]/

Patch-set includes a few auxiliary steps:
- patches #2 and #3 fix a few bugs in test_loader behaviour;
- patch #4 replaces __regex macro with ability to specify regular expressions in __msg and __xlated using "{{" "}}" escapes;
- patch #8 updates __xlated to match disassembly lines consequently, same way as __jited does.

Changes v2->v3:
- changed macro name from __jit_x86 to __jited with __arch_* to specify disassembly arch (Yonghong);
- __jited matches disassembly lines consequently with "..." allowing to skip some number of lines (Andrii);
- __xlated matches disassembly lines consequently, same as __jited;
- "{{...}}" regex brackets instead of __regex macro;
- bug fixes for old commits.

Changes v1->v2:
- stylistic changes suggested by Yonghong;
- fix for -Wformat-truncation related warning when compiled with llvm15 (Yonghong).

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

Eduard Zingerman (8):
selftests/bpf: less spam in the log for message matching selftests/bpf: correctly move 'log' upon successful match selftests/bpf: fix to avoid __msg tag de-duplication by clang selftests/bpf: replace __regex macro with "{{...}}" patterns selftests/bpf: utility function to get program disassembly after jit selftests/bpf: __jited test tag to check disassembly after jit selftests/bpf: validate jit behaviour for tail calls selftests/bpf: validate __xlated same way as __jited

 tools/testing/selftests/bpf/.gitignore        |   1 +
 tools/testing/selftests/bpf/Makefile          |  48 ++-
 .../selftests/bpf/jit_disasm_helpers.c        | 234 ++++++++++++
 .../selftests/bpf/jit_disasm_helpers.h        |  10 +
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 tools/testing/selftests/bpf/progs/bpf_misc.h  |  55 ++-
 .../testing/selftests/bpf/progs/dynptr_fail.c |   6 +-
 .../testing/selftests/bpf/progs/rbtree_fail.c |   2 +-
 .../bpf/progs/refcounted_kptr_fail.c          |   4 +-
 .../selftests/bpf/progs/verifier_nocsr.c      |  53 ++-
 .../selftests/bpf/progs/verifier_spill_fill.c |   8 +-
 .../bpf/progs/verifier_tailcall_jit.c         | 105 ++++++
 tools/testing/selftests/bpf/test_loader.c     | 357 +++++++++++++-----
 13 files changed, 772 insertions(+), 113 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/jit_disasm_helpers.c
 create mode 100644 tools/testing/selftests/bpf/jit_disasm_helpers.h
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_tailcall_jit.c
Signature · 1 line
2.45.2