Commit 4c97259a authored by Eduard Zingerman's avatar Eduard Zingerman Committed by Alexei Starovoitov

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: default avatarEduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20231024000917.12153-3-eddyz87@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 3c4e420c
...@@ -1830,6 +1830,20 @@ static struct bpf_verifier_state_list **explored_state(struct bpf_verifier_env * ...@@ -1830,6 +1830,20 @@ static struct bpf_verifier_state_list **explored_state(struct bpf_verifier_env *
return &env->explored_states[(idx ^ state->callsite) % state_htab_size(env)]; return &env->explored_states[(idx ^ state->callsite) % state_htab_size(env)];
} }
static bool same_callsites(struct bpf_verifier_state *a, struct bpf_verifier_state *b)
{
int fr;
if (a->curframe != b->curframe)
return false;
for (fr = a->curframe; fr >= 0; fr--)
if (a->frame[fr]->callsite != b->frame[fr]->callsite)
return false;
return true;
}
static void update_branch_counts(struct bpf_verifier_env *env, struct bpf_verifier_state *st) static void update_branch_counts(struct bpf_verifier_env *env, struct bpf_verifier_state *st)
{ {
while (st) { while (st) {
...@@ -15909,18 +15923,14 @@ static void clean_live_states(struct bpf_verifier_env *env, int insn, ...@@ -15909,18 +15923,14 @@ static void clean_live_states(struct bpf_verifier_env *env, int insn,
struct bpf_verifier_state *cur) struct bpf_verifier_state *cur)
{ {
struct bpf_verifier_state_list *sl; struct bpf_verifier_state_list *sl;
int i;
sl = *explored_state(env, insn); sl = *explored_state(env, insn);
while (sl) { while (sl) {
if (sl->state.branches) if (sl->state.branches)
goto next; goto next;
if (sl->state.insn_idx != insn || if (sl->state.insn_idx != insn ||
sl->state.curframe != cur->curframe) !same_callsites(&sl->state, cur))
goto next; goto next;
for (i = 0; i <= cur->curframe; i++)
if (sl->state.frame[i]->callsite != cur->frame[i]->callsite)
goto next;
clean_verifier_state(env, &sl->state); clean_verifier_state(env, &sl->state);
next: next:
sl = sl->next; sl = sl->next;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment