aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/bpf/progs/profiler3.c
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2020-10-08 18:12:39 -0700
committerDaniel Borkmann <daniel@iogearbox.net>2020-10-09 22:03:06 +0200
commit03d4d13fab3fa75fbcf09bced5e3c8acf1622969 (patch)
treecb78a9cc26dad4f3c4a94292f44f85e3e5f49c4b /tools/testing/selftests/bpf/progs/profiler3.c
parentbpf: Track spill/fill of bounded scalars. (diff)
downloadwireguard-linux-03d4d13fab3fa75fbcf09bced5e3c8acf1622969.tar.xz
wireguard-linux-03d4d13fab3fa75fbcf09bced5e3c8acf1622969.zip
selftests/bpf: Add profiler test
The main purpose of the profiler test to check different llvm generation patterns to make sure the verifier can load these large programs. Note that profiler.inc.h test doesn't follow strict kernel coding style. The code was formatted in the kernel style, but variable declarations are kept as-is to preserve original llvm IR pattern. profiler1.c should pass with older and newer llvm profiler[23].c may fail on older llvm that don't have: https://reviews.llvm.org/D85570 because llvm may do speculative code motion optimization that will generate code like this: // r9 is a pointer to map_value // r7 is a scalar 17: bf 96 00 00 00 00 00 00 r6 = r9 18: 0f 76 00 00 00 00 00 00 r6 += r7 19: a5 07 01 00 01 01 00 00 if r7 < 257 goto +1 20: bf 96 00 00 00 00 00 00 r6 = r9 // r6 is used here The verifier will reject such code with the error: "math between map_value pointer and register with unbounded min value is not allowed" At insn 18 the r7 is indeed unbounded. The later insn 19 checks the bounds and the insn 20 undoes map_value addition. It is currently impossible for the verifier to understand such speculative pointer arithmetic. Hence llvm D85570 addresses it on the compiler side. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20201009011240.48506-4-alexei.starovoitov@gmail.com
Diffstat (limited to '')
-rw-r--r--tools/testing/selftests/bpf/progs/profiler3.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/profiler3.c b/tools/testing/selftests/bpf/progs/profiler3.c
new file mode 100644
index 000000000000..6249fc31ccb0
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/profiler3.c
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2020 Facebook */
+#define barrier_var(var) /**/
+#define UNROLL
+#define INLINE __noinline
+#include "profiler.inc.h"