Skip to content

Commit 8c30396

Browse files
author
Alexei Starovoitov
committed
selftests/bpf: add loop test 5
Add a test with multiple exit conditions. It's not an infinite loop only when the verifier can properly track all math on variable 'i' through all possible ways of executing this loop. barrier()s are needed to disable llvm optimization that combines multiple branches into fewer branches. Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Yonghong Song <[email protected]>
1 parent a78d0db commit 8c30396

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void test_bpf_verif_scale(void)
7272
{ "loop1.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
7373
{ "loop2.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
7474
{ "loop4.o", BPF_PROG_TYPE_SCHED_CLS },
75+
{ "loop5.o", BPF_PROG_TYPE_SCHED_CLS },
7576

7677
/* partial unroll. 19k insn in a loop.
7778
* Total program size 20.8k insn.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (c) 2019 Facebook
3+
#include <linux/bpf.h>
4+
#include "bpf_helpers.h"
5+
#define barrier() __asm__ __volatile__("": : :"memory")
6+
7+
char _license[] SEC("license") = "GPL";
8+
9+
SEC("socket")
10+
int while_true(volatile struct __sk_buff* skb)
11+
{
12+
int i = 0;
13+
14+
while (1) {
15+
if (skb->len)
16+
i += 3;
17+
else
18+
i += 7;
19+
if (i == 9)
20+
break;
21+
barrier();
22+
if (i == 10)
23+
break;
24+
barrier();
25+
if (i == 13)
26+
break;
27+
barrier();
28+
if (i == 14)
29+
break;
30+
}
31+
return i;
32+
}

0 commit comments

Comments
 (0)