All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Delyan Kratunov <delyank@fb.com>
Cc: Yonghong Song <yhs@fb.com>,
	"daniel@iogearbox.net" <daniel@iogearbox.net>,
	"ast@kernel.org" <ast@kernel.org>,
	"andrii@kernel.org" <andrii@kernel.org>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v1 0/3] Avoid typedef size mismatches in skeletons
Date: Thu, 10 Feb 2022 16:17:11 -0800	[thread overview]
Message-ID: <CAADnVQJmx39YO-ZU=Y12sED2pM-FadKDnqOo2n+L6AewZCai1A@mail.gmail.com> (raw)
In-Reply-To: <b475429b1521d83c2b538f83b9013c9ee9b13d10.camel@fb.com>

On Thu, Feb 10, 2022 at 3:59 PM Delyan Kratunov <delyank@fb.com> wrote:
>
> On Thu, 2022-02-10 at 15:14 -0800, Alexei Starovoitov wrote:
> > So adding
> > _Static_assert(sizeof(type_in_skel) == const_size_from_kernel);
> > to skel.h would force users to pick types that are the same
> > both in bpf prog and in corresponding user space part.
>
> I'm not sure users have this much control over the definition of the types in
> their program though. If a kernel and uapi typedef differ in size, this approach
> would force the user to use kernel types for the entire program.
>
> If, for example, pid_t is a different size in glibc and the kernel, it would
> force you out of using any glibc functions taking pid_t (and potentially all of
> glibc depending on how entangled the headers are).

pid_t is a great example, since its meaning is different
in kernel and in user space.
One is thread and another is process.

static_assert will catch such issues and will force
users to pick u64 and think through the type
conversions. In kernel from pid_t -> u64 in bpf prog,
and in user space pid_t -> u64 in skel.
That would be an explicit action by users that hopefully
make them think about the differences in size and semantics.

> By normalizing to stdint types, we're saying that the contract represented by
> the skel does not operate with either uapi or kernel types and it's up to you to
> ensure you use the right one (or mix and match, if you can). It feels
> fundamentally more permissive to different types of situations than forcing the
> skel user to only use kernel types or refactor their program to isolate the
> kernel type leakage to only the compilation unit using the skel.

static_assert will force users to use compatible types, not kernel types.

      reply	other threads:[~2022-02-11  0:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-10  0:36 [PATCH bpf-next v1 0/3] Avoid typedef size mismatches in skeletons Delyan Kratunov
2022-02-10  0:36 ` [PATCH bpf-next v1 3/3] selftests/bpf: add test case for userspace and bpf type size mismatch Delyan Kratunov
2022-02-10 22:44   ` Andrii Nakryiko
2022-02-10 23:48     ` Delyan Kratunov
2022-02-10  0:36 ` [PATCH bpf-next v1 2/3] bpftool: skeleton uses explicitly sized ints Delyan Kratunov
2022-02-10 22:42   ` Andrii Nakryiko
2022-02-10 23:45     ` Delyan Kratunov
2022-02-10  0:36 ` [PATCH bpf-next v1 1/3] libbpf: btf_dump can produce " Delyan Kratunov
2022-02-10 22:35   ` Andrii Nakryiko
2022-02-10 23:40     ` Delyan Kratunov
2022-02-10 22:18 ` [PATCH bpf-next v1 0/3] Avoid typedef size mismatches in skeletons Yonghong Song
2022-02-10 22:48   ` Andrii Nakryiko
2022-02-10 22:51 ` Yonghong Song
2022-02-10 23:14   ` Alexei Starovoitov
2022-02-10 23:59     ` Delyan Kratunov
2022-02-11  0:17       ` Alexei Starovoitov [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='CAADnVQJmx39YO-ZU=Y12sED2pM-FadKDnqOo2n+L6AewZCai1A@mail.gmail.com' \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=delyank@fb.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.