selftests/bpf: more loop tests
Subsystems (5)
Alexei Starovoitov
maintainerv2 cover selftests/bpf: more loop tests
Add two bounded loop tests.
v1-v2: addressed feedback from Yonghong.
Alexei Starovoitov (2):
selftests/bpf: add loop test 4
selftests/bpf: add loop test 5
.../bpf/prog_tests/bpf_verif_scale.c | 2 ++ tools/testing/selftests/bpf/progs/loop4.c | 18 +++++++++++ tools/testing/selftests/bpf/progs/loop5.c | 32 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/loop4.c create mode 100644 tools/testing/selftests/bpf/progs/loop5.c
Signature · 1 line
2.20.0
Alexei Starovoitov
maintainerPATCH v2 1/2 selftests/bpf: add loop test 4
Add a test that returns a 'random' number between [0, 2^20) If state pruning is not working correctly for loop body the number of processed insns will be 2^20 * num_of_insns_in_loop_body and the program will be rejected.
--- .../selftests/bpf/prog_tests/bpf_verif_scale.c | 1 + tools/testing/selftests/bpf/progs/loop4.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/loop4.c
tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c +1 -0
@@ -71,6 +71,7 @@ void test_bpf_verif_scale(void) { "loop1.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, { "loop2.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, + { "loop4.o", BPF_PROG_TYPE_SCHED_CLS },/* partial unroll. 19k insn in a loop. * Total program size 20.8k insn.
tools/testing/selftests/bpf/progs/loop4.c new file +18 -0
@@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2019 Facebook +#include <linux/bpf.h> +#include "bpf_helpers.h" + +char _license[] SEC("license") = "GPL"; + +SEC("socket") +int combinations (volatile struct __sk_buff * skb) +{ +int ret =0 , i; + +#pragma nounroll +for (i =0 ; i <20 ; i++) +if (skb->len) + ret |=1 << i; +return ret; +}
Signature · 1 line
2.20.0
Alexei Starovoitov
maintainerPATCH v2 2/2 selftests/bpf: add loop test 5
In reply to Alexei StarovoitovAdd 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.
--- .../bpf/prog_tests/bpf_verif_scale.c | 1 + tools/testing/selftests/bpf/progs/loop5.c | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/loop5.c
tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c +1 -0
@@ -72,6 +72,7 @@ void test_bpf_verif_scale(void) { "loop1.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, { "loop2.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, { "loop4.o", BPF_PROG_TYPE_SCHED_CLS }, + { "loop5.o", BPF_PROG_TYPE_SCHED_CLS },/* partial unroll. 19k insn in a loop. * Total program size 20.8k insn.
tools/testing/selftests/bpf/progs/loop5.c new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2019 Facebook +#include <linux/bpf.h> +#include "bpf_helpers.h" +#define barrier () __asm__ __volatile__("": : :"memory") + +char _license[] SEC("license") = "GPL"; + +SEC("socket") +int while_true (volatile struct __sk_buff * skb) +{ +int i =0 ; + +while (1 ) { +if (skb->len) + i +=3 ; +else + i +=7 ; +if (i ==9 ) +break ; +barrier (); +if (i ==10 ) +break ; +barrier (); +if (i ==13 ) +break ; +barrier (); +if (i ==14 ) +break ; + } +return i; +}
Signature · 1 line
2.20.0
Quoted 7 lines · Alexei Starovoitov
Add two bounded loop tests.
v1-v2: addressed feedback from Yonghong.
Alexei Starovoitov (2):
selftests/bpf: add loop test 4
selftests/bpf: add loop test 5
Looks good to me. Ack for the whole series.
Quoted 8 lines
.../bpf/prog_tests/bpf_verif_scale.c | 2 ++ tools/testing/selftests/bpf/progs/loop4.c | 18 +++++++++++ tools/testing/selftests/bpf/progs/loop5.c | 32 +++++++++++++++++++ 3 files changed, 52 insertions(+)create mode 100644
tools/testing/selftests/bpf/progs/loop4.ccreate mode 100644tools/testing/selftests/bpf/progs/loop5.c
Alexei Starovoitov
AppliedQuoted 6 lines · Yonghong Song
Quoted 2 lines · Alexei Starovoitov
Add two bounded loop tests.
Quoted 8 lines
Quoted 5 lines
v1-v2: addressed feedback from Yonghong.
Alexei Starovoitov (2):
selftests/bpf: add loop test 4
selftests/bpf: add loop test 5Looks good to me. Ack for the whole series.
Acked-by Yonghong Song <[email protected]>
Applied. Thanks