[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <b80b0dc5-ebd3-4d6e-8ba8-9fe4d2dbf9d0@linux.dev>
Date: Thu, 14 Dec 2023 18:05:01 -0800
From: Martin KaFai Lau <martin.lau@...ux.dev>
To: thinker.li@...il.com
Cc: sinquersw@...il.com, kuifeng@...a.com, netdev@...r.kernel.org,
bpf@...r.kernel.org, ast@...nel.org, song@...nel.org, kernel-team@...a.com,
andrii@...nel.org, drosen@...gle.com
Subject: Re: [PATCH bpf-next v13 03/14] bpf, net: introduce
bpf_struct_ops_desc.
On 12/8/23 4:26 PM, thinker.li@...il.com wrote:
> diff --git a/net/bpf/bpf_dummy_struct_ops.c b/net/bpf/bpf_dummy_struct_ops.c
> index 2748f9d77b18..bd753dbccaf6 100644
> --- a/net/bpf/bpf_dummy_struct_ops.c
> +++ b/net/bpf/bpf_dummy_struct_ops.c
> @@ -17,6 +17,8 @@ struct bpf_dummy_ops_test_args {
> struct bpf_dummy_ops_state state;
> };
>
> +static struct btf *bpf_dummy_ops_btf;
> +
> static struct bpf_dummy_ops_test_args *
> dummy_ops_init_args(const union bpf_attr *kattr, unsigned int nr)
> {
> @@ -85,9 +87,13 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr,
> void *image = NULL;
> unsigned int op_idx;
> int prog_ret;
> + u32 type_id;
s32 type_id;
> int err;
>
> - if (prog->aux->attach_btf_id != st_ops->type_id)
> + type_id = btf_find_by_name_kind(bpf_dummy_ops_btf,
> + bpf_bpf_dummy_ops.name,
> + BTF_KIND_STRUCT);
if (type_id < 0)
return -EINVAL;
> + if (prog->aux->attach_btf_id != type_id)
> return -EOPNOTSUPP;
>
> func_proto = prog->aux->attach_func_proto;
> @@ -142,6 +148,7 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr,
>
> static int bpf_dummy_init(struct btf *btf)
> {
> + bpf_dummy_ops_btf = btf;
> return 0;
> }
>
> diff --git a/net/ipv4/bpf_tcp_ca.c b/net/ipv4/bpf_tcp_ca.c
> index c7bbd8f3c708..5bb56c9ad4e5 100644
> --- a/net/ipv4/bpf_tcp_ca.c
> +++ b/net/ipv4/bpf_tcp_ca.c
> @@ -20,6 +20,7 @@ static u32 unsupported_ops[] = {
>
> static const struct btf_type *tcp_sock_type;
> static u32 tcp_sock_id, sock_id;
> +static const struct btf_type *tcp_congestion_ops_type;
>
> static int bpf_tcp_ca_init(struct btf *btf)
> {
> @@ -36,6 +37,11 @@ static int bpf_tcp_ca_init(struct btf *btf)
> tcp_sock_id = type_id;
> tcp_sock_type = btf_type_by_id(btf, tcp_sock_id);
>
> + type_id = btf_find_by_name_kind(btf, "tcp_congestion_ops", BTF_KIND_STRUCT);
> + if (type_id < 0)
> + return -EINVAL;
> + tcp_congestion_ops_type = btf_type_by_id(btf, type_id);
> +
> return 0;
> }
>
> @@ -149,7 +155,7 @@ static u32 prog_ops_moff(const struct bpf_prog *prog)
> u32 midx;
>
> midx = prog->expected_attach_type;
> - t = bpf_tcp_congestion_ops.type;
> + t = tcp_congestion_ops_type;
> m = &btf_type_member(t)[midx];
>
> return __btf_member_bit_offset(t, m) / 8;
Powered by blists - more mailing lists