From: Alexei Starovoitov <ast@xxxxxxxxxx> Add a sanity test for bpf_can_loop(). Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx> --- tools/lib/bpf/bpf_helpers.h | 1 + .../bpf/progs/verifier_iterating_callbacks.c | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h index 79eaa581be98..70270f07074e 100644 --- a/tools/lib/bpf/bpf_helpers.h +++ b/tools/lib/bpf/bpf_helpers.h @@ -307,6 +307,7 @@ struct bpf_iter_num; extern int bpf_iter_num_new(struct bpf_iter_num *it, int start, int end) __weak __ksym; extern int *bpf_iter_num_next(struct bpf_iter_num *it) __weak __ksym; extern void bpf_iter_num_destroy(struct bpf_iter_num *it) __weak __ksym; +extern long bpf_can_loop(void *ignored) __weak __ksym; #ifndef bpf_for_each /* bpf_for_each(iter_type, cur_elem, args...) provides generic construct for diff --git a/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c b/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c index 5905e036e0ea..3fc0e82ffc03 100644 --- a/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c +++ b/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c @@ -239,4 +239,51 @@ int bpf_loop_iter_limit_nested(void *unused) return 1000 * a + b + c; } +SEC("socket") +__success __retval(0xd495cdc0) +int can_loop1(const void *ctx) +{ + volatile int i; + int sum = 0; + + for (i = 0; i < 1000000 && bpf_can_loop(0); i++) + sum += i; + for (i = 0; i < 1000000 && bpf_can_loop(0); i++) + sum += i; + + return sum; +} + +SEC("socket") +__success __retval(999000000) +int can_loop2(const void *ctx) +{ + volatile int i, j; + int sum = 0; + + for (i = 0; i < 1000 && bpf_can_loop(0); i++) + for (j = 0; j < 1000 && bpf_can_loop(0); j++) + sum += i + j; + + return sum; +} + +static __noinline int loop(void) +{ + volatile int i; + int sum = 0; + + for (i = 0; i <= 1000 && bpf_can_loop(0); i++) + sum += i; + + return sum; +} + +SEC("socket") +__success __retval(500500) +int can_loop3(const void *ctx) +{ + return loop(); +} + char _license[] SEC("license") = "GPL"; -- 2.34.1