bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: "Daniel Borkmann" <daniel@iogearbox.net>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Alexei Starovoitov" <alexei.starovoitov@gmail.com>,
	"Hangbin Liu" <haliu@redhat.com>,
	"David Ahern" <dsahern@gmail.com>,
	"Stephen Hemminger" <stephen@networkplumber.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Martin KaFai Lau" <kafai@fb.com>,
	"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
	"David Miller" <davem@davemloft.net>,
	"Jesper Dangaard Brouer" <brouer@redhat.com>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	"Jiri Benc" <jbenc@redhat.com>,
	"Andrii Nakryiko" <andrii@kernel.org>
Subject: Re: [PATCHv3 iproute2-next 0/5] iproute2: add libbpf support
Date: Wed, 4 Nov 2020 12:43:38 -0800	[thread overview]
Message-ID: <CAEf4BzY2pAaEmv_x_nGQC83373ZWUuNv-wcYRye+vfZ3Fa2qbw@mail.gmail.com> (raw)
In-Reply-To: <20201104111708.0595e2a3@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>

On Wed, Nov 4, 2020 at 11:17 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Wed, 4 Nov 2020 14:12:47 +0100 Daniel Borkmann wrote:
> > If we would have done lib/bpf.c as a dynamic library back then, we wouldn't be
> > where we are today since users might be able to start consuming BPF functionality
> > just now, don't you agree? This was an explicit design choice back then for exactly
> > this reason. If we extend lib/bpf.c or import libbpf one way or another then there
> > is consistency across distros and users would be able to consume it in a predictable
> > way starting from next major releases. And you could start making this assumption
> > on all major distros in say, 3 months from now. The discussion is somehow focused
> > on the PoV of /a/ distro which is all nice and good, but the ones consuming the
> > loader shipping software /across/ distros are users writing BPF progs, all I'm
> > trying to say is that the _user experience_ should be the focus of this discussion
> > and right now we're trying hard making it rather painful for them to consume it.

This! Thanks, Daniel, for stating it very explicitly. Earlier I
mentioned iproute2 code simplification if using submodules, but that's
just a nice by-product, not the goal, so I'll just ignore that. I'll
try to emphasize the end user experience though.

What users writing BPF programs can expect from iproute2 in terms of
available BPF features is what matters. And by not enforcing a
specific minimal libbpf version, iproute2 version doesn't matter all
that much, because libbpf version that iproute2 ends up linking
against might be very old.

There was a lot of talk about API stability and backwards
compatibility. Libbpf has had a stable API and ABI for at least 1.5
years now and is very conscious about that when adding or extending
new APIs. That's not even a factor in me arguing for submodules. I'll
give a few specific examples of libbpf API not changing at all, but
how end user experience gets tremendously better.

Some of the most important APIs of libbpf are, arguably,
bpf_object__open() and bpf_object__load(). They accept a BPF ELF file,
do some preprocessing and in the end load BPF instructions into the
kernel for verification. But while API doesn't change across libbpf
versions, BPF-side code features supported changes quite a lot.

1. BTF sanitization. Newer versions of clang would emit a richer set
of BTF type information. Old kernels might not support BTF at all (but
otherwise would work just fine), or might not support some specific
newer additions to BTF. If someone was to use the latest Clang, but
outdated libbpf and old kernel, they would have a bad time, because
their BPF program would fail due to the kernel being strict about BTF.
But new libbpf would "sanitize" BTF, according to supported features
of the kernel, or just drop BTF altogether, if the kernel is that old.

If iproute2's latest version doesn't imply the latest libbpf version,
there is a high chance that the user's BPF program will fail to load.
Which requires users to be **aware** of all these complications, and
care about specific Clang versions and subsets of BTF that get
generated. With the latest libbpf all that goes away.

2. bpf_probe_read_user() falling back to bpf_probe_read(). Newer
kernels warn if a BPF application isn't using a proper _kernel() or
_user() variant of bpf_probe_read(), and eventually will just stop
supporting generic bpf_probe_read(). So what this means is that end
users would need to compile to variants of their BPF application, one
for older kernels with bpf_probe_read(), another with
bpf_probe_read_kernel()/bpf_probe_read_user(). That's a massive pain
in the butt. But newer libbpf versions provide a completely
transparent fallback from _user()/_kernel() variants to generic one,
if the kernel doesn't support new variants. So the instruction to
users becomes simple: always use
bpf_probe_read_user()/bpf_probe_read_kernel().

But with iproute2 not enforcing new enough versions of libbpf, all
that goes out of the window and puts the burden back on end users.

3. Another feature (and far from being the last of this kind in
libbpf) is a full support for individual *non-always-inlined*
functions in BPF code, which was added recently. This allows to
structure BPF code better, get better instruction cache use and for
newer kernels even get significant speed ups of BPF code verification.
This is purely a libbpf feature, no API was changed. Further, the
kernel understands the difference between global and static functions
in BPF code and optimizes verification, if possible. Libbpf takes care
of falling back to static functions for old kernels that are not yet
aware of global functions. All that is completely transparent and
works reliably without users having to deal with three variants of
doing helper functions in their BPF code.

And again, if, when using iproute2, the user doesn't know which
version of libbpf will be used, they have to assume the worst
(__always_inline) or maintain 2 or 3 different copies of their code.

And there are more conveniences like that significantly simplifying
BPF end users by hiding differences of kernel versions, clang
versions, etc.

Submodule is a way that I know of to make this better for end users.
If there are other ways to pull this off with shared library use, I'm
all for it, it will save the security angle that distros are arguing
for. E.g., if distributions will always have the latest libbpf
available almost as soon as it's cut upstream *and* new iproute2
versions enforce the latest libbpf when they are packaged/released,
then this might work equivalently for end users. If Linux distros
would be willing to do this faithfully and promptly, I have no
objections whatsoever. Because all that matters is BPF end user
experience, as Daniel explained above.

>
> IIUC you're saying that we cannot depend on libbpf updates from distro.

As I tried to explain above, a big part of libbpf is BPF loader,
which, while not changing the library API, does get more and advanced
features with newer versions. So yeah, you can totally use older
versions of libbpf, but you need to be aware of all the kernel + clang
+ BPF code features interactions, which newer libbpfs often
transparently alleviate for the user.

So if someone has some old BPF code not using anything fancy, they
might not care all that much, probably.


> Isn't that a pretty bad experience for all users who would like to link
> against it? There are 4 components (kernel, lib, tools, compiler) all
> need to be kept up to date for optimal user experience. Cutting corners
> with one of them leads nowhere medium term IMHO.
>
> Unless what you guys are saying is that libbpf is _not_ supposed to be
> backward compatible from the user side, and must be used a submodule.
> But then why bother defining ABI versions, or build it as an .so at all.

That's not what anyone is saying, I hope we established that in this
thread that libbpf does provide a stable API and ABI, with backwards
and forward compatibility. And takes it very seriously. User BPF
programs just tend to grow in complexity and features used and newer
libbpf versions are sometimes a requirement to utilize all that
effectively.

>
> I'm also confused by the testing argument. Surely the solution is to
> add unit / system tests for iproute2. Distros will rebuild packages
> when dependencies change and retest. If we have 0 tests doesn't matter
> what update strategy there is.

Tests are good, but I'm a bit sceptical about the surface area that
could be tested. Compiled BPF program (ELF file) is an input to BPF
loader APIs, and that compiled BPF program can be arbitrarily complex,
using a variety of different kernel/libbpf features. So a single
non-changing APIs accepts an infinite variety of inputs. selftests/bpf
mandate that each new kernel and libbpf feature gets a test, I'm
wondering if iproute2 test suite would be able to keep up with this.
And then again, some features are not supposed to work on older libbpf
versions, so not clear how iproute2 would test that. But regardless,
more testing is always better, so I hope this won't discourage testing
per se.

  reply	other threads:[~2020-11-04 20:43 UTC|newest]

Thread overview: 167+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-23  3:38 [PATCH iproute2-next 0/5] iproute2: add libbpf support Hangbin Liu
2020-10-23  3:38 ` [PATCH iproute2-next 1/5] configure: add check_libbpf() for later " Hangbin Liu
2020-10-23  3:38 ` [PATCH iproute2-next 2/5] lib: rename bpf.c to bpf_legacy.c Hangbin Liu
2020-10-23  3:38 ` [PATCH iproute2-next 3/5] lib: add libbpf support Hangbin Liu
2020-10-23 14:34   ` David Ahern
2020-10-25 15:13     ` Toke Høiland-Jørgensen
2020-10-25 22:12       ` David Ahern
2020-10-26  8:56         ` Hangbin Liu
2020-10-26 15:15           ` David Ahern
2020-10-27  2:58             ` Hangbin Liu
2020-10-24  0:21   ` Andrii Nakryiko
2020-10-25 15:11     ` Toke Høiland-Jørgensen
2020-10-26  8:10     ` Hangbin Liu
2020-10-23  3:38 ` [PATCH iproute2-next 4/5] examples/bpf: move struct bpf_elf_map defined maps to legacy folder Hangbin Liu
2020-10-23  3:38 ` [PATCH iproute2-next 5/5] examples/bpf: add bpf examples with BTF defined maps Hangbin Liu
2020-10-28 13:25 ` [PATCHv2 iproute2-next 0/5] iproute2: add libbpf support Hangbin Liu
2020-10-28 13:25   ` [PATCHv2 iproute2-next 1/5] configure: add check_libbpf() for later " Hangbin Liu
2020-10-28 13:25   ` [PATCHv2 iproute2-next 2/5] lib: rename bpf.c to bpf_legacy.c Hangbin Liu
2020-10-28 13:25   ` [PATCHv2 iproute2-next 3/5] lib: add libbpf support Hangbin Liu
2020-10-28 13:25   ` [PATCHv2 iproute2-next 4/5] examples/bpf: move struct bpf_elf_map defined maps to legacy folder Hangbin Liu
2020-10-28 13:25   ` [PATCHv2 iproute2-next 5/5] examples/bpf: add bpf examples with BTF defined maps Hangbin Liu
2020-10-28 21:17   ` [PATCHv2 iproute2-next 0/5] iproute2: add libbpf support Alexei Starovoitov
2020-10-28 23:02   ` David Ahern
2020-10-29  2:06     ` Hangbin Liu
2020-10-29  2:20       ` David Ahern
2020-10-29  2:45         ` Hangbin Liu
2020-10-29  3:00           ` David Ahern
2020-10-29  3:17             ` Hangbin Liu
2020-10-29 10:26             ` Hangbin Liu
2020-10-29 10:51               ` Toke Høiland-Jørgensen
2020-10-29  2:27       ` Andrii Nakryiko
2020-10-29  2:33         ` David Ahern
2020-10-29  2:46           ` Andrii Nakryiko
2020-10-29  2:34         ` Stephen Hemminger
2020-10-29  2:50           ` Andrii Nakryiko
2020-10-29 11:38             ` Jesper Dangaard Brouer
2020-10-29 20:30               ` Andrii Nakryiko
2020-10-29  2:33       ` Stephen Hemminger
2020-10-29 15:11   ` [PATCHv3 " Hangbin Liu
2020-10-29 15:11     ` [PATCHv3 iproute2-next 1/5] configure: add check_libbpf() for later " Hangbin Liu
2020-10-29 15:26       ` Toke Høiland-Jørgensen
2020-11-02 15:37       ` David Ahern
2020-11-03  5:54         ` Hangbin Liu
2020-11-03 17:32           ` David Ahern
2020-11-04  8:51             ` Hangbin Liu
2020-11-04 11:09               ` Toke Høiland-Jørgensen
2020-11-04 11:40                 ` Hangbin Liu
2020-10-29 15:11     ` [PATCHv3 iproute2-next 2/5] lib: rename bpf.c to bpf_legacy.c Hangbin Liu
2020-10-29 15:11     ` [PATCHv3 iproute2-next 3/5] lib: add libbpf support Hangbin Liu
2020-11-02 15:41       ` David Ahern
2020-11-03  5:48         ` Hangbin Liu
2020-11-03 17:19           ` David Ahern
2020-11-04  8:22         ` Hangbin Liu
2020-11-05  2:33           ` David Ahern
2020-11-05  7:51             ` Hangbin Liu
2020-11-05 15:25               ` David Ahern
2020-11-05 15:57                 ` Toke Høiland-Jørgensen
2020-11-05 16:02                   ` David Ahern
2020-11-06  0:56                     ` Hangbin Liu
2020-11-06  0:41                 ` Hangbin Liu
2020-10-29 15:11     ` [PATCHv3 iproute2-next 4/5] examples/bpf: move struct bpf_elf_map defined maps to legacy folder Hangbin Liu
2020-10-29 15:11     ` [PATCHv3 iproute2-next 5/5] examples/bpf: add bpf examples with BTF defined maps Hangbin Liu
2020-11-02 15:47     ` [PATCHv3 iproute2-next 0/5] iproute2: add libbpf support David Ahern
2020-11-03  6:58       ` Andrii Nakryiko
2020-11-03  8:42         ` Jiri Benc
2020-11-03 17:45           ` David Ahern
2020-11-03 17:48           ` Alexei Starovoitov
2020-11-03  8:46         ` Daniel Borkmann
2020-11-03 17:35           ` David Ahern
2020-11-03 17:47             ` Alexei Starovoitov
2020-11-03 18:23               ` Stephen Hemminger
2020-11-03 22:32               ` David Ahern
2020-11-03 22:55                 ` Alexei Starovoitov
2020-11-04  1:40                   ` David Ahern
2020-11-04  2:45                     ` Alexei Starovoitov
2020-11-04  9:28                       ` Jiri Benc
2020-11-05  2:39                         ` David Ahern
2020-11-04  2:17                   ` Hangbin Liu
2020-11-04  3:11                     ` Alexei Starovoitov
2020-11-04 10:01                       ` Jiri Benc
2020-11-04 10:21                       ` Daniel Borkmann
2020-11-04 11:20                         ` Toke Høiland-Jørgensen
2020-11-04 13:12                           ` Daniel Borkmann
2020-11-04 19:17                             ` Jakub Kicinski
2020-11-04 20:43                               ` Andrii Nakryiko [this message]
2020-11-04 22:24                                 ` Toke Høiland-Jørgensen
2020-11-05 20:14                                   ` Andrii Nakryiko
2020-11-05  3:48                                 ` David Ahern
2020-11-05 20:53                                   ` Andrii Nakryiko
2020-11-05  3:19                         ` David Ahern
2020-11-05 14:05                           ` Jamal Hadi Salim
2020-11-05 21:01                             ` Andrii Nakryiko
2020-11-06 15:27                               ` Jamal Hadi Salim
2020-11-06 21:25                                 ` Andrii Nakryiko
2020-11-10 12:47                             ` Edward Cree
2020-11-11  0:53                               ` Alexei Starovoitov
2020-11-11 11:31                                 ` Edward Cree
2020-11-11 18:08                                   ` Alexei Starovoitov
2020-11-05 20:45                           ` Andrii Nakryiko
2020-11-06  9:00                             ` Jiri Benc
2020-11-06 21:07                               ` Andrii Nakryiko
2020-11-04 21:15                       ` Edward Cree
2020-11-04 22:10                         ` Alexei Starovoitov
2020-11-04 22:35                           ` Toke Høiland-Jørgensen
2020-11-04 23:05                           ` Edward Cree
2020-11-05 20:19                             ` Andrii Nakryiko
2020-11-06  8:44                               ` Jiri Benc
2020-11-06 20:57                                 ` Andrii Nakryiko
2020-11-06 21:04                                   ` Alexei Starovoitov
2020-11-06 23:25                                     ` Stephen Hemminger
2020-11-06 23:30                                       ` Andrii Nakryiko
2020-11-07  0:41                                         ` Stephen Hemminger
2020-11-07  1:07                                           ` Andrii Nakryiko
2020-11-06 23:38                                       ` David Ahern
2020-11-09  1:45                                         ` Alexei Starovoitov
2020-11-10  4:09                                           ` David Ahern
2020-11-11  0:47                                             ` Alexei Starovoitov
2020-11-11 11:02                                               ` Toke Høiland-Jørgensen
2020-11-11 15:06                                                 ` Daniel Borkmann
2020-11-11 16:33                                                   ` David Ahern
2020-11-12 22:36                                                   ` Toke Høiland-Jørgensen
2020-11-12 23:20                                                     ` Daniel Borkmann
2020-11-13  0:04                                                       ` Stephen Hemminger
2020-11-13  0:40                                                         ` Alexei Starovoitov
2020-11-13  3:55                                                       ` David Ahern
2020-11-09  7:07     ` [PATCHv4 " Hangbin Liu
2020-11-09  7:07       ` [PATCHv4 iproute2-next 1/5] configure: add check_libbpf() for later " Hangbin Liu
2020-11-14  3:26         ` David Ahern
2020-11-16  4:30           ` Hangbin Liu
2020-11-16  4:33             ` David Ahern
2020-11-09  7:07       ` [PATCHv4 iproute2-next 2/5] lib: rename bpf.c to bpf_legacy.c Hangbin Liu
2020-11-14  3:24         ` David Ahern
2020-11-16  3:55           ` Hangbin Liu
2020-11-09  7:08       ` [PATCHv4 iproute2-next 3/5] lib: add libbpf support Hangbin Liu
2020-11-09  7:08       ` [PATCHv4 iproute2-next 4/5] examples/bpf: move struct bpf_elf_map defined maps to legacy folder Hangbin Liu
2020-11-09  7:08       ` [PATCHv4 iproute2-next 5/5] examples/bpf: add bpf examples with BTF defined maps Hangbin Liu
2020-11-16  6:53       ` [PATCHv5 iproute2-next 0/5] iproute2: add libbpf support Hangbin Liu
2020-11-16  6:53         ` [PATCHv5 iproute2-next 1/5] configure: add check_libbpf() for later " Hangbin Liu
2020-11-16  6:53         ` [PATCHv5 iproute2-next 2/5] lib: rename bpf.c to bpf_legacy.c Hangbin Liu
2020-11-16  6:53         ` [PATCHv5 iproute2-next 3/5] lib: add libbpf support Hangbin Liu
2020-11-16  6:53         ` [PATCHv5 iproute2-next 4/5] examples/bpf: move struct bpf_elf_map defined maps to legacy folder Hangbin Liu
2020-11-16  6:53         ` [PATCHv5 iproute2-next 5/5] examples/bpf: add bpf examples with BTF defined maps Hangbin Liu
2020-11-16  7:19         ` [PATCHv5 iproute2-next 0/5] iproute2: add libbpf support Alexei Starovoitov
2020-11-16 14:54           ` Jesper Dangaard Brouer
2020-11-16 23:29             ` Toke Høiland-Jørgensen
2020-11-17  2:37             ` Alexei Starovoitov
2020-11-17  3:19               ` Hangbin Liu
2020-11-17 18:27                 ` Alexei Starovoitov
2020-11-17 11:56               ` Edward Cree
2020-11-17  3:38             ` David Ahern
2020-11-17 18:19               ` Alexei Starovoitov
2020-11-16 16:45           ` Stephen Hemminger
2020-11-23 13:11         ` [PATCHv6 " Hangbin Liu
2020-11-23 13:11           ` [PATCHv6 iproute2-next 1/5] iproute2: add check_libbpf() and get_libbpf_version() Hangbin Liu
2020-11-23 13:11           ` [PATCHv6 iproute2-next 2/5] lib: make ipvrf able to use libbpf and fix function name conflicts Hangbin Liu
2020-11-23 13:11           ` [PATCHv6 iproute2-next 3/5] lib: add libbpf support Hangbin Liu
2020-11-23 13:12           ` [PATCHv6 iproute2-next 4/5] examples/bpf: move struct bpf_elf_map defined maps to legacy folder Hangbin Liu
2020-11-23 13:12           ` [PATCHv6 iproute2-next 5/5] examples/bpf: add bpf examples with BTF defined maps Hangbin Liu
2020-11-25  5:28           ` [PATCHv6 iproute2-next 0/5] iproute2: add libbpf support David Ahern
2020-11-25  5:30           ` patchwork-bot+netdevbpf
2020-11-29  6:16 ` [PATCH " Stephen Hemminger
2020-11-29  6:22   ` Greg KH
2020-11-30 11:39     ` Michal Kubecek
2020-11-29 17:33   ` Alexei Starovoitov
2020-11-29 19:41   ` David Ahern
2020-11-30 11:04     ` Toke Høiland-Jørgensen
2020-12-01 14:22     ` Jesper Dangaard Brouer

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=CAEf4BzY2pAaEmv_x_nGQC83373ZWUuNv-wcYRye+vfZ3Fa2qbw@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=haliu@redhat.com \
    --cc=jbenc@redhat.com \
    --cc=kafai@fb.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=stephen@networkplumber.org \
    --cc=toke@redhat.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 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).