From: Kui-Feng Lee <sinquersw@gmail.com>
To: Eduard Zingerman <eddyz87@gmail.com>,
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
Cc: kuifeng@meta.com
Subject: Re: [PATCH bpf-next v6 5/9] bpf: look into the types of the fields of a struct type recursively.
Date: Thu, 23 May 2024 09:59:55 -0700 [thread overview]
Message-ID: <717622d5-0005-495b-8f06-85009e223429@gmail.com> (raw)
In-Reply-To: <6266baf6b48afb63df4789cb932dfee713029988.camel@gmail.com>
On 5/21/24 11:12, Eduard Zingerman wrote:
> On Mon, 2024-05-20 at 13:40 -0700, Kui-Feng Lee wrote:
>> The verifier has field information for specific special types, such as
>> kptr, rbtree root, and list head. These types are handled
>> differently. However, we did not previously examine the types of fields of
>> a struct type variable. Field information records were not generated for
>> the kptrs, rbtree roots, and linked_list heads that are not located at the
>> outermost struct type of a variable.
>>
>> For example,
>>
>> struct A {
>> struct task_struct __kptr * task;
>> };
>>
>> struct B {
>> struct A mem_a;
>> }
>>
>> struct B var_b;
>>
>> It did not examine "struct A" so as not to generate field information for
>> the kptr in "struct A" for "var_b".
>>
>> This patch enables BPF programs to define fields of these special types in
>> a struct type other than the direct type of a variable or in a struct type
>> that is the type of a field in the value type of a map.
>>
>> Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
>> ---
>
> Acked-by: Eduard Zingerman <eddyz87@gmail.com>
>
> [...]
>
>> + /* Look into variables of struct types */
>> + if ((field_type == BPF_KPTR_REF || !field_type) &&
>> + __btf_type_is_struct(var_type)) {
>
> This code would have looked nicer (handled inside the same switch as
> all other branches) if we had BPF_NESTED_FIELD in `btf_field_type` or
> something like that. But that's probably be an overkill.
After thinking twice, I will change btf_get_field_type() to return
BPF_KPTR_REF only if the type is not struct.
>
>> + sz = var_type->size;
>> + if (expected_size && expected_size != sz * nelems)
>> + return 0;
>> + ret = btf_find_nested_struct(btf, var_type, off, nelems, field_mask,
>> + &info[0], info_cnt);
>> + return ret;
>> + }
>
> [...]
next prev parent reply other threads:[~2024-05-23 16:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-20 20:40 [PATCH bpf-next v6 0/9] Enable BPF programs to declare arrays of kptr, bpf_rb_root, and bpf_list_head Kui-Feng Lee
2024-05-20 20:40 ` [PATCH bpf-next v6 1/9] bpf: Remove unnecessary checks on the offset of btf_field Kui-Feng Lee
2024-05-20 20:40 ` [PATCH bpf-next v6 2/9] bpf: Remove unnecessary call to btf_field_type_size() Kui-Feng Lee
2024-05-20 20:40 ` [PATCH bpf-next v6 3/9] bpf: refactor btf_find_struct_field() and btf_find_datasec_var() Kui-Feng Lee
2024-05-20 20:40 ` [PATCH bpf-next v6 4/9] bpf: create repeated fields for arrays Kui-Feng Lee
2024-05-20 20:40 ` [PATCH bpf-next v6 5/9] bpf: look into the types of the fields of a struct type recursively Kui-Feng Lee
2024-05-21 18:12 ` Eduard Zingerman
2024-05-23 16:59 ` Kui-Feng Lee [this message]
2024-05-20 20:40 ` [PATCH bpf-next v6 6/9] bpf: limit the number of levels of a nested struct type Kui-Feng Lee
2024-05-20 20:40 ` [PATCH bpf-next v6 7/9] selftests/bpf: Test kptr arrays and kptrs in nested struct fields Kui-Feng Lee
2024-05-21 17:35 ` Eduard Zingerman
2024-05-20 20:40 ` [PATCH bpf-next v6 8/9] selftests/bpf: Test global bpf_rb_root arrays and fields in nested struct types Kui-Feng Lee
2024-05-20 20:40 ` [PATCH bpf-next v6 9/9] selftests/bpf: Test global bpf_list_head arrays Kui-Feng Lee
2024-05-21 18:31 ` Eduard Zingerman
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=717622d5-0005-495b-8f06-85009e223429@gmail.com \
--to=sinquersw@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=kernel-team@meta.com \
--cc=kuifeng@meta.com \
--cc=martin.lau@linux.dev \
--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