From: Alexei Starovoitov "bpf: Describe loops that scalar evolution cannot count exactly" counts more loops. Three tests expected a loop that is not counted. All progs load. test the test expects now ---------------------------- ------------------------------------------- no_widen_small_spill_counter header_count is [0..266] uninit_slot_counter header_count is [0..11] state_loop_first_last_equal the prog loads kfunc_implicit_arg (new) r5 is not live before the call of the kfunc The first two loops count from a stack slot with unknown contents. The count has an upper bound for each first value. state_loop_first_last_equal examined the log of precision backtracking in a loop that was not counted. 'r0 += 1; r0 += 1' is now a step of 2, and the loop is counted. Keep the prog as a load test: "bpf: Remove precision tracking" removes backtracking. The verifier fills in r5, the implicit argument of bpf_stream_vprintk(). Signed-off-by: Alexei Starovoitov --- .../bpf/progs/compute_live_registers.c | 13 ++++++++++ .../selftests/bpf/progs/verifier_precision.c | 25 ++----------------- .../selftests/bpf/progs/verifier_scev.c | 6 +++-- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/compute_live_registers.c b/tools/testing/selftests/bpf/progs/compute_live_registers.c index 1ff24bbc7beb..de0496ce7d5e 100644 --- a/tools/testing/selftests/bpf/progs/compute_live_registers.c +++ b/tools/testing/selftests/bpf/progs/compute_live_registers.c @@ -538,6 +538,19 @@ void gotox(void) #endif /* gotox: x86, arm64, riscv64 */ +extern int bpf_stream_vprintk(int stream_id, const char *fmt__str, const void *args, + __u32 len__sz) __weak __ksym; + +/* The verifier fills in the implicit argument of the kfunc. The prog does not pass r5. */ +SEC("syscall") +__log_level(2) +__msg(": .1234..... (85) call bpf_stream_vprintk") +int kfunc_implicit_arg(void *ctx) +{ + bpf_stream_printk(1 /* BPF_STDOUT */, "x"); + return 0; +} + /* to retain debug info for BTF generation */ void kfunc_root(void) { diff --git a/tools/testing/selftests/bpf/progs/verifier_precision.c b/tools/testing/selftests/bpf/progs/verifier_precision.c index f4459561bf39..2ec3ee7821c0 100644 --- a/tools/testing/selftests/bpf/progs/verifier_precision.c +++ b/tools/testing/selftests/bpf/progs/verifier_precision.c @@ -150,24 +150,7 @@ __naked int bpf_store_release(void) #endif /* v4 instruction */ SEC("?raw_tp") -__success __log_level(2) -/* - * Without the bug fix there will be no history between "last_idx 3 first_idx 3" - * and "parent state regs=" lines. "R0=6" parts are here to help anchor - * expected log messages to the one specific mark_chain_precision operation. - * - * This is quite fragile: if verifier checkpointing heuristic changes, this - * might need adjusting. - */ -__msg("2: (07) r0 += 1 ; R0=6") -__msg("3: (35) if r0 >= 0xa goto pc+1") -__msg("mark_precise: frame0: last_idx 3 first_idx 3 subseq_idx -1") -__msg("mark_precise: frame0: regs=r0 stack= before 2: (07) r0 += 1") -__msg("mark_precise: frame0: regs=r0 stack= before 1: (07) r0 += 1") -__msg("mark_precise: frame0: regs=r0 stack= before 4: (05) goto pc-4") -__msg("mark_precise: frame0: regs=r0 stack= before 3: (35) if r0 >= 0xa goto pc+1") -__msg("mark_precise: frame0: parent state regs= stack=: R0=P4") -__msg("3: R0=6") +__success __naked int state_loop_first_last_equal(void) { asm volatile ( @@ -175,11 +158,7 @@ __naked int state_loop_first_last_equal(void) "l0_%=:" "r0 += 1;" "r0 += 1;" - /* every few iterations we'll have a checkpoint here with - * first_idx == last_idx, potentially confusing precision - * backtracking logic - */ - "if r0 >= 10 goto l1_%=;" /* checkpoint + mark_precise */ + "if r0 >= 10 goto l1_%=;" "goto l0_%=;" "l1_%=:" "exit;" diff --git a/tools/testing/selftests/bpf/progs/verifier_scev.c b/tools/testing/selftests/bpf/progs/verifier_scev.c index a68a2368aa71..b30802c9e9e3 100644 --- a/tools/testing/selftests/bpf/progs/verifier_scev.c +++ b/tools/testing/selftests/bpf/progs/verifier_scev.c @@ -1188,7 +1188,8 @@ __success __log_level(2) __msg("scev at header 2:") __msg_next(" *fp-8=(+ *fp-8 1) / (linear *fp-8 1)") -__msg("loop header at 2, can't compute iterations count") +/* whatever is in the other bytes of the slot */ +__msg("loop header at 2, header_count is [0..266] ") __not_msg("widening") __naked void no_widen_small_spill_counter(void) { @@ -2405,7 +2406,8 @@ __naked void sibling_inner_loops(void) SEC("socket") __success __log_level(2) -__msg("loop header at 0, can't compute iterations count") +/* whatever is in the slot */ +__msg("loop header at 0, header_count is [0..11] ") __naked void uninit_slot_counter(void) { asm volatile (" \ -- 2.55.0