bpf: honor env->test_state_freq flag in is_state_visited()
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 2 Mar 2023 23:50:02 +0000 (15:50 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 4 Mar 2023 19:14:31 +0000 (11:14 -0800)
env->test_state_freq flag can be set by user by passing
BPF_F_TEST_STATE_FREQ program flag. This is used in a bunch of selftests
to have predictable state checkpoints at every jump and so on.

Currently, bounded loop handling heuristic ignores this flag if number
of processed jumps and/or number of processed instructions is below some
thresholds, which throws off that reliable state checkpointing.

Honor this flag in all circumstances by disabling heuristic if
env->test_state_freq is set.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20230302235015.2044271-5-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c

index b071b922848b832edea8786eed334fa84e438799..fa93ba10762d4cb9aaef8fdc59390504430a5359 100644 (file)
@@ -14651,7 +14651,8 @@ static int is_state_visited(struct bpf_verifier_env *env, int insn_idx)
                         * This threshold shouldn't be too high either, since states
                         * at the end of the loop are likely to be useful in pruning.
                         */
-                       if (env->jmps_processed - env->prev_jmps_processed < 20 &&
+                       if (!env->test_state_freq &&
+                           env->jmps_processed - env->prev_jmps_processed < 20 &&
                            env->insn_processed - env->prev_insn_processed < 100)
                                add_new_state = false;
                        goto miss;