From: Song Liu <songliubraving@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
Networking <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 04/11] libbpf: implement basic split BTF support
Date: Tue, 3 Nov 2020 05:41:32 +0000 [thread overview]
Message-ID: <80AB5729-CBCA-4306-9048-8E8114EB0A66@fb.com> (raw)
In-Reply-To: <CAEf4BzanQsEopXA7cGQi51hf_Q0hNb7NUTvtnkD8xg9AHoU9Ng@mail.gmail.com>
> On Nov 2, 2020, at 9:02 PM, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>
> On Mon, Nov 2, 2020 at 3:24 PM Song Liu <songliubraving@fb.com> wrote:
>>
>>
>>
>>> On Oct 28, 2020, at 5:58 PM, Andrii Nakryiko <andrii@kernel.org> wrote:
>>>
>>
>> [...]
>>
>>>
>>> BTF deduplication is not yet supported for split BTF and support for it will
>>> be added in separate patch.
>>>
>>> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
>>
>> Acked-by: Song Liu <songliubraving@fb.com>
>>
>> With a couple nits:
>>
>>> ---
>>> tools/lib/bpf/btf.c | 205 ++++++++++++++++++++++++++++++---------
>>> tools/lib/bpf/btf.h | 8 ++
>>> tools/lib/bpf/libbpf.map | 9 ++
>>> 3 files changed, 175 insertions(+), 47 deletions(-)
>>>
>>> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
>>> index db9331fea672..20c64a8441a8 100644
>>> --- a/tools/lib/bpf/btf.c
>>> +++ b/tools/lib/bpf/btf.c
>>> @@ -78,10 +78,32 @@ struct btf {
>>> void *types_data;
>>> size_t types_data_cap; /* used size stored in hdr->type_len */
>>>
>>> - /* type ID to `struct btf_type *` lookup index */
>>> + /* type ID to `struct btf_type *` lookup index
>>> + * type_offs[0] corresponds to the first non-VOID type:
>>> + * - for base BTF it's type [1];
>>> + * - for split BTF it's the first non-base BTF type.
>>> + */
>>> __u32 *type_offs;
>>> size_t type_offs_cap;
>>> + /* number of types in this BTF instance:
>>> + * - doesn't include special [0] void type;
>>> + * - for split BTF counts number of types added on top of base BTF.
>>> + */
>>> __u32 nr_types;
>>
>> This is a little confusing. Maybe add a void type for every split BTF?
>
> Agree about being a bit confusing. But I don't want VOID in every BTF,
> that seems sloppy (there's no continuity). I'm currently doing similar
> changes on kernel side, and so far everything also works cleanly with
> start_id == 0 && nr_types including VOID (for base BTF), and start_id
> == base_btf->nr_type && nr_types has all the added types (for split
> BTF). That seems a bit more straightforward, so I'll probably do that
> here as well (unless I'm missing something, I'll double check).
That sounds good.
>
>>
>>> + /* if not NULL, points to the base BTF on top of which the current
>>> + * split BTF is based
>>> + */
>>
>> [...]
>>
>>>
>>> @@ -252,12 +274,20 @@ static int btf_parse_str_sec(struct btf *btf)
>>> const char *start = btf->strs_data;
>>> const char *end = start + btf->hdr->str_len;
>>>
>>> - if (!hdr->str_len || hdr->str_len - 1 > BTF_MAX_STR_OFFSET ||
>>> - start[0] || end[-1]) {
>>> - pr_debug("Invalid BTF string section\n");
>>> - return -EINVAL;
>>> + if (btf->base_btf) {
>>> + if (hdr->str_len == 0)
>>> + return 0;
>>> + if (hdr->str_len - 1 > BTF_MAX_STR_OFFSET || end[-1]) {
>>> + pr_debug("Invalid BTF string section\n");
>>> + return -EINVAL;
>>> + }
>>> + } else {
>>> + if (!hdr->str_len || hdr->str_len - 1 > BTF_MAX_STR_OFFSET ||
>>> + start[0] || end[-1]) {
>>> + pr_debug("Invalid BTF string section\n");
>>> + return -EINVAL;
>>> + }
>>> }
>>> -
>>> return 0;
>>
>> I found this function a little difficult to follow. Maybe rearrange it as
>>
>> /* too long, or not \0 terminated */
>> if (hdr->str_len - 1 > BTF_MAX_STR_OFFSET || end[-1])
>> goto err_out;
>
> this won't work, if str_len == 0. Both str_len - 1 will underflow, and
> end[-1] will be reading garbage
>
> How about this:
>
> if (btf->base_btf && hdr->str_len == 0)
> return 0;
>
> if (!hdr->str_len || hdr->str_len - 1 > BTF_MAX_STR_OFFSET || end[-1])
> return -EINVAL;
>
> if (!btf->base_btf && start[0])
> return -EINVAL;
>
> return 0;
>
> This seems more straightforward, right?
Yeah, I like this version. BTW, short comment for each condition will be
helpful.
next prev parent reply other threads:[~2020-11-03 5:41 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 0:58 [PATCH bpf-next 00/11] libbpf: split BTF support Andrii Nakryiko
2020-10-29 0:58 ` [PATCH bpf-next 01/11] libbpf: factor out common operations in BTF writing APIs Andrii Nakryiko
2020-10-30 0:36 ` Song Liu
2020-10-29 0:58 ` [PATCH bpf-next 02/11] selftest/bpf: relax btf_dedup test checks Andrii Nakryiko
2020-10-30 16:43 ` Song Liu
2020-10-30 18:44 ` Andrii Nakryiko
2020-10-30 22:30 ` Song Liu
2020-10-29 0:58 ` [PATCH bpf-next 03/11] libbpf: unify and speed up BTF string deduplication Andrii Nakryiko
2020-10-30 23:32 ` Song Liu
2020-11-03 4:51 ` Andrii Nakryiko
2020-11-03 4:59 ` Alexei Starovoitov
2020-11-03 6:01 ` Andrii Nakryiko
2020-10-29 0:58 ` [PATCH bpf-next 04/11] libbpf: implement basic split BTF support Andrii Nakryiko
2020-11-02 23:23 ` Song Liu
2020-11-03 5:02 ` Andrii Nakryiko
2020-11-03 5:41 ` Song Liu [this message]
2020-11-04 23:51 ` Andrii Nakryiko
2020-10-29 0:58 ` [PATCH bpf-next 05/11] selftests/bpf: add split BTF basic test Andrii Nakryiko
2020-11-02 23:36 ` Song Liu
2020-11-03 5:10 ` Andrii Nakryiko
2020-10-29 0:58 ` [PATCH bpf-next 06/11] selftests/bpf: add checking of raw type dump in BTF writer APIs selftests Andrii Nakryiko
2020-11-03 0:08 ` Song Liu
2020-11-03 5:14 ` Andrii Nakryiko
2020-10-29 0:58 ` [PATCH bpf-next 07/11] libbpf: fix BTF data layout checks and allow empty BTF Andrii Nakryiko
2020-11-03 0:51 ` Song Liu
2020-11-03 5:18 ` Andrii Nakryiko
2020-11-03 5:44 ` Song Liu
2020-10-29 0:58 ` [PATCH bpf-next 08/11] libbpf: support BTF dedup of split BTFs Andrii Nakryiko
2020-11-03 2:49 ` Song Liu
2020-11-03 5:25 ` Andrii Nakryiko
2020-11-03 5:59 ` Song Liu
2020-11-03 6:31 ` Andrii Nakryiko
2020-11-03 17:15 ` Song Liu
2020-11-03 5:10 ` Alexei Starovoitov
2020-11-03 6:27 ` Andrii Nakryiko
2020-11-03 17:55 ` Alexei Starovoitov
2020-10-29 0:59 ` [PATCH bpf-next 09/11] libbpf: accomodate DWARF/compiler bug with duplicated identical arrays Andrii Nakryiko
2020-11-03 2:52 ` Song Liu
2020-10-29 0:59 ` [PATCH bpf-next 10/11] selftests/bpf: add split BTF dedup selftests Andrii Nakryiko
2020-11-03 5:35 ` Song Liu
2020-11-03 6:05 ` Andrii Nakryiko
2020-11-03 6:30 ` Song Liu
2020-10-29 0:59 ` [PATCH bpf-next 11/11] tools/bpftool: add bpftool support for split BTF Andrii Nakryiko
2020-11-03 6:03 ` Song Liu
2020-10-30 0:33 ` [PATCH bpf-next 00/11] libbpf: split BTF support Song Liu
2020-10-30 2:33 ` Andrii Nakryiko
2020-10-30 6:45 ` Song Liu
2020-10-30 12:04 ` Alan Maguire
2020-10-30 18:30 ` Andrii Nakryiko
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=80AB5729-CBCA-4306-9048-8E8114EB0A66@fb.com \
--to=songliubraving@fb.com \
--cc=Kernel-team@fb.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=netdev@vger.kernel.org \
/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