Message ID | 20211016124806.1547989-5-houtao1@huawei.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | introduce dummy BPF STRUCT_OPS | expand |
Context | Check | Description |
---|---|---|
bpf/vmtest-bpf-next-PR | success | PR summary |
netdev/cover_letter | success | Series has a cover letter |
netdev/fixes_present | success | Fixes tag not required for -next series |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Clearly marked for bpf-next |
netdev/subject_prefix | success | Link |
netdev/cc_maintainers | warning | 3 maintainers not CCed: john.fastabend@gmail.com songliubraving@fb.com kpsingh@kernel.org |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Signed-off-by tag matches author and committer |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 1 this patch: 1 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | No Fixes tag |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 32 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 1 this patch: 1 |
netdev/header_inline | success | No static functions without inline keyword in header files |
bpf/vmtest-bpf-next | success | VM_Test |
On Sat, Oct 16, 2021 at 08:48:05PM +0800, Hou Tao wrote: > bpf_struct_ops_test_run() will be used to run struct_ops program > from bpf_dummy_ops and now its main purpose is to test the handling > of return value and multiple arguments. lgtm. Please merge it with patch 3.
On Sat, Oct 16, 2021 at 08:48:05PM +0800, Hou Tao wrote: > bpf_struct_ops_test_run() will be used to run struct_ops program > from bpf_dummy_ops and now its main purpose is to test the handling > of return value and multiple arguments. > > Signed-off-by: Hou Tao <houtao1@huawei.com> > --- > kernel/bpf/bpf_struct_ops.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c > index 44be101f2562..ceedc9f0f786 100644 > --- a/kernel/bpf/bpf_struct_ops.c > +++ b/kernel/bpf/bpf_struct_ops.c > @@ -11,6 +11,9 @@ > #include <linux/refcount.h> > #include <linux/mutex.h> > > +static int bpf_struct_ops_test_run(struct bpf_prog *prog, > + const union bpf_attr *kattr, > + union bpf_attr __user *uattr); > enum bpf_struct_ops_state { > BPF_STRUCT_OPS_STATE_INIT, > BPF_STRUCT_OPS_STATE_INUSE, > @@ -93,6 +96,7 @@ const struct bpf_verifier_ops bpf_struct_ops_verifier_ops = { > }; > > const struct bpf_prog_ops bpf_struct_ops_prog_ops = { > + .test_run = bpf_struct_ops_test_run, > }; > > static const struct btf_type *module_type; > @@ -667,3 +671,16 @@ void bpf_struct_ops_put(const void *kdata) > call_rcu(&st_map->rcu, bpf_struct_ops_put_rcu); > } > } > + > +static int bpf_struct_ops_test_run(struct bpf_prog *prog, > + const union bpf_attr *kattr, > + union bpf_attr __user *uattr) > +{ > + const struct bpf_struct_ops *st_ops; > + > + st_ops = bpf_struct_ops_find(prog->aux->attach_btf_id); Checking bpf_bpf_dummy_ops.type_id == prog->aux->attach_btf_id is as good? then the bpf_struct_ops_find() should not be needed. > + if (st_ops != &bpf_bpf_dummy_ops) > + return -EOPNOTSUPP; > + > + return bpf_dummy_struct_ops_test_run(prog, kattr, uattr); The function bpf_dummy_struct_ops_test_run() is available under CONFIG_NET. How about checking the attach_btf_id in bpf_dummy_struct_ops_test_run(). and then rename s/bpf_dummy_struct_ops_test_run/bpf_struct_ops_test_run/. and do this in bpf_struct_ops_prog_ops: const struct bpf_prog_ops bpf_struct_ops_prog_ops = { #ifdef CONFIG_NET .test_run = bpf_struct_ops_test_run, #endif }; Take a look at some test_run in bpf_trace.c as examples.
diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c index 44be101f2562..ceedc9f0f786 100644 --- a/kernel/bpf/bpf_struct_ops.c +++ b/kernel/bpf/bpf_struct_ops.c @@ -11,6 +11,9 @@ #include <linux/refcount.h> #include <linux/mutex.h> +static int bpf_struct_ops_test_run(struct bpf_prog *prog, + const union bpf_attr *kattr, + union bpf_attr __user *uattr); enum bpf_struct_ops_state { BPF_STRUCT_OPS_STATE_INIT, BPF_STRUCT_OPS_STATE_INUSE, @@ -93,6 +96,7 @@ const struct bpf_verifier_ops bpf_struct_ops_verifier_ops = { }; const struct bpf_prog_ops bpf_struct_ops_prog_ops = { + .test_run = bpf_struct_ops_test_run, }; static const struct btf_type *module_type; @@ -667,3 +671,16 @@ void bpf_struct_ops_put(const void *kdata) call_rcu(&st_map->rcu, bpf_struct_ops_put_rcu); } } + +static int bpf_struct_ops_test_run(struct bpf_prog *prog, + const union bpf_attr *kattr, + union bpf_attr __user *uattr) +{ + const struct bpf_struct_ops *st_ops; + + st_ops = bpf_struct_ops_find(prog->aux->attach_btf_id); + if (st_ops != &bpf_bpf_dummy_ops) + return -EOPNOTSUPP; + + return bpf_dummy_struct_ops_test_run(prog, kattr, uattr); +}
bpf_struct_ops_test_run() will be used to run struct_ops program from bpf_dummy_ops and now its main purpose is to test the handling of return value and multiple arguments. Signed-off-by: Hou Tao <houtao1@huawei.com> --- kernel/bpf/bpf_struct_ops.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)