From: Alexei Starovoitov The bound of the loop is 10. It is in .rodata, and the prog loads it in each iteration, as clang does for a 'const volatile' variable. The test expects that scalar evolution calculates the number of iterations: loop header at 3, header_count is 10 Without "bpf: Let scalar evolution see loads from read-only maps" the message is 'non-linear latch at 5'. Signed-off-by: Alexei Starovoitov --- .../selftests/bpf/progs/verifier_scev.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_scev.c b/tools/testing/selftests/bpf/progs/verifier_scev.c index 61bb39a12de2..c242724686fc 100644 --- a/tools/testing/selftests/bpf/progs/verifier_scev.c +++ b/tools/testing/selftests/bpf/progs/verifier_scev.c @@ -1411,6 +1411,29 @@ __naked void widened_reg_is_not_linked(void) : __clobber_all); } +const volatile __u32 rodata_bound = 10; + +/* for (i = 0; i < rodata_bound; i++): the bound is loaded in every iteration. */ +SEC("socket") +__success +__log_level(2) +__msg("loop header at 3, header_count is 10") +__naked void bound_from_rodata(void) +{ + asm volatile ( + "r6 = 0;" + "r7 = %[rodata_bound] ll;" +"1:" + "r6 += 1;" + "r1 = *(u32 *)(r7 + 0);" + "if r6 < r1 goto 1b;" + "r0 = 0;" + "exit;" + : + : __imm_addr(rodata_bound) + : __clobber_all); +} + /* The unknown SCEV of an unbound STACK_MISC slot must not prevent widening. */ SEC("tracepoint") __success -- 2.55.0