bpf: add find_containing_subprog() utility function
commit 27e88bc4df1d80888fe1aaca786a7cc6e69587e2 upstream. Add a utility function, looking for a subprogram containing a given instruction index, rewrite find_subprog() to use this function. Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/r/20241210041100.1898468-2-eddyz87@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
ab7edf42ce
commit
d30b9c5950
+24
-4
@@ -2528,16 +2528,36 @@ static int cmp_subprogs(const void *a, const void *b)
|
|||||||
((struct bpf_subprog_info *)b)->start;
|
((struct bpf_subprog_info *)b)->start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Find subprogram that contains instruction at 'off' */
|
||||||
|
static struct bpf_subprog_info *find_containing_subprog(struct bpf_verifier_env *env, int off)
|
||||||
|
{
|
||||||
|
struct bpf_subprog_info *vals = env->subprog_info;
|
||||||
|
int l, r, m;
|
||||||
|
|
||||||
|
if (off >= env->prog->len || off < 0 || env->subprog_cnt == 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
l = 0;
|
||||||
|
r = env->subprog_cnt - 1;
|
||||||
|
while (l < r) {
|
||||||
|
m = l + (r - l + 1) / 2;
|
||||||
|
if (vals[m].start <= off)
|
||||||
|
l = m;
|
||||||
|
else
|
||||||
|
r = m - 1;
|
||||||
|
}
|
||||||
|
return &vals[l];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find subprogram that starts exactly at 'off' */
|
||||||
static int find_subprog(struct bpf_verifier_env *env, int off)
|
static int find_subprog(struct bpf_verifier_env *env, int off)
|
||||||
{
|
{
|
||||||
struct bpf_subprog_info *p;
|
struct bpf_subprog_info *p;
|
||||||
|
|
||||||
p = bsearch(&off, env->subprog_info, env->subprog_cnt,
|
p = find_containing_subprog(env, off);
|
||||||
sizeof(env->subprog_info[0]), cmp_subprogs);
|
if (!p || p->start != off)
|
||||||
if (!p)
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
return p - env->subprog_info;
|
return p - env->subprog_info;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_subprog(struct bpf_verifier_env *env, int off)
|
static int add_subprog(struct bpf_verifier_env *env, int off)
|
||||||
|
|||||||
Reference in New Issue
Block a user