selftests/bpf: Convert exceptions_assert.c to bpf_cmp
authorAlexei Starovoitov <ast@kernel.org>
Tue, 26 Dec 2023 19:11:45 +0000 (11:11 -0800)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 3 Jan 2024 19:08:23 +0000 (11:08 -0800)
commit624cd2a17672f4596fee97a5558bc990778bbcf9
tree8b24caf8e239bea1bbc4313d0f4a9aaed3c832e0
parenta8b242d77bd72556b7a9d8be779f7d27b95ba73c
selftests/bpf: Convert exceptions_assert.c to bpf_cmp

Convert exceptions_assert.c to bpf_cmp_unlikely() macro.

Since

bpf_assert(bpf_cmp_unlikely(var, ==, 100));
other code;

will generate assembly code:

  if r1 == 100 goto L2;
  r0 = 0
  call bpf_throw
L1:
  other code;
  ...

L2: goto L1;

LLVM generates redundant basic block with extra goto. LLVM will be fixed eventually.
Right now it's less efficient than __bpf_assert(var, ==, 100) macro that produces:
  if r1 == 100 goto L1;
  r0 = 0
  call bpf_throw
L1:
  other code;

But extra goto doesn't hurt the verification process.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/bpf/20231226191148.48536-4-alexei.starovoitov@gmail.com
tools/testing/selftests/bpf/progs/exceptions_assert.c