Skip to content

Commit b37a530

Browse files
Jakub Kicinskidavem330
authored andcommitted
bpf: remove old offload/analyzer
Thanks to the ability to load a program for a specific device, running verifier twice is no longer needed. Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Quentin Monnet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c6c580d commit b37a530

File tree

3 files changed

+0
-122
lines changed

3 files changed

+0
-122
lines changed

include/linux/bpf_verifier.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ struct bpf_verifier_env {
152152
bool strict_alignment; /* perform strict pointer alignment checks */
153153
struct bpf_verifier_state *cur_state; /* current verifier state */
154154
struct bpf_verifier_state_list **explored_states; /* search pruning optimization */
155-
const struct bpf_ext_analyzer_ops *analyzer_ops; /* external analyzer ops */
156155
const struct bpf_ext_analyzer_ops *dev_ops; /* device analyzer ops */
157-
void *analyzer_priv; /* pointer to external analyzer's private data */
158156
struct bpf_map *used_maps[MAX_USED_MAPS]; /* array of map's used by eBPF program */
159157
u32 used_map_cnt; /* number of used maps */
160158
u32 id_gen; /* used to generate unique reg IDs */
@@ -179,7 +177,4 @@ int bpf_prog_offload_verifier_prep(struct bpf_verifier_env *env)
179177
}
180178
#endif
181179

182-
int bpf_analyzer(struct bpf_prog *prog, const struct bpf_ext_analyzer_ops *ops,
183-
void *priv);
184-
185180
#endif /* _LINUX_BPF_VERIFIER_H */

kernel/bpf/verifier.c

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,6 @@ static int check_ctx_access(struct bpf_verifier_env *env, int insn_idx, int off,
949949
*/
950950
*reg_type = info.reg_type;
951951

952-
if (env->analyzer_ops)
953-
return 0;
954-
955952
env->insn_aux_data[insn_idx].ctx_field_size = info.ctx_field_size;
956953
/* remember the offset of last byte accessed in ctx */
957954
if (env->prog->aux->max_ctx_offset < off + size)
@@ -3736,9 +3733,6 @@ static int is_state_visited(struct bpf_verifier_env *env, int insn_idx)
37363733
static int ext_analyzer_insn_hook(struct bpf_verifier_env *env,
37373734
int insn_idx, int prev_insn_idx)
37383735
{
3739-
if (env->analyzer_ops && env->analyzer_ops->insn_hook)
3740-
return env->analyzer_ops->insn_hook(env, insn_idx,
3741-
prev_insn_idx);
37423736
if (env->dev_ops && env->dev_ops->insn_hook)
37433737
return env->dev_ops->insn_hook(env, insn_idx, prev_insn_idx);
37443738

@@ -4601,72 +4595,3 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr)
46014595
kfree(env);
46024596
return ret;
46034597
}
4604-
4605-
static const struct bpf_verifier_ops * const bpf_analyzer_ops[] = {
4606-
#ifdef CONFIG_NET
4607-
[BPF_PROG_TYPE_XDP] = &xdp_analyzer_ops,
4608-
[BPF_PROG_TYPE_SCHED_CLS] = &tc_cls_act_analyzer_ops,
4609-
#endif
4610-
};
4611-
4612-
int bpf_analyzer(struct bpf_prog *prog, const struct bpf_ext_analyzer_ops *ops,
4613-
void *priv)
4614-
{
4615-
struct bpf_verifier_env *env;
4616-
int ret;
4617-
4618-
if (prog->type >= ARRAY_SIZE(bpf_analyzer_ops) ||
4619-
!bpf_analyzer_ops[prog->type])
4620-
return -EOPNOTSUPP;
4621-
4622-
env = kzalloc(sizeof(struct bpf_verifier_env), GFP_KERNEL);
4623-
if (!env)
4624-
return -ENOMEM;
4625-
4626-
env->insn_aux_data = vzalloc(sizeof(struct bpf_insn_aux_data) *
4627-
prog->len);
4628-
ret = -ENOMEM;
4629-
if (!env->insn_aux_data)
4630-
goto err_free_env;
4631-
env->prog = prog;
4632-
env->ops = bpf_analyzer_ops[env->prog->type];
4633-
env->analyzer_ops = ops;
4634-
env->analyzer_priv = priv;
4635-
4636-
/* grab the mutex to protect few globals used by verifier */
4637-
mutex_lock(&bpf_verifier_lock);
4638-
4639-
env->strict_alignment = false;
4640-
if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS))
4641-
env->strict_alignment = true;
4642-
4643-
env->explored_states = kcalloc(env->prog->len,
4644-
sizeof(struct bpf_verifier_state_list *),
4645-
GFP_KERNEL);
4646-
ret = -ENOMEM;
4647-
if (!env->explored_states)
4648-
goto skip_full_check;
4649-
4650-
ret = check_cfg(env);
4651-
if (ret < 0)
4652-
goto skip_full_check;
4653-
4654-
env->allow_ptr_leaks = capable(CAP_SYS_ADMIN);
4655-
4656-
ret = do_check(env);
4657-
if (env->cur_state) {
4658-
free_verifier_state(env->cur_state, true);
4659-
env->cur_state = NULL;
4660-
}
4661-
4662-
skip_full_check:
4663-
while (!pop_stack(env, NULL, NULL));
4664-
free_states(env);
4665-
4666-
mutex_unlock(&bpf_verifier_lock);
4667-
vfree(env->insn_aux_data);
4668-
err_free_env:
4669-
kfree(env);
4670-
return ret;
4671-
}
4672-
EXPORT_SYMBOL_GPL(bpf_analyzer);

net/core/filter.c

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3777,25 +3777,6 @@ static bool tc_cls_act_is_valid_access(int off, int size,
37773777
return bpf_skb_is_valid_access(off, size, type, info);
37783778
}
37793779

3780-
static bool
3781-
tc_cls_act_is_valid_access_analyzer(int off, int size,
3782-
enum bpf_access_type type,
3783-
struct bpf_insn_access_aux *info)
3784-
{
3785-
switch (off) {
3786-
case offsetof(struct sk_buff, len):
3787-
return true;
3788-
case offsetof(struct sk_buff, data):
3789-
info->reg_type = PTR_TO_PACKET;
3790-
return true;
3791-
case offsetof(struct sk_buff, cb) +
3792-
offsetof(struct bpf_skb_data_end, data_end):
3793-
info->reg_type = PTR_TO_PACKET_END;
3794-
return true;
3795-
}
3796-
return false;
3797-
}
3798-
37993780
static bool __is_valid_xdp_access(int off, int size)
38003781
{
38013782
if (off < 0 || off >= sizeof(struct xdp_md))
@@ -3830,21 +3811,6 @@ static bool xdp_is_valid_access(int off, int size,
38303811
return __is_valid_xdp_access(off, size);
38313812
}
38323813

3833-
static bool xdp_is_valid_access_analyzer(int off, int size,
3834-
enum bpf_access_type type,
3835-
struct bpf_insn_access_aux *info)
3836-
{
3837-
switch (off) {
3838-
case offsetof(struct xdp_buff, data):
3839-
info->reg_type = PTR_TO_PACKET;
3840-
return true;
3841-
case offsetof(struct xdp_buff, data_end):
3842-
info->reg_type = PTR_TO_PACKET_END;
3843-
return true;
3844-
}
3845-
return false;
3846-
}
3847-
38483814
void bpf_warn_invalid_xdp_action(u32 act)
38493815
{
38503816
const u32 act_max = XDP_REDIRECT;
@@ -4516,10 +4482,6 @@ const struct bpf_verifier_ops tc_cls_act_verifier_ops = {
45164482
.gen_prologue = tc_cls_act_prologue,
45174483
};
45184484

4519-
const struct bpf_verifier_ops tc_cls_act_analyzer_ops = {
4520-
.is_valid_access = tc_cls_act_is_valid_access_analyzer,
4521-
};
4522-
45234485
const struct bpf_prog_ops tc_cls_act_prog_ops = {
45244486
.test_run = bpf_prog_test_run_skb,
45254487
};
@@ -4530,10 +4492,6 @@ const struct bpf_verifier_ops xdp_verifier_ops = {
45304492
.convert_ctx_access = xdp_convert_ctx_access,
45314493
};
45324494

4533-
const struct bpf_verifier_ops xdp_analyzer_ops = {
4534-
.is_valid_access = xdp_is_valid_access_analyzer,
4535-
};
4536-
45374495
const struct bpf_prog_ops xdp_prog_ops = {
45384496
.test_run = bpf_prog_test_run_xdp,
45394497
};

0 commit comments

Comments
 (0)