[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <007e30b4-31aa-41b0-9e19-f7e2a385773e@linux.dev>
Date: Tue, 2 Apr 2024 10:57:03 -0700
From: Martin KaFai Lau <martin.lau@...ux.dev>
To: Jordan Rife <jrife@...gle.com>
Cc: linux-kselftest@...r.kernel.org, netdev@...r.kernel.org,
Alexei Starovoitov <ast@...nel.org>, Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>, Eduard Zingerman <eddyz87@...il.com>,
Song Liu <song@...nel.org>, Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>, KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...gle.com>, Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>, Mykola Lysenko <mykolal@...com>,
Shuah Khan <shuah@...nel.org>, "David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>, Jesper Dangaard Brouer <hawk@...nel.org>,
Daan De Meyer <daan.j.demeyer@...il.com>, bpf@...r.kernel.org
Subject: Re: [PATCH v1 bpf-next 1/8] selftests/bpf: Introduce
sock_addr_testmod
On 3/29/24 12:18 PM, Jordan Rife wrote:
> +static int do_sock_op(int op, struct sockaddr *addr, int addrlen)
This function can be made as a new kfunc in bpf_testmod.c. The
sock_create_kern() could be moved to here also. Take a look at the
register_btf_kfunc_id_set() usage in bpf_testmod.c and how those registered
kfunc(s) can be called by the bpf prog in progs/*.
If the do_kernel_{bind,connect,sendmsg} and the sock_create_kern need a
sleepable context, it will need to mark the kfunc KF_SLEEPABLE. The kfunc can be
registered to the BPF_PROG_TYPE_SYSCALL sleepable prog type. There are some
examples in progs/kfunc_call_test.c and how the "syscall" bpf prog can be run by
bpf_prog_test_run_opts().
The result (e.g. ensuring the addr and addrlen have not been changed) can be
checked in the bpf prog itself. Then the new sock_addr_testmod is not needed.
> +{
> + switch (op) {
> + case BIND:
> + return do_kernel_bind(addr, addrlen);
> + case CONNECT:
> + return do_kernel_connect(addr, addrlen);
> + case SENDMSG:
> + return do_kernel_sendmsg(addr, addrlen);
> + default:
> + return -EINVAL;
> + }
> +}
> +
Powered by blists - more mailing lists