BPF List
 help / color / mirror / Atom feed
From: Kui-Feng Lee <sinquersw@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Kui-Feng Lee <thinker.li@gmail.com>,
	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 4/6] bpftool: generated shadow variables for struct_ops maps.
Date: Wed, 28 Feb 2024 16:51:43 -0800	[thread overview]
Message-ID: <c1387f44-0eea-4b65-b184-53f9b974a7bc@gmail.com> (raw)
In-Reply-To: <63fb7cb7-e884-472f-a81f-182d5867d1d4@gmail.com>



On 2/28/24 16:44, Kui-Feng Lee wrote:
> 
> 
> On 2/28/24 16:09, Andrii Nakryiko wrote:
>> On Wed, Feb 28, 2024 at 2:28 PM Kui-Feng Lee <sinquersw@gmail.com> wrote:
>>>
>>>
>>>
>>> On 2/28/24 13:21, Kui-Feng Lee wrote:
>>>> Will fix most of issues.
>>>>
>>>> On 2/28/24 10:25, Andrii Nakryiko wrote:
>>>>> On Mon, Feb 26, 2024 at 5:04 PM Kui-Feng Lee <thinker.li@gmail.com>
>>>>> wrote:
>>>>>>
>>>>>> + * type. Accessing them through the generated names may 
>>>>>> unintentionally
>>>>>> + * corrupt data.
>>>>>> + */
>>>>>> +static int gen_st_ops_shadow_type(struct btf *btf, const char 
>>>>>> *ident,
>>>>>> +                                 const struct bpf_map *map)
>>>>>> +{
>>>>>> +       int err;
>>>>>> +
>>>>>> +       printf("\t\tstruct {\n");
>>>>>
>>>>> would it be useful to still name this type? E.g., if it is `struct
>>>>> bpf_struct_ops_tcp_congestion_ops in vmlinux BTF` we can name this one
>>>>> as <skeleton-name>__bpf_struct_ops_tcp_congestion_ops. We have a
>>>>> similar pattern for bss/data/rodata sections, having names is useful.
>>>>
>>>> If a user defines several struct_ops maps with the same name and 
>>>> type in
>>>> different files, it can cause name conflicts. Unless we also prefix the
>>>> name with the name of the skeleton. I am not sure if it is a good idea
>>>> to generate such long names. If a user want to refer to the type, he
>>>> still can use typeof(). WDYT?
>>>
>>> I misread your words. So, you were saying to prefix the skeleton name,
>>> not map names. It is doable.
>>
>> I did say to prefix with skeleton name, but *that* actually can lead
>> to a conflict if you have two struct_ops maps that use the same BTF
>> type. On the other hand, map names are unique, they are forced to be
>> global symbols, so there is no way for them to conflict (it would be
>> link-time error).
> 
> I avoided conflicts by checking if the definition of a type is already
> generated.
> 
> For example, if there are two maps with the same type, they would looks 
> like.
> struct XXXSekelton {
>      ...
>      struct {
>          struct struct_ops_type {
>               ....
>          } *map1;
>          struct struct_ops_type *map2;
>      } struct_ops;
>    ...
> };
> 
> WDYT?

Sorry! It should be "<skeleton-type>_bpf_struct_ops_tcp_congestion_ops"
instead of "struct_ops_type".

> 
>>
>> How about we append both skeleton name, map name, and map's underlying
>> BTF type? So:
>>
>> <skel>__<map>__bpf_struct_ops_tcp_congestion_ops
>>
>> ?
>>
>> Is there any problem with having a long name?
> 
> No a big problem! Just not convenient to use.
> 
>>
>>>
>>>>
>>>>>
>>>>>> +
>>>>>> +       err = walk_st_ops_shadow_vars(btf, ident, map);
>>>>>> +       if (err)
>>>>>> +               return err;
>>>>>> +
>>>>>> +       printf("\t\t} *%s;\n", ident);
>>>>>> +
>>>>>> +       return 0;
>>>>>> +}
>>>>>> +

  reply	other threads:[~2024-02-29  0:51 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
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 [this message]
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=c1387f44-0eea-4b65-b184-53f9b974a7bc@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