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 | 14 ++++++++++++++ 2 files changed, 15 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..7c2025e58554 100644 --- a/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c +++ b/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c @@ -239,4 +239,18 @@ int bpf_loop_iter_limit_nested(void *unused) return 1000 * a + b + c; } +SEC("socket") +__success __retval(0xa93addc0) +int can_loop(const void *ctx) +{ + int sum = 0; + volatile int i; + + for (i = 0; i < 2000000 && bpf_can_loop(0); i++) + sum += i; + + return sum; +} + + char _license[] SEC("license") = "GPL"; -- 2.34.1