Skip to content

Commit 590eee4

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
bpf: do not update state->loop_entry in get_loop_entry()
The patch 9 is simpler if less places modify loop_entry field. The loop deleted by this patch does not affect correctness, but is a performance optimization. However, measurements on selftests and sched_ext programs show that this optimization is unnecessary: - at most 2 steps are done in get_loop_entry(); - most of the time 0 or 1 steps are done in get_loop_entry(). Measured using "do-not-submit" patches from here: https://github.com/eddyz87/bpf/tree/get-loop-entry-hungup Signed-off-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent bb7abf3 commit 590eee4

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

kernel/bpf/verifier.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,13 +1829,12 @@ static bool same_callsites(struct bpf_verifier_state *a, struct bpf_verifier_sta
18291829
* and cur's loop entry has to be updated (case A), handle this in
18301830
* update_branch_counts();
18311831
* - use st->branch > 0 as a signal that st is in the current DFS path;
1832-
* - handle cases B and C in is_state_visited();
1833-
* - update topmost loop entry for intermediate states in get_loop_entry().
1832+
* - handle cases B and C in is_state_visited().
18341833
*/
18351834
static struct bpf_verifier_state *get_loop_entry(struct bpf_verifier_env *env,
18361835
struct bpf_verifier_state *st)
18371836
{
1838-
struct bpf_verifier_state *topmost = st->loop_entry, *old;
1837+
struct bpf_verifier_state *topmost = st->loop_entry;
18391838
u32 steps = 0;
18401839

18411840
while (topmost && topmost->loop_entry) {
@@ -1846,14 +1845,6 @@ static struct bpf_verifier_state *get_loop_entry(struct bpf_verifier_env *env,
18461845
}
18471846
topmost = topmost->loop_entry;
18481847
}
1849-
/* Update loop entries for intermediate states to avoid this
1850-
* traversal in future get_loop_entry() calls.
1851-
*/
1852-
while (st && st->loop_entry != topmost) {
1853-
old = st->loop_entry;
1854-
st->loop_entry = topmost;
1855-
st = old;
1856-
}
18571848
return topmost;
18581849
}
18591850

0 commit comments

Comments
 (0)