From: Alan Maguire <alan.maguire@oracle.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: andrii@kernel.org, jolsa@kernel.org, acme@redhat.com,
quentin@isovalent.com, eddyz87@gmail.com, mykolal@fb.com,
ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev,
song@kernel.org, yonghong.song@linux.dev,
john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com,
haoluo@google.com, houtao1@huawei.com, bpf@vger.kernel.org,
masahiroy@kernel.org, mcgrof@kernel.org, nathan@kernel.org
Subject: Re: [PATCH v5 bpf-next 8/9] libbpf,bpf: share BTF relocate-related code with kernel
Date: Sun, 2 Jun 2024 14:42:10 +0100 [thread overview]
Message-ID: <95a78cf9-c358-4822-b052-65cae1d5391a@oracle.com> (raw)
In-Reply-To: <CAEf4BzZ4Z38GspkSi8QjdGTfwFvNZ3aVPjGjU-6XQte+dKwWVQ@mail.gmail.com>
On 01/06/2024 02:59, Andrii Nakryiko wrote:
> On Fri, May 31, 2024 at 12:04 PM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
>>
>> On Tue, May 28, 2024 at 5:25 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>>>
>>> Share relocation implementation with the kernel. As part of this,
>>> we also need the type/string visitation functions so add them to a
>>> btf_common.c file that also gets shared with the kernel. Relocation
>>> code in kernel and userspace is identical save for the impementation
>>> of the reparenting of split BTF to the relocated base BTF and
>>> retrieval of BTF header from "struct btf"; these small functions
>>> need separate user-space and kernel implementations.
>>>
>>> One other wrinkle on the kernel side is we have to map .BTF.ids in
>>> modules as they were generated with the type ids used at BTF encoding
>>> time. btf_relocate() optionally returns an array mapping from old BTF
>>> ids to relocated ids, so we use that to fix up these references where
>>> needed for kfuncs.
>>>
>>> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
>>> ---
>>> include/linux/btf.h | 45 ++++++++++
>>> kernel/bpf/Makefile | 10 ++-
>>> kernel/bpf/btf.c | 168 +++++++++++++++++++++++++----------
>>> tools/lib/bpf/Build | 2 +-
>>> tools/lib/bpf/btf.c | 130 ---------------------------
>>> tools/lib/bpf/btf_iter.c | 143 +++++++++++++++++++++++++++++
>>> tools/lib/bpf/btf_relocate.c | 23 +++++
>>> 7 files changed, 344 insertions(+), 177 deletions(-)
>>> create mode 100644 tools/lib/bpf/btf_iter.c
>>>
>>
>> [...]
>>
>>> +static inline struct btf_decl_tag *btf_decl_tag(const struct btf_type *t)
>>> +{
>>> + return (struct btf_decl_tag *)(t + 1);
>>> +}
>>> +
>>> static inline int btf_id_cmp_func(const void *a, const void *b)
>>> {
>>> const int *pa = a, *pb = b;
>>> @@ -515,9 +528,17 @@ static inline const struct bpf_struct_ops_desc *bpf_struct_ops_find(struct btf *
>>> }
>>> #endif
>>>
>>> +typedef int (*type_id_visit_fn)(__u32 *type_id, void *ctx);
>>> +typedef int (*str_off_visit_fn)(__u32 *str_off, void *ctx);
>>> +
>>
>> let me take a quick stab at implementing type/str field iterator in
>> libbpf. If I don't get stuck anywhere, maybe you can just rebase on
>> that and avoid the callback hell and the need for this
>> callback-vs-iter churn in the kernel code as well
>>
>
> Sent it out as one RFC patch (which unfortunately makes it harder to
> see iterator logic, sorry; but I ran out of time to split it
> properly), see [0].
> It is especially nice when per-field logic is very simple (like
> bpftool's gen.c logic, where we just remap ID). Please take a look and
> let me know what you think.
>
> [0] https://patchwork.kernel.org/project/netdevbpf/patch/20240601014505.3443241-1-andrii@kernel.org/
>
thanks for this! Looking now...
>>> #ifdef CONFIG_BPF_SYSCALL
>>> const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id);
>>> +void btf_set_base_btf(struct btf *btf, const struct btf *base_btf);
>>> +int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **map_ids);
>>> +int btf_type_visit_type_ids(struct btf_type *t, type_id_visit_fn visit, void *ctx);
>>> +int btf_type_visit_str_offs(struct btf_type *t, str_off_visit_fn visit, void *ctx);
>>> const char *btf_name_by_offset(const struct btf *btf, u32 offset);
>>> +const char *btf_str_by_offset(const struct btf *btf, u32 offset);
>>> struct btf *btf_parse_vmlinux(void);
>>> struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog);
>>> u32 *btf_kfunc_id_set_contains(const struct btf *btf, u32 kfunc_btf_id,
>>
>> [...]
next prev parent reply other threads:[~2024-06-02 13:42 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-28 12:23 [PATCH v5 bpf-next 0/9] bpf: support resilient split BTF Alan Maguire
2024-05-28 12:24 ` [PATCH v5 bpf-next 1/9] libbpf: add btf__distill_base() creating split BTF with distilled base BTF Alan Maguire
2024-05-30 19:58 ` Eduard Zingerman
2024-05-28 12:24 ` [PATCH v5 bpf-next 2/9] selftests/bpf: test distilled base, split BTF generation Alan Maguire
2024-05-30 20:23 ` Eduard Zingerman
2024-05-28 12:24 ` [PATCH v5 bpf-next 3/9] libbpf: split BTF relocation Alan Maguire
2024-05-31 2:22 ` Eduard Zingerman
2024-05-31 15:38 ` Alan Maguire
2024-05-31 18:44 ` Andrii Nakryiko
2024-06-01 7:56 ` Eduard Zingerman
2024-06-02 13:47 ` Alan Maguire
2024-05-31 18:21 ` Andrii Nakryiko
2024-05-28 12:24 ` [PATCH v5 bpf-next 4/9] selftests/bpf: extend distilled BTF tests to cover " Alan Maguire
2024-05-31 2:23 ` Eduard Zingerman
2024-05-28 12:24 ` [PATCH v5 bpf-next 5/9] libbpf: make btf_parse_elf process .BTF.base transparently Alan Maguire
2024-05-31 18:57 ` Andrii Nakryiko
2024-06-01 8:04 ` Eduard Zingerman
2024-05-28 12:24 ` [PATCH v5 bpf-next 6/9] resolve_btfids: handle presence of .BTF.base section Alan Maguire
2024-05-28 12:24 ` [PATCH v5 bpf-next 7/9] module, bpf: store BTF base pointer in struct module Alan Maguire
2024-05-28 18:27 ` Luis Chamberlain
2024-05-28 12:24 ` [PATCH v5 bpf-next 8/9] libbpf,bpf: share BTF relocate-related code with kernel Alan Maguire
2024-05-31 9:34 ` Eduard Zingerman
2024-05-31 16:13 ` Alan Maguire
2024-05-31 19:04 ` Andrii Nakryiko
2024-06-01 1:59 ` Andrii Nakryiko
2024-06-02 13:42 ` Alan Maguire [this message]
2024-05-28 12:24 ` [PATCH v5 bpf-next 9/9] kbuild,bpf: add module-specific pahole flags for distilled base BTF Alan Maguire
2024-05-31 19:06 ` Andrii Nakryiko
2024-06-02 13:41 ` Alan Maguire
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=95a78cf9-c358-4822-b052-65cae1d5391a@oracle.com \
--to=alan.maguire@oracle.com \
--cc=acme@redhat.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=houtao1@huawei.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=masahiroy@kernel.org \
--cc=mcgrof@kernel.org \
--cc=mykolal@fb.com \
--cc=nathan@kernel.org \
--cc=quentin@isovalent.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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