From: Kui-Feng Lee <sinquersw@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Kui-Feng Lee <thinker.li@gmail.com>, bpf <bpf@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Kernel Team <kernel-team@meta.com>,
Andrii Nakryiko <andrii@kernel.org>,
Kui-Feng Lee <kuifeng@meta.com>
Subject: Re: [PATCH bpf-next v2 00/11] Enable BPF programs to declare arrays of kptr, bpf_rb_root, and bpf_list_head.
Date: Thu, 25 Apr 2024 10:08:23 -0700 [thread overview]
Message-ID: <5b6f154e-3317-4ba0-af50-6d48ae08be19@gmail.com> (raw)
In-Reply-To: <CAADnVQ+v7HPSxKV0f-BiwF3DntcYmpstyTDmnHuBsXN=GfB1Fg@mail.gmail.com>
On 4/24/24 17:49, Alexei Starovoitov wrote:
> On Wed, Apr 24, 2024 at 3:32 PM Kui-Feng Lee <sinquersw@gmail.com> wrote:
>>
>>> struct map_value {
>>> struct {
>>> struct task __kptr *p1;
>>> struct thread __kptr *p2;
>>> } arr[10];
>>> };
>>>
>>> won't be able to be represented as BPF_REPEAT_FIELDS?
>>
>>
>> BPF_REPEAT_FIELDS can handle it. With this case, bpf_parse_fields() will
>> create a list of btf_fields like this:
>>
>> [ btf_field(type=BPF_KPTR_..., offset=0, ...),
>> btf_field(type=BPF_KPTR_..., offset=8, ...),
>> btf_field(type=BPF_REPEAT_FIELDS, offset=16, repeated_fields=2,
>> nelems=9, size=16)]
>>
>> You might miss the explanation in [1].
>>
>> btf_record_find() is still doing binary search. Looking for p2 in
>> obj->arr[1], the offset will be 24. btf_record_find() will find the
>> BPF_REPEATED_FIELDS one, and redirect the offset to
>>
>> (field->offset - field->size + (16 - field->offset) % field->size) == 8
>>
>> Then, it will return the btf_field whose offset is 8.
>>
>>
>> [1]
>> https://lore.kernel.org/all/4d3dc24f-fb50-4674-8eec-4c38e4d4b2c1@gmail.com/
>
> I somehow completely missed that email.
> Just read it and tbh it looks very unnatural and convoluted.
>
>> [kptr_a, kptr_b, repeated_fields(nelems=3, repeated_cnt=2),
>> repeated_fields(nelems=9, repeated_cnt=3)]
>
> is kinda an inverted array description where elements come first
> and then array type. I have a hard time imagining how search
> in such thing will work.
About searching, it will find the elements if index is 0. For index >=
1, it will find repeated_fields(), and redirect to the offset to an
offset at index 0. The pseudo code looks like
field = bsearch(all_fields, offset..);
while (field && is_repeated_fields(field)) {
offset = redirect_offset(offset, field);
field =
bsearch(&all_fields[field.index-field.repeated_cnt..field.index], offset);
}
>
> Also consider that arrays won't be huge, since bpf prog
> can only access them with a constant offset.
> Even array[NR_CPUS] is unlikely, since indexing into it
> with a variable index won't be possible.
I also got a similar opinion from Andrii in another message.
So, I will move to flatten solution.
Thank you for your feedback.
next prev parent reply other threads:[~2024-04-25 17:08 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-12 21:08 [PATCH bpf-next v2 00/11] Enable BPF programs to declare arrays of kptr, bpf_rb_root, and bpf_list_head Kui-Feng Lee
2024-04-12 21:08 ` [PATCH bpf-next v2 01/11] bpf: Remove unnecessary checks on the offset of btf_field Kui-Feng Lee
2024-04-12 21:08 ` [PATCH bpf-next v2 02/11] bpf: Remove unnecessary call to btf_field_type_size() Kui-Feng Lee
2024-04-12 21:08 ` [PATCH bpf-next v2 03/11] bpf: Add nelems to struct btf_field_info and btf_field Kui-Feng Lee
2024-04-12 21:08 ` [PATCH bpf-next v2 04/11] bpf: initialize/free array of btf_field(s) Kui-Feng Lee
2024-04-12 21:08 ` [PATCH bpf-next v2 05/11] bpf: Find btf_field with the knowledge of arrays Kui-Feng Lee
2024-04-12 21:08 ` [PATCH bpf-next v2 06/11] bpf: check_map_access() " Kui-Feng Lee
2024-04-12 21:08 ` [PATCH bpf-next v2 07/11] bpf: check_map_kptr_access() compute the offset from the reg state Kui-Feng Lee
2024-04-12 21:08 ` [PATCH bpf-next v2 08/11] bpf: Enable and verify btf_field arrays Kui-Feng Lee
2024-04-12 21:08 ` [PATCH bpf-next v2 09/11] selftests/bpf: Test global kptr arrays Kui-Feng Lee
2024-04-12 21:08 ` [PATCH bpf-next v2 10/11] selftests/bpf: Test global bpf_rb_root arrays Kui-Feng Lee
2024-04-12 21:08 ` [PATCH bpf-next v2 11/11] selftests/bpf: Test global bpf_list_head arrays Kui-Feng Lee
2024-04-18 3:30 ` [PATCH bpf-next v2 00/11] Enable BPF programs to declare arrays of kptr, bpf_rb_root, and bpf_list_head Alexei Starovoitov
2024-04-18 4:31 ` Kui-Feng Lee
2024-04-18 5:11 ` Alexei Starovoitov
2024-04-18 6:07 ` Kui-Feng Lee
2024-04-18 14:53 ` Alexei Starovoitov
2024-04-18 18:27 ` Kui-Feng Lee
2024-04-19 18:36 ` Kui-Feng Lee
2024-04-23 2:45 ` Kui-Feng Lee
2024-04-23 2:54 ` Kui-Feng Lee
2024-04-24 20:09 ` Alexei Starovoitov
2024-04-24 22:32 ` Kui-Feng Lee
2024-04-24 22:34 ` Kui-Feng Lee
2024-04-24 22:36 ` Kui-Feng Lee
2024-04-25 0:49 ` Alexei Starovoitov
2024-04-25 17:08 ` Kui-Feng Lee [this message]
2024-04-25 0:48 ` Andrii Nakryiko
2024-04-25 17:09 ` 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=5b6f154e-3317-4ba0-af50-6d48ae08be19@gmail.com \
--to=sinquersw@gmail.com \
--cc=alexei.starovoitov@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=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