bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Matteo Croce <mcroce@linux.microsoft.com>,
	bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>
Subject: Re: [RFC bpf 2/2] btf: adapt relo_core for kernel compilation
Date: Fri, 17 Sep 2021 10:45:05 -0700	[thread overview]
Message-ID: <CAEf4BzaRuU5Zj3h1vRqjTf-vKghsYsLPdmJ+q7Knz9pGoBYyTA@mail.gmail.com> (raw)
In-Reply-To: <CAADnVQ+j2zZecHSuc46HZ=wYmwqFEqDuO=xgfirguKKUWAJCBg@mail.gmail.com>

On Thu, Sep 16, 2021 at 9:12 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Thu, Sep 16, 2021 at 6:22 PM Matteo Croce <mcroce@linux.microsoft.com> wrote:
> >
> > How can we share the helpers source too instead of duplicating it?
>
> Ideally. Yes.
> Andrii pointed out that libbpf's btf.h is installed,
> so it's part of libbpf api.
> Therefore it's safer to rename kernel helpers with equivalent meaning
> instead of risking libbpf renames.
>
> >
> > Indeed, I found a small difference between the userspace and kernel code.
> >
> > In tools/lib/bpf/btf.h we have btf_is_mod() which returns true for
> > { BTF_KIND_VOLATILE, BTF_KIND_CONST, BTF_KIND_RESTRICT },
> > while in kernel/bpf/btf.c we have btf_type_is_modifier() which returns
> > true also for BTF_KIND_TYPEDEF.
> >
> > Which is the right one?
>
> btf_is_mod() is part of libbpf btf.h, so we cannot change it.
> btf_type_is_modifier() is kernel internal helper.
> It doesn't need to change and doesn't need to match.

libbpf's btf_is_mod() is not including typedef because there are cases
where typedef shouldn't be skipped. I see one such case in btf_dump.c.
So typedef is certainly not just a modifier from libbpf's point of
view. Kernel doesn't care, though, which is why this difference
exists.

> The equivalent helpers are
> skip_mods_and_typedefs() in the libbpf
> and
> btf_type_skip_modifiers() in the kernel.
> In this case it's probably better to search-and-replace in libbpf.

27 uses in kernel vs 42 in libbpf, so, technically, libbpf should win.
I don't mind mass-renaming of internal helpers, I'd just prefer the
name of the function to reflect the actual logic (where as I pointed
out above, libbpf knows and cares about the distinction between
modifiers (const, volatile, restrict) and typedef). Should we rename
both to btf_type_skip_mods_and_typedefs() or
btf_type_skip_mods_typedefs()?

BTW, kernel might need to start caring about typedefs separately from
modifiers in the context of btf_tag work by Yonghong. Typedefs might
have btf_tags associated with them, I think.

> In most other cases kernel search-and-replace will be necessary.
> For example:
> btf_type_vlen->btf_vlen
> btf_type_member->btf_members

      reply	other threads:[~2021-09-17 17:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-09 13:31 [RFC bpf 0/2] bpf: kernel CO-RE relocation Matteo Croce
2021-09-09 13:31 ` [RFC bpf 1/2] btf: copy relo_core from tools to kernel Matteo Croce
2021-09-09 13:31 ` [RFC bpf 2/2] btf: adapt relo_core for kernel compilation Matteo Croce
2021-09-09 18:23   ` Alexei Starovoitov
2021-09-17  1:21     ` Matteo Croce
2021-09-17  4:12       ` Alexei Starovoitov
2021-09-17 17:45         ` Andrii Nakryiko [this message]

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=CAEf4BzaRuU5Zj3h1vRqjTf-vKghsYsLPdmJ+q7Knz9pGoBYyTA@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=acme@kernel.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=mcroce@linux.microsoft.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;
as well as URLs for NNTP newsgroup(s).