Skip to content

Commit 4c97259

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
bpf: extract same_callsites() as utility function
Extract same_callsites() from clean_live_states() as a utility function. This function would be used by the next patch in the set. Signed-off-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 3c4e420 commit 4c97259

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

kernel/bpf/verifier.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,20 @@ static struct bpf_verifier_state_list **explored_state(struct bpf_verifier_env *
18301830
return &env->explored_states[(idx ^ state->callsite) % state_htab_size(env)];
18311831
}
18321832

1833+
static bool same_callsites(struct bpf_verifier_state *a, struct bpf_verifier_state *b)
1834+
{
1835+
int fr;
1836+
1837+
if (a->curframe != b->curframe)
1838+
return false;
1839+
1840+
for (fr = a->curframe; fr >= 0; fr--)
1841+
if (a->frame[fr]->callsite != b->frame[fr]->callsite)
1842+
return false;
1843+
1844+
return true;
1845+
}
1846+
18331847
static void update_branch_counts(struct bpf_verifier_env *env, struct bpf_verifier_state *st)
18341848
{
18351849
while (st) {
@@ -15909,18 +15923,14 @@ static void clean_live_states(struct bpf_verifier_env *env, int insn,
1590915923
struct bpf_verifier_state *cur)
1591015924
{
1591115925
struct bpf_verifier_state_list *sl;
15912-
int i;
1591315926

1591415927
sl = *explored_state(env, insn);
1591515928
while (sl) {
1591615929
if (sl->state.branches)
1591715930
goto next;
1591815931
if (sl->state.insn_idx != insn ||
15919-
sl->state.curframe != cur->curframe)
15932+
!same_callsites(&sl->state, cur))
1592015933
goto next;
15921-
for (i = 0; i <= cur->curframe; i++)
15922-
if (sl->state.frame[i]->callsite != cur->frame[i]->callsite)
15923-
goto next;
1592415934
clean_verifier_state(env, &sl->state);
1592515935
next:
1592615936
sl = sl->next;

0 commit comments

Comments
 (0)