Skip to content

Commit 00176a3

Browse files
Jakub Kicinskidavem330
authored andcommitted
bpf: remove the verifier ops from program structure
Since the verifier ops don't have to be associated with the program for its entire lifetime we can move it to verifier's struct bpf_verifier_env. Signed-off-by: Jakub Kicinski <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7de16e3 commit 00176a3

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

include/linux/bpf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ struct bpf_prog_aux {
188188
struct latch_tree_node ksym_tnode;
189189
struct list_head ksym_lnode;
190190
const struct bpf_prog_ops *ops;
191-
const struct bpf_verifier_ops *vops;
192191
struct bpf_map **used_maps;
193192
struct bpf_prog *prog;
194193
struct user_struct *user;

include/linux/bpf_verifier.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct bpf_ext_analyzer_ops {
141141
*/
142142
struct bpf_verifier_env {
143143
struct bpf_prog *prog; /* eBPF program being verified */
144+
const struct bpf_verifier_ops *ops;
144145
struct bpf_verifier_stack_elem *head; /* stack of verifier states to be processed */
145146
int stack_size; /* number of states to be processed */
146147
bool strict_alignment; /* perform strict pointer alignment checks */

kernel/bpf/syscall.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -748,22 +748,12 @@ static const struct bpf_prog_ops * const bpf_prog_types[] = {
748748
#undef BPF_MAP_TYPE
749749
};
750750

751-
static const struct bpf_verifier_ops * const bpf_verifier_ops[] = {
752-
#define BPF_PROG_TYPE(_id, _name) \
753-
[_id] = & _name ## _verifier_ops,
754-
#define BPF_MAP_TYPE(_id, _ops)
755-
#include <linux/bpf_types.h>
756-
#undef BPF_PROG_TYPE
757-
#undef BPF_MAP_TYPE
758-
};
759-
760751
static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog)
761752
{
762753
if (type >= ARRAY_SIZE(bpf_prog_types) || !bpf_prog_types[type])
763754
return -EINVAL;
764755

765756
prog->aux->ops = bpf_prog_types[type];
766-
prog->aux->vops = bpf_verifier_ops[type];
767757
prog->type = type;
768758
return 0;
769759
}

kernel/bpf/verifier.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323

2424
#include "disasm.h"
2525

26+
static const struct bpf_verifier_ops * const bpf_verifier_ops[] = {
27+
#define BPF_PROG_TYPE(_id, _name) \
28+
[_id] = & _name ## _verifier_ops,
29+
#define BPF_MAP_TYPE(_id, _ops)
30+
#include <linux/bpf_types.h>
31+
#undef BPF_PROG_TYPE
32+
#undef BPF_MAP_TYPE
33+
};
34+
2635
/* bpf_check() is a static code analyzer that walks eBPF program
2736
* instruction by instruction and updates register/stack state.
2837
* All paths of conditional branches are analyzed until 'bpf_exit' insn.
@@ -856,8 +865,8 @@ static int check_ctx_access(struct bpf_verifier_env *env, int insn_idx, int off,
856865
*reg_type = info.reg_type;
857866
return 0;
858867
}
859-
} else if (env->prog->aux->vops->is_valid_access &&
860-
env->prog->aux->vops->is_valid_access(off, size, t, &info)) {
868+
} else if (env->ops->is_valid_access &&
869+
env->ops->is_valid_access(off, size, t, &info)) {
861870
/* A non zero info.ctx_field_size indicates that this field is a
862871
* candidate for later verifier transformation to load the whole
863872
* field and then apply a mask when accessed with a narrower
@@ -1565,8 +1574,8 @@ static int check_call(struct bpf_verifier_env *env, int func_id, int insn_idx)
15651574
return -EINVAL;
15661575
}
15671576

1568-
if (env->prog->aux->vops->get_func_proto)
1569-
fn = env->prog->aux->vops->get_func_proto(func_id);
1577+
if (env->ops->get_func_proto)
1578+
fn = env->ops->get_func_proto(func_id);
15701579

15711580
if (!fn) {
15721581
verbose(env, "unknown func %s#%d\n", func_id_name(func_id),
@@ -4035,7 +4044,7 @@ static struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 of
40354044
*/
40364045
static int convert_ctx_accesses(struct bpf_verifier_env *env)
40374046
{
4038-
const struct bpf_verifier_ops *ops = env->prog->aux->vops;
4047+
const struct bpf_verifier_ops *ops = env->ops;
40394048
int i, cnt, size, ctx_field_size, delta = 0;
40404049
const int insn_cnt = env->prog->len;
40414050
struct bpf_insn insn_buf[16], *insn;
@@ -4236,7 +4245,7 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
42364245
insn = new_prog->insnsi + i + delta;
42374246
}
42384247
patch_call_imm:
4239-
fn = prog->aux->vops->get_func_proto(insn->imm);
4248+
fn = env->ops->get_func_proto(insn->imm);
42404249
/* all functions that have prototype and verifier allowed
42414250
* programs to call them, must be real in-kernel functions
42424251
*/
@@ -4294,6 +4303,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr)
42944303
if (!env->insn_aux_data)
42954304
goto err_free_env;
42964305
env->prog = *prog;
4306+
env->ops = bpf_verifier_ops[env->prog->type];
42974307

42984308
/* grab the mutex to protect few globals used by verifier */
42994309
mutex_lock(&bpf_verifier_lock);
@@ -4406,6 +4416,7 @@ int bpf_analyzer(struct bpf_prog *prog, const struct bpf_ext_analyzer_ops *ops,
44064416
if (!env->insn_aux_data)
44074417
goto err_free_env;
44084418
env->prog = prog;
4419+
env->ops = bpf_verifier_ops[env->prog->type];
44094420
env->analyzer_ops = ops;
44104421
env->analyzer_priv = priv;
44114422

0 commit comments

Comments
 (0)