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@iogearbox.net" <daniel@iogearbox.net>,
Kernel Team <Kernel-team@fb.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"rafael@kernel.org" <rafael@kernel.org>,
"jeyu@kernel.org" <jeyu@kernel.org>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v4 bpf-next 1/5] bpf: add in-kernel split BTF support
Date: Tue, 10 Nov 2020 20:14:54 +0000 [thread overview]
Message-ID: <E26C39E9-51C4-4E31-87AC-69CADE54A15F@fb.com> (raw)
In-Reply-To: <CAEf4BzYORuxNUvJDTe4cPvJ18HNhFDOuYGfLdUzuwHeddVLw6Q@mail.gmail.com>
> On Nov 10, 2020, at 10:31 AM, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>
> On Tue, Nov 10, 2020 at 9:50 AM Song Liu <songliubraving@fb.com> wrote:
>>
>>
>>
>>> On Nov 9, 2020, at 5:19 PM, Andrii Nakryiko <andrii@kernel.org> wrote:
>>>
>>> Adjust in-kernel BTF implementation to support a split BTF mode of operation.
>>> Changes are mostly mirroring libbpf split BTF changes, with the exception of
>>> start_id being 0 for in-kernel implementation due to simpler read-only mode.
>>>
>>> Otherwise, for split BTF logic, most of the logic of jumping to base BTF,
>>> where necessary, is encapsulated in few helper functions. Type numbering and
>>> string offset in a split BTF are logically continuing where base BTF ends, so
>>> most of the high-level logic is kept without changes.
>>>
>>> Type verification and size resolution is only doing an added resolution of new
>>> split BTF types and relies on already cached size and type resolution results
>>> in the base BTF.
>>>
>>> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
>>> ---
>>> kernel/bpf/btf.c | 171 +++++++++++++++++++++++++++++++++--------------
>>> 1 file changed, 119 insertions(+), 52 deletions(-)
>>>
>>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>>> index 6324de8c59f7..727c1c27053f 100644
>>> --- a/kernel/bpf/btf.c
>>> +++ b/kernel/bpf/btf.c
>>> @@ -203,12 +203,17 @@ struct btf {
>>> const char *strings;
>>> void *nohdr_data;
>>> struct btf_header hdr;
>>> - u32 nr_types;
>>> + u32 nr_types; /* includes VOID for base BTF */
>>> u32 types_size;
>>> u32 data_size;
>>> refcount_t refcnt;
>>> u32 id;
>>> struct rcu_head rcu;
>>> +
>>> + /* split BTF support */
>>> + struct btf *base_btf;
>>> + u32 start_id; /* first type ID in this BTF (0 for base BTF) */
>>> + u32 start_str_off; /* first string offset (0 for base BTF) */
>>> };
>>>
>>> enum verifier_phase {
>>> @@ -449,14 +454,27 @@ static bool btf_type_is_datasec(const struct btf_type *t)
>>> return BTF_INFO_KIND(t->info) == BTF_KIND_DATASEC;
>>> }
>>>
>>> +static u32 btf_nr_types_total(const struct btf *btf)
>>> +{
>>> + u32 total = 0;
>>> +
>>> + while (btf) {
>>> + total += btf->nr_types;
>>> + btf = btf->base_btf;
>>> + }
>>> +
>>> + return total;
>>> +}
>>> +
>>> s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind)
>>> {
>>> const struct btf_type *t;
>>> const char *tname;
>>> - u32 i;
>>> + u32 i, total;
>>>
>>> - for (i = 1; i <= btf->nr_types; i++) {
>>> - t = btf->types[i];
>>> + total = btf_nr_types_total(btf);
>>> + for (i = 1; i < total; i++) {
>>> + t = btf_type_by_id(btf, i);
>>> if (BTF_INFO_KIND(t->info) != kind)
>>> continue;
>>>
>>> @@ -599,8 +617,14 @@ static const struct btf_kind_operations *btf_type_ops(const struct btf_type *t)
>>>
>>> static bool btf_name_offset_valid(const struct btf *btf, u32 offset)
>>> {
>>> - return BTF_STR_OFFSET_VALID(offset) &&
>>> - offset < btf->hdr.str_len;
>>> + if (!BTF_STR_OFFSET_VALID(offset))
>>> + return false;
>>> +
>>> + while (offset < btf->start_str_off)
>>> + btf = btf->base_btf;
>>
>> Do we need "if (!btf) return false;" in the while loop? (and some other loops below)
>
> No, because for base btf start_str_off and start_type_id are always
> zero, so loop condition is always false.
Ah, I misread the code. Thanks for the explanation.
Acked-by: Song Liu <songliubraving@fb.com>
next prev parent reply other threads:[~2020-11-10 20:15 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-10 1:19 [PATCH v4 bpf-next 0/5] Integrate kernel module BTF support Andrii Nakryiko
2020-11-10 1:19 ` [PATCH v4 bpf-next 1/5] bpf: add in-kernel split " Andrii Nakryiko
2020-11-10 17:49 ` Song Liu
2020-11-10 18:31 ` Andrii Nakryiko
2020-11-10 20:14 ` Song Liu [this message]
2020-11-10 1:19 ` [PATCH v4 bpf-next 2/5] bpf: assign ID to vmlinux BTF and return extra info for BTF in GET_OBJ_INFO Andrii Nakryiko
2020-11-10 20:24 ` Song Liu
2020-11-10 1:19 ` [PATCH v4 bpf-next 3/5] kbuild: build kernel module BTFs if BTF is enabled and pahole supports it Andrii Nakryiko
2020-11-11 1:04 ` Song Liu
2020-11-16 19:55 ` Allan, Bruce W
2020-11-16 20:34 ` Andrii Nakryiko
2020-11-16 21:24 ` Jakub Kicinski
2020-11-16 22:35 ` Andrii Nakryiko
2021-11-26 15:16 ` Fabian Grünbichler
2021-12-08 0:08 ` Andrii Nakryiko
2020-11-17 3:44 ` David Ahern
2020-11-10 1:19 ` [PATCH v4 bpf-next 4/5] bpf: load and verify kernel module BTFs Andrii Nakryiko
2020-11-11 7:11 ` kernel test robot
2020-11-11 10:13 ` Jessica Yu
2020-11-11 20:11 ` Andrii Nakryiko
2020-11-13 10:31 ` Jessica Yu
2020-11-13 18:54 ` Andrii Nakryiko
2020-11-10 1:19 ` [PATCH v4 bpf-next 5/5] tools/bpftool: add support for in-kernel and named BTF in `btf show` Andrii Nakryiko
2020-11-11 1:15 ` Song Liu
2020-11-11 4:19 ` Andrii Nakryiko
2020-11-11 7:44 ` Song Liu
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=E26C39E9-51C4-4E31-87AC-69CADE54A15F@fb.com \
--to=songliubraving@fb.com \
--cc=Kernel-team@fb.com \
--cc=acme@redhat.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=gregkh@linuxfoundation.org \
--cc=jeyu@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rafael@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;
as well as URLs for NNTP newsgroup(s).