Skip to content

Commit 346757c

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
bpf: include backedges in peak_states stat
Count states accumulated in bpf_scc_visit->backedges in env->peak_states. Signed-off-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 49af1fa commit 346757c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

include/linux/bpf_verifier.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ struct bpf_scc_visit {
733733
*/
734734
struct bpf_verifier_state *entry_state;
735735
struct bpf_scc_backedge *backedges; /* list of backedges */
736+
u32 num_backedges;
736737
};
737738

738739
/* An array of bpf_scc_visit structs sharing tht same bpf_scc_callchain->scc
@@ -822,6 +823,7 @@ struct bpf_verifier_env {
822823
u32 longest_mark_read_walk;
823824
u32 free_list_size;
824825
u32 explored_states_size;
826+
u32 num_backedges;
825827
bpfptr_t fd_array;
826828

827829
/* bit mask to keep track of whether a register has been accessed

kernel/bpf/verifier.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ static void update_peak_states(struct bpf_verifier_env *env)
16481648
{
16491649
u32 cur_states;
16501650

1651-
cur_states = env->explored_states_size + env->free_list_size;
1651+
cur_states = env->explored_states_size + env->free_list_size + env->num_backedges;
16521652
env->peak_states = max(env->peak_states, cur_states);
16531653
}
16541654

@@ -1949,6 +1949,9 @@ static int maybe_exit_scc(struct bpf_verifier_env *env, struct bpf_verifier_stat
19491949
if (env->log.level & BPF_LOG_LEVEL2)
19501950
verbose(env, "SCC exit %s\n", format_callchain(env, &callchain));
19511951
visit->entry_state = NULL;
1952+
env->num_backedges -= visit->num_backedges;
1953+
visit->num_backedges = 0;
1954+
update_peak_states(env);
19521955
return propagate_backedges(env, visit);
19531956
}
19541957

@@ -1977,6 +1980,9 @@ static int add_scc_backedge(struct bpf_verifier_env *env,
19771980
verbose(env, "SCC backedge %s\n", format_callchain(env, &callchain));
19781981
backedge->next = visit->backedges;
19791982
visit->backedges = backedge;
1983+
visit->num_backedges++;
1984+
env->num_backedges++;
1985+
update_peak_states(env);
19801986
return 0;
19811987
}
19821988

0 commit comments

Comments
 (0)