bpf: Allow precision backtracking between overlapping checkpoints

SCEV integration logic might create two consecutive checkpoints at the
same instruction w/o processing any instructions in between.

This happens for loop-entry checkpoint -> regular checkpoint
sequences, where the loop-entry checkpoint has to remain unchanged
but the regular checkpoint is used for widening.

This commit adapts bpf_mark_chain_precision() to support this.

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://patch.msgid.link/20261009-scev-minimal-rebase-v3-32-bcba9bc53ac9@gmail.com
This commit is contained in:
Eduard Zingerman 2026-10-09 03:47:50 -07:00 committed by Alexei Starovoitov
parent 2fa579694d
commit 60b0109ad1
No known key found for this signature in database
3 changed files with 10 additions and 1 deletions

View File

@ -502,7 +502,10 @@ struct bpf_verifier_state {
bool speculative;
bool in_sleepable;
/* first and last insn idx of this verifier state */
/*
* First and last insn idx of this verifier state.
* last_insn_idx is -1 if no instructions have been executed yet.
*/
u32 first_insn_idx;
u32 last_insn_idx;
/* if this state is a backedge state then equal_state

View File

@ -888,6 +888,10 @@ int bpf_mark_chain_precision(struct bpf_verifier_env *env,
}
if (last_idx < 0) {
/* Consecutive checkpoints can have no instructions between them. */
if (st->parent)
goto parent;
/* we are at the entry into subprog, which
* is expected for global funcs, but only if
* requested precise registers are R1-R5
@ -952,6 +956,7 @@ int bpf_mark_chain_precision(struct bpf_verifier_env *env,
return -EFAULT;
}
}
parent:
st = st->parent;
if (!st)
break;

View File

@ -1306,6 +1306,7 @@ int bpf_split_cur_state(struct bpf_verifier_env *env)
}
cur->parent = new;
cur->last_insn_idx = -1;
cur->first_insn_idx = insn_idx;
cur->dfs_depth = new->dfs_depth + 1;
bpf_clear_jmp_history(cur);