Re: [PATCH bpf-next 3/5] bpf: do .test_run in dummy BPF STRUCT_OPS
From: Martin KaFai Lau <hidden>
Date: 2021-10-01 19:09:43
Also in:
bpf
On Thu, Sep 30, 2021 at 07:05:41PM +0800, Hou Tao wrote:
quoted
quoted
diff --git a/net/bpf/bpf_dummy_struct_ops.c b/net/bpf/bpf_dummy_struct_ops.c index 1249e4bb4ccb..da77736cd093 100644 --- a/net/bpf/bpf_dummy_struct_ops.c +++ b/net/bpf/bpf_dummy_struct_ops.c@@ -10,12 +10,188 @@ extern struct bpf_struct_ops bpf_bpf_dummy_ops; +static const struct btf_type *dummy_ops_state; + +static struct bpf_dummy_ops_state * +init_dummy_ops_state(const union bpf_attr *kattr) +{ + __u32 size_in; + struct bpf_dummy_ops_state *state; + void __user *data_in; + + size_in = kattr->test.data_size_in;These are the args for the test functions? Using ctx_in/ctx_size_in and ctx_out/ctx_size_out instead should be more consistent with other bpf_prog_test_run* in test_run.c.Yes, there are args. I had think about using ctx_in/ctx_out, but I didn't because I thought the program which using ctx_in/ctx_out only has one argument (namely bpf_context *), but the bpf_dummy_ops::init may have multiple arguments. Anyway I will check it again and use ctx_in/ctx_out if possible.
got it.
ctx_in could have multiple args.
I was more thinking on the muliple arg test also. Potentially some of them
are just integers, e.g.
int test2(struct bpf_dummy_ops_state *state, char a, short b, int c, long d)
{
}
All args can be put in ctx_in like bpf_prog_test_run_raw_tp().
Take a look at raw_tp_test_run.c. Although it is not strictly
necessary to use u64 for all args in the struct_ops test
because the struct_ops test still wants to prepare the
trampoline to catch the return value issue...etc, passing
an array of u64 args in ctx_in should make it easier to program
the userspace and optimizing the ctx_in based on the sizeof each
arg seems not gaining much as a test also.
For "struct bpf_dummy_ops_state *state", instead of making an
exception to pass ptr arg in data_in, the user ptr can be directly
passed as a u64 stored in ctx_in also, then there is no need to use
data_in or data_size_in. If it is needed, the userspace's
sizeof(struct bpf_dummy_ops_state) can be found from the
prog->aux->btf.
There is no need to use data_out/data_out_size also, just directly
copy it back to the same user ptr stored in ctx_in.