From: Kui-Feng Lee <sinquersw@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
Kui-Feng Lee <thinker.li@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev,
song@kernel.org, kernel-team@meta.com, andrii@kernel.org,
quentin@isovalent.com, kuifeng@meta.com
Subject: Re: [PATCH bpf-next v5 2/6] libbpf: set btf_value_type_id of struct bpf_map for struct_ops.
Date: Wed, 28 Feb 2024 13:24:01 -0800 [thread overview]
Message-ID: <c5580b27-6deb-4ab8-bc97-3c4bbd0eff20@gmail.com> (raw)
In-Reply-To: <CAEf4BzYp0xjWPzeA1-QCL20PSBa9krcA=LwxuZpe+8-btQUf6g@mail.gmail.com>
On 2/28/24 09:48, Andrii Nakryiko wrote:
> On Mon, Feb 26, 2024 at 5:04 PM Kui-Feng Lee <thinker.li@gmail.com> wrote:
>>
>> For a struct_ops map, btf_value_type_id is the type ID of it's struct
>> type. This value is required by bpftool to generate skeleton including
>> pointers of shadow types. The code generator gets the type ID from
>> bpf_map__btf_vaule_type_id() in order to get the type information of the
>> struct type of a map.
>>
>> Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
>> ---
>> tools/lib/bpf/libbpf.c | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index ef8fd20f33ca..465b50235a01 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -1229,6 +1229,7 @@ static int init_struct_ops_maps(struct bpf_object *obj, const char *sec_name,
>> map->name = strdup(var_name);
>> if (!map->name)
>> return -ENOMEM;
>> + map->btf_value_type_id = type_id;
>>
>
> this part is good
>
>> map->def.type = BPF_MAP_TYPE_STRUCT_OPS;
>> map->def.key_size = sizeof(int);
>> @@ -4818,7 +4819,9 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b
>> if (obj->btf && btf__fd(obj->btf) >= 0) {
>> create_attr.btf_fd = btf__fd(obj->btf);
>> create_attr.btf_key_type_id = map->btf_key_type_id;
>> - create_attr.btf_value_type_id = map->btf_value_type_id;
>> + create_attr.btf_value_type_id =
>> + def->type != BPF_MAP_TYPE_STRUCT_OPS ?
>> + map->btf_value_type_id : 0;
>
> but here I think it's cleaner to reset create_attr.btf_value_type_id
> to zero a bit lower, see that we have special logic for
> PERF_EVENT_ARRAY, CGROUP_ARRAY and a bunch more maps. Just add a case
> for BPF_MAP_TYPE_STRUCT_OPS that will clear
> create_attr.btf_value_type_id only (keeping btf_fd and
> map->btf_value_Type_id intact)
No problem!
>
>> }
>>
>> if (bpf_map_type__is_map_in_map(def->type)) {
>> --
>> 2.34.1
>>
next prev parent reply other threads:[~2024-02-28 21:24 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 1:04 [PATCH bpf-next v5 0/6] Create shadow types for struct_ops maps in skeletons Kui-Feng Lee
2024-02-27 1:04 ` [PATCH bpf-next v5 1/6] libbpf: expose resolve_func_ptr() through libbpf_internal.h Kui-Feng Lee
2024-02-28 14:38 ` Quentin Monnet
2024-02-28 17:45 ` Andrii Nakryiko
2024-02-28 18:27 ` Kui-Feng Lee
2024-02-27 1:04 ` [PATCH bpf-next v5 2/6] libbpf: set btf_value_type_id of struct bpf_map for struct_ops Kui-Feng Lee
2024-02-28 17:48 ` Andrii Nakryiko
2024-02-28 21:24 ` Kui-Feng Lee [this message]
2024-02-27 1:04 ` [PATCH bpf-next v5 3/6] libbpf: Convert st_ops->data to shadow type Kui-Feng Lee
2024-02-28 17:58 ` Andrii Nakryiko
2024-02-28 18:18 ` Martin KaFai Lau
2024-02-28 19:27 ` Kui-Feng Lee
2024-02-27 1:04 ` [PATCH bpf-next v5 4/6] bpftool: generated shadow variables for struct_ops maps Kui-Feng Lee
2024-02-28 18:25 ` Andrii Nakryiko
2024-02-28 21:21 ` Kui-Feng Lee
2024-02-28 22:28 ` Kui-Feng Lee
2024-02-29 0:09 ` Andrii Nakryiko
2024-02-29 0:44 ` Kui-Feng Lee
2024-02-29 0:51 ` Kui-Feng Lee
2024-02-29 1:03 ` Andrii Nakryiko
2024-02-29 1:14 ` Kui-Feng Lee
2024-02-27 1:04 ` [PATCH bpf-next v5 5/6] bpftool: Add an example for struct_ops map and shadow type Kui-Feng Lee
2024-02-28 14:38 ` Quentin Monnet
2024-02-27 1:04 ` [PATCH bpf-next v5 6/6] selftests/bpf: Test if shadow types work correctly Kui-Feng Lee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c5580b27-6deb-4ab8-bc97-3c4bbd0eff20@gmail.com \
--to=sinquersw@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=kuifeng@meta.com \
--cc=martin.lau@linux.dev \
--cc=quentin@isovalent.com \
--cc=song@kernel.org \
--cc=thinker.li@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox