From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
Networking <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 3/3] selftests/bpf: allow compiling BPF objects without BTF
Date: Mon, 29 Mar 2021 11:55:58 -0700 [thread overview]
Message-ID: <20210329185558.mjoikgfdp53lq2it@ast-mbp> (raw)
In-Reply-To: <CAEf4Bza-uieOvR6AQkC-suD=_mjs5KC_1Ra3xo9kvdSxAMmeRg@mail.gmail.com>
On Sun, Mar 28, 2021 at 11:09:23PM -0700, Andrii Nakryiko wrote:
>
> BPF skeleton works just fine without BTF, if BPF programs don't use
> global data. I have no way of knowing how BPF skeleton is used in the
> wild, and specifically whether it is used without BTF and
> .data/.rodata.
No way of knowing?
The skel gen even for the most basic progs fails when there is no BTF in .o
$ bpftool gen skeleton prog_compiled_without_dash_g.o
libbpf: BTF is required, but is missing or corrupted.
libbpf_needs_btf() check is preventing all but the most primitive progs.
Any prog with new style of map definition:
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, __u32);
__type(value, __u64);
} array SEC(".maps");
would fail skel gen.
bpftool is capable of skel gen for progs with old style maps only:
struct bpf_map_def SEC("maps")
I think it's a safe bet that if folks didn't adopt new map definition
they didn't use skeleton either.
I think making skel gen reject such case is a good thing for the users,
since it prevents them from creating maps that look like blob of bytes.
It's good for admins too that more progs will get BTF described map key/value
and systems are easier to debug.
Ideally the kernel should reject loading progs and maps without BTF
to guarantee introspection.
Unfortunately the kernel backward compatibility prevents doing such
drastic things.
We might add a sysctl knob though.
The bpftool can certainly add a message and reject .o-s without BTF.
The chance of upsetting anyone is tiny.
Keep supporting old style 'bpf_map_def' is a maintenance burden.
Sooner or later it needs to be removed not only from skel gen,
but from libbpf as well.
> No one is asking for that, but they might be already using BTF-less
> skeleton. So I'm fixing a bug in bpftool. In a way that doesn't cause
> long term maintenance burden. And see above about my stance on tools'
> assumptions.
The patch and long term direction I'm arguing against is this one:
https://patchwork.kernel.org/project/netdevbpf/patch/20210319205909.1748642-2-andrii@kernel.org/
How is this a bug fix?
From commit log:
"If BPF object file is using global variables, but is compiled without BTF or
ends up having only some of DATASEC types due to static linking"
global vars without BTF were always rejected by bpftool
and should continue being rejected.
I see no reason for adding such feature.
> we both know this very well. But just as a fun exercise, I just
> double-checked by compiling fentry demo from libbpf-bootstrap ([0]).
> It works just fine without `-g` and BTF.
>
> [0] https://github.com/libbpf/libbpf-bootstrap/blob/master/src/fentry.bpf.c
yes. the skel gen will work for such demo prog, but the user should
be making them introspectable.
Try llvm-strip prog.o
Old and new bpftool-s will simply crash, because there are no symbols.
Should skel gen support such .o as well?
I don't think so. imo it's the same category of non-introspectable progs
that shouldn't be allowed.
> Yeah, that's fine and we do require BTF for new features (where it
> makes sense, of course, not just arbitrarily).
I'm saying the kernel should enforce introspection.
sysctl btf_enforced=1 might be the answer.
next prev parent reply other threads:[~2021-03-29 18:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-19 20:59 [PATCH bpf-next 0/3] Handle no-BTF object files better Andrii Nakryiko
2021-03-19 20:59 ` [PATCH bpf-next 1/3] bpftool: improve skeleton generation for objects without BTF Andrii Nakryiko
2021-03-19 20:59 ` [PATCH bpf-next 2/3] libbpf: skip BTF fixup if object file has no BTF Andrii Nakryiko
2021-03-19 21:25 ` Jiri Olsa
2021-03-19 20:59 ` [PATCH bpf-next 3/3] selftests/bpf: allow compiling BPF objects without BTF Andrii Nakryiko
2021-03-20 2:21 ` Alexei Starovoitov
2021-03-20 17:00 ` Andrii Nakryiko
2021-03-22 1:07 ` Alexei Starovoitov
2021-03-22 16:56 ` Andrii Nakryiko
2021-03-22 17:54 ` Alexei Starovoitov
2021-03-26 16:44 ` Andrii Nakryiko
2021-03-29 1:16 ` Alexei Starovoitov
2021-03-29 6:09 ` Andrii Nakryiko
2021-03-29 18:55 ` Alexei Starovoitov [this message]
2021-03-30 18:00 ` 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=20210329185558.mjoikgfdp53lq2it@ast-mbp \
--to=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
/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