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: Andrii Nakryiko <andriin@fb.com>, bpf <bpf@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Yonghong Song <yhs@fb.com>, Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH v4 bpf-next 02/14] libbpf: convert libbpf code to use new btf helpers
Date: Wed, 7 Aug 2019 12:59:53 -0700	[thread overview]
Message-ID: <CAEf4BzahxLWRVNcNWpba7_7CbbQgN8k0RU8Ya1XCK8j4rPQ0NQ@mail.gmail.com> (raw)
In-Reply-To: <20190807193011.g2zuaapc2uvvr4h6@ast-mbp>

On Wed, Aug 7, 2019 at 12:30 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Tue, Aug 06, 2019 at 10:37:54PM -0700, Andrii Nakryiko wrote:
> > Simplify code by relying on newly added BTF helper functions.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ..
> >
> > -     for (i = 0, vsi = (struct btf_var_secinfo *)(t + 1);
> > -          i < vars; i++, vsi++) {
> > +     for (i = 0, vsi = (void *)btf_var_secinfos(t); i < vars; i++, vsi++) {
>
> > +                     struct btf_member *m = (void *)btf_members(t);
> ...
> >               case BTF_KIND_ENUM: {
> > -                     struct btf_enum *m = (struct btf_enum *)(t + 1);
> > -                     __u16 vlen = BTF_INFO_VLEN(t->info);
> > +                     struct btf_enum *m = (void *)btf_enum(t);
> > +                     __u16 vlen = btf_vlen(t);
> ...
> >               case BTF_KIND_FUNC_PROTO: {
> > -                     struct btf_param *m = (struct btf_param *)(t + 1);
> > -                     __u16 vlen = BTF_INFO_VLEN(t->info);
> > +                     struct btf_param *m = (void *)btf_params(t);
> > +                     __u16 vlen = btf_vlen(t);
>
> So all of these 'void *' type hacks are only to drop const-ness ?

Yes.

> May be the helpers shouldn't be taking const then?
>

Probably not, because then we'll have much wider-spread problem of
casting const pointers into non-const when passing btf_type into
helpers.
I think const as a default is the right choice, because normally BTF
is immutable and btf__type_by_id is returning const pointer, etc.
That's typical and expected use-case. btf_dedup and BTF sanitization +
datasec size setting pieces are an exception that have to modify BTF
types in place before passing it to user.

So realistically I think we can just leave it as (void *), or I can do
explicit non-const type casts, or we can just not use helpers for
mutable cases. Do you have a preference?

  reply	other threads:[~2019-08-07 20:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-07  5:37 [PATCH v4 bpf-next 00/14] CO-RE offset relocations Andrii Nakryiko
2019-08-07  5:37 ` [PATCH v4 bpf-next 01/14] libbpf: add helpers for working with BTF types Andrii Nakryiko
2019-08-07 19:31   ` Alexei Starovoitov
2019-08-07 19:54     ` Andrii Nakryiko
2019-08-07  5:37 ` [PATCH v4 bpf-next 02/14] libbpf: convert libbpf code to use new btf helpers Andrii Nakryiko
2019-08-07 19:30   ` Alexei Starovoitov
2019-08-07 19:59     ` Andrii Nakryiko [this message]
2019-08-07 20:01       ` Alexei Starovoitov
2019-08-07 20:10         ` Andrii Nakryiko
2019-08-07  5:37 ` [PATCH v4 bpf-next 03/14] libbpf: add .BTF.ext offset relocation section loading Andrii Nakryiko
2019-08-07  5:37 ` [PATCH v4 bpf-next 04/14] libbpf: implement BPF CO-RE offset relocation algorithm Andrii Nakryiko
2019-08-07  5:37 ` [PATCH v4 bpf-next 05/14] selftests/bpf: add BPF_CORE_READ relocatable read macro Andrii Nakryiko
2019-08-07  5:37 ` [PATCH v4 bpf-next 06/14] selftests/bpf: add CO-RE relocs testing setup Andrii Nakryiko
2019-08-07  5:37 ` [PATCH v4 bpf-next 07/14] selftests/bpf: add CO-RE relocs struct flavors tests Andrii Nakryiko
2019-08-07  5:38 ` [PATCH v4 bpf-next 08/14] selftests/bpf: add CO-RE relocs nesting tests Andrii Nakryiko
2019-08-07  5:38 ` [PATCH v4 bpf-next 09/14] selftests/bpf: add CO-RE relocs array tests Andrii Nakryiko
2019-08-07  5:38 ` [PATCH v4 bpf-next 10/14] selftests/bpf: add CO-RE relocs enum/ptr/func_proto tests Andrii Nakryiko
2019-08-07  5:38 ` [PATCH v4 bpf-next 11/14] selftests/bpf: add CO-RE relocs modifiers/typedef tests Andrii Nakryiko
2019-08-07  5:38 ` [PATCH v4 bpf-next 12/14] selftests/bpf: add CO-RE relocs ptr-as-array tests Andrii Nakryiko
2019-08-07  5:38 ` [PATCH v4 bpf-next 13/14] selftests/bpf: add CO-RE relocs ints tests Andrii Nakryiko
2019-08-07  5:38 ` [PATCH v4 bpf-next 14/14] selftests/bpf: add CO-RE relocs misc tests 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=CAEf4BzahxLWRVNcNWpba7_7CbbQgN8k0RU8Ya1XCK8j4rPQ0NQ@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=yhs@fb.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).