summary refs log tree commit diff
path: root/tools/testing/selftests/bpf/progs/loop1.c
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2019-06-19 02:22:53 +0200
committerDaniel Borkmann <daniel@iogearbox.net>2019-06-19 02:22:53 +0200
commit94079b64255fe40b9b53fd2e4081f68b9b14f54a (patch)
tree2901e802c5161bb29dc5882fa14043f46de96cd0 /tools/testing/selftests/bpf/progs/loop1.c
parenta324aae32fa9bfdd03e89078e20ebcbd7737fda5 (diff)
parentb5dc0163d8fd78e64a7e21f309cf932fda34353e (diff)
downloadlinux-94079b64255fe40b9b53fd2e4081f68b9b14f54a.tar.gz
Merge branch 'bpf-bounded-loops'
Alexei Starovoitov says:

====================
v2->v3: fixed issues in backtracking pointed out by Andrii.
The next step is to add a lot more tests for backtracking.

v1->v2: addressed Andrii's feedback.

this patch set introduces verifier support for bounded loops and
adds several other improvements.
Ideally they would be introduced one at a time,
but to support bounded loop the verifier needs to 'step back'
in the patch 1. That patch introduces tracking of spill/fill
of constants through the stack. Though it's a useful feature
it hurts cilium tests.
Patch 3 introduces another feature by extending is_branch_taken
logic to 'if rX op rY' conditions. This feature is also
necessary to support bounded loops.
Then patch 4 adds support for the loops while adding
key heuristics with jmp_processed.
Introduction of parentage chain of verifier states in patch 4
allows patch 9 to add backtracking of precise scalar registers
which finally resolves degradation from patch 1.

The end result is much faster verifier for existing programs
and new support for loops.
See patch 8 for many kinds of loops that are now validated.
Patch 9 is the most tricky one and could be rewritten with
a different algorithm in the future.
====================

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/loop1.c')
-rw-r--r--tools/testing/selftests/bpf/progs/loop1.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/loop1.c b/tools/testing/selftests/bpf/progs/loop1.c
new file mode 100644
index 000000000000..dea395af9ea9
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/loop1.c
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2019 Facebook
+#include <linux/sched.h>
+#include <linux/ptrace.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+#include <linux/bpf.h>
+#include "bpf_helpers.h"
+
+char _license[] SEC("license") = "GPL";
+
+SEC("raw_tracepoint/kfree_skb")
+int nested_loops(volatile struct pt_regs* ctx)
+{
+	int i, j, sum = 0, m;
+
+	for (j = 0; j < 300; j++)
+		for (i = 0; i < j; i++) {
+			if (j & 1)
+				m = ctx->rax;
+			else
+				m = j;
+			sum += i * m;
+		}
+
+	return sum;
+}