Skip to content

Commit 44df171

Browse files
yonghong-songAlexei Starovoitov
authored and
Alexei Starovoitov
committed
selftests/bpf: Workaround a verifier issue for test exhandler
The llvm patch [1] enabled opaque pointer which caused selftest 'exhandler' failure. ... ; work = task->task_works; 7: (79) r1 = *(u64 *)(r6 +2120) ; R1_w=ptr_callback_head(off=0,imm=0) R6_w=ptr_task_struct(off=0,imm=0) ; func = work->func; 8: (79) r2 = *(u64 *)(r1 +8) ; R1_w=ptr_callback_head(off=0,imm=0) R2_w=scalar() ; if (!work && !func) 9: (4f) r1 |= r2 math between ptr_ pointer and register with unbounded min value is not allowed below is insn 10 and 11 10: (55) if r1 != 0 goto +5 11: (18) r1 = 0 ll ... In llvm, the code generation of 'r1 |= r2' happened in codegen selectiondag phase due to difference of opaque pointer vs. non-opaque pointer. Without [1], the related code looks like: r2 = *(u64 *)(r6 + 2120) r1 = *(u64 *)(r2 + 8) if r2 != 0 goto +6 <LBB0_4> if r1 != 0 goto +5 <LBB0_4> r1 = 0 ll ... I haven't found a good way in llvm to fix this issue. So let us workaround the problem first so bpf CI won't be blocked. [1] https://reviews.llvm.org/D123300 Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 8c89b5d commit 44df171

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

tools/testing/selftests/bpf/progs/exhandler_kern.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <bpf/bpf_tracing.h>
88
#include <bpf/bpf_core_read.h>
99

10+
#define barrier_var(var) asm volatile("" : "=r"(var) : "0"(var))
11+
1012
char _license[] SEC("license") = "GPL";
1113

1214
unsigned int exception_triggered;
@@ -37,7 +39,16 @@ int BPF_PROG(trace_task_newtask, struct task_struct *task, u64 clone_flags)
3739
*/
3840
work = task->task_works;
3941
func = work->func;
40-
if (!work && !func)
41-
exception_triggered++;
42+
/* Currently verifier will fail for `btf_ptr |= btf_ptr` * instruction.
43+
* To workaround the issue, use barrier_var() and rewrite as below to
44+
* prevent compiler from generating verifier-unfriendly code.
45+
*/
46+
barrier_var(work);
47+
if (work)
48+
return 0;
49+
barrier_var(func);
50+
if (func)
51+
return 0;
52+
exception_triggered++;
4253
return 0;
4354
}

0 commit comments

Comments
 (0)