BPF List
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@fb.com>,
	"daniel@iogearbox.net" <daniel@iogearbox.net>,
	Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 08/11] libbpf: support BTF dedup of split BTFs
Date: Tue, 3 Nov 2020 05:59:13 +0000	[thread overview]
Message-ID: <4EEF76DA-2E9F-4B09-BD31-817148CDC445@fb.com> (raw)
In-Reply-To: <CAEf4BzaxLMH-ZN+FEhg54J3quGTAHZVg143KWSsD0PFEM5E3yg@mail.gmail.com>



> On Nov 2, 2020, at 9:25 PM, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
> 
> On Mon, Nov 2, 2020 at 6:49 PM Song Liu <songliubraving@fb.com> wrote:
>> 
>> 
>> 
>>> On Oct 28, 2020, at 5:58 PM, Andrii Nakryiko <andrii@kernel.org> wrote:
>>> 
>>> Add support for deduplication split BTFs. When deduplicating split BTF, base
>>> BTF is considered to be immutable and can't be modified or adjusted. 99% of
>>> BTF deduplication logic is left intact (module some type numbering adjustments).
>>> There are only two differences.
>>> 
>>> First, each type in base BTF gets hashed (expect VAR and DATASEC, of course,
>>> those are always considered to be self-canonical instances) and added into
>>> a table of canonical table candidates. Hashing is a shallow, fast operation,
>>> so mostly eliminates the overhead of having entire base BTF to be a part of
>>> BTF dedup.
>>> 
>>> Second difference is very critical and subtle. While deduplicating split BTF
>>> types, it is possible to discover that one of immutable base BTF BTF_KIND_FWD
>>> types can and should be resolved to a full STRUCT/UNION type from the split
>>> BTF part.  This is, obviously, can't happen because we can't modify the base
>>> BTF types anymore. So because of that, any type in split BTF that directly or
>>> indirectly references that newly-to-be-resolved FWD type can't be considered
>>> to be equivalent to the corresponding canonical types in base BTF, because
>>> that would result in a loss of type resolution information. So in such case,
>>> split BTF types will be deduplicated separately and will cause some
>>> duplication of type information, which is unavoidable.
>>> 
>>> With those two changes, the rest of the algorithm manages to deduplicate split
>>> BTF correctly, pointing all the duplicates to their canonical counter-parts in
>>> base BTF, but also is deduplicating whatever unique types are present in split
>>> BTF on their own.
>>> 
>>> Also, theoretically, split BTF after deduplication could end up with either
>>> empty type section or empty string section. This is handled by libbpf
>>> correctly in one of previous patches in the series.
>>> 
>>> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
>> 
>> Acked-by: Song Liu <songliubraving@fb.com>
>> 
>> With some nits:
>> 
>>> ---
>> 
>> [...]
>> 
>>> 
>>>      /* remap string offsets */
>>>      err = btf_for_each_str_off(d, strs_dedup_remap_str_off, d);
>>> @@ -3553,6 +3582,63 @@ static bool btf_compat_fnproto(struct btf_type *t1, struct btf_type *t2)
>>>      return true;
>>> }
>>> 
>> 
>> An overview comment about bpf_deup_prep() will be great.
> 
> ok
> 
>> 
>>> +static int btf_dedup_prep(struct btf_dedup *d)
>>> +{
>>> +     struct btf_type *t;
>>> +     int type_id;
>>> +     long h;
>>> +
>>> +     if (!d->btf->base_btf)
>>> +             return 0;
>>> +
>>> +     for (type_id = 1; type_id < d->btf->start_id; type_id++)
>>> +     {
>> 
>> Move "{" to previous line?
> 
> yep, my bad
> 
>> 
>>> +             t = btf_type_by_id(d->btf, type_id);
>>> +
>>> +             /* all base BTF types are self-canonical by definition */
>>> +             d->map[type_id] = type_id;
>>> +
>>> +             switch (btf_kind(t)) {
>>> +             case BTF_KIND_VAR:
>>> +             case BTF_KIND_DATASEC:
>>> +                     /* VAR and DATASEC are never hash/deduplicated */
>>> +                     continue;
>> 
>> [...]
>> 
>>>      /* we are going to reuse hypot_map to store compaction remapping */
>>>      d->hypot_map[0] = 0;
>>> -     for (i = 1; i <= d->btf->nr_types; i++)
>>> -             d->hypot_map[i] = BTF_UNPROCESSED_ID;
>>> +     /* base BTF types are not renumbered */
>>> +     for (id = 1; id < d->btf->start_id; id++)
>>> +             d->hypot_map[id] = id;
>>> +     for (i = 0, id = d->btf->start_id; i < d->btf->nr_types; i++, id++)
>>> +             d->hypot_map[id] = BTF_UNPROCESSED_ID;
>> 
>> We don't really need i in the loop, shall we just do
>>        for (id = d->btf->start_id; id < d->btf->start_id + d->btf->nr_types; id++)
>> ?
>> 
> 
> I prefer the loop with i iterating over the count of types, it seems
> more "obviously correct". For simple loop like this I could do
> 
> for (i = 0; i < d->btf->nr_types; i++)
>    d->hypot_map[d->start_id + i] = ...;
> 
> But for the more complicated one below I found that maintaining id as
> part of the for loop control block is a bit cleaner. So I just stuck
> to the consistent pattern across all of them.

How about 

	for (i = 0; i < d->btf->nr_types; i++) {
		id = d->start_id + i;
		...
?

I would expect for loop with two loop variable to do some tricks, like two 
termination conditions, or another conditional id++ somewhere in the loop. 

Thanks,
Song


  reply	other threads:[~2020-11-03  5:59 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
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 [this message]
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=4EEF76DA-2E9F-4B09-BD31-817148CDC445@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