From: "Mauricio Vásquez" <mauricio@kinvolk.io>
To: netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Quentin Monnet <quentin@isovalent.com>,
Rafael David Tinoco <rafaeldtinoco@gmail.com>,
Lorenzo Fontana <lorenzo.fontana@elastic.co>,
Leonardo Di Donato <leonardo.didonato@elastic.co>
Subject: [PATCH bpf-next v4 0/8] libbpf: Implement BTFGen
Date: Wed, 12 Jan 2022 09:27:01 -0500 [thread overview]
Message-ID: <20220112142709.102423-1-mauricio@kinvolk.io> (raw)
CO-RE requires to have BTF information describing the kernel types in
order to perform the relocations. This is usually provided by the kernel
itself when it's configured with CONFIG_DEBUG_INFO_BTF. However, this
configuration is not enabled in all the distributions and it's not
available on kernels before 5.12.
It's possible to use CO-RE in kernels without CONFIG_DEBUG_INFO_BTF
support by providing the BTF information from an external source.
BTFHub[0] contains BTF files to each released kernel not supporting BTF,
for the most popular distributions.
Providing this BTF file for a given kernel has some challenges:
1. Each BTF file is a few MBs big, then it's not possible to ship the
eBPF program with all the BTF files needed to run in different kernels.
(The BTF files will be in the order of GBs if you want to support a high
number of kernels)
2. Downloading the BTF file for the current kernel at runtime delays the
start of the program and it's not always possible to reach an external
host to download such a file.
Providing the BTF file with the information about all the data types of
the kernel for running an eBPF program is an overkill in many of the
cases. Usually the eBPF programs access only some kernel fields.
This series implements BTFGen support in bpftool. This idea was
discussed during the "Towards truly portable eBPF"[1] presentation at
Linux Plumbers 2021.
There is a good example[2] on how to use BTFGen and BTFHub together
to generate multiple BTF files, to each existing/supported kernel,
tailored to one application. For example: a complex bpf object might
support nearly 400 kernels by having BTF files summing only 1.5 MB.
[0]: https://github.com/aquasecurity/btfhub/
[1]: https://www.youtube.com/watch?v=igJLKyP1lFk&t=2418s
[2]: https://github.com/aquasecurity/btfhub/tree/main/tools
Changelog:
v3 > v4:
- parse BTF and BTF.ext sections in bpftool and use
bpf_core_calc_relo_insn() directly
- expose less internal details from libbpf to bpftool
- implement support for enum-based relocations
- split commits in a more granular way
v2 > v3:
- expose internal libbpf APIs to bpftool instead
- implement btfgen in bpftool
- drop btf__raw_data() from libbpf
v1 > v2:
- introduce bpf_object__prepare() and ‘record_core_relos’ to expose
CO-RE relocations instead of bpf_object__reloc_info_gen()
- rename btf__save_to_file() to btf__raw_data()
v1: https://lore.kernel.org/bpf/20211027203727.208847-1-mauricio@kinvolk.io/
v2: https://lore.kernel.org/bpf/20211116164208.164245-1-mauricio@kinvolk.io/
v3: https://lore.kernel.org/bpf/20211217185654.311609-1-mauricio@kinvolk.io/
Mauricio Vásquez (8):
libbpf: split bpf_core_apply_relo()
libbpf: Implement changes needed for BTFGen in bpftool
bpftool: Add gen btf command
bpftool: Implement btf_save_raw()
bpftool: Add struct definitions and helpers for BTFGen
bpftool: Implement btfgen()
bpftool: Implement relocations recording for BTFGen
bpftool: Implement btfgen_get_btf()
kernel/bpf/btf.c | 13 +-
tools/bpf/bpftool/gen.c | 849 ++++++++++++++++++++++++++++++++
tools/lib/bpf/Makefile | 2 +-
tools/lib/bpf/libbpf.c | 127 +++--
tools/lib/bpf/libbpf_internal.h | 12 +
tools/lib/bpf/relo_core.c | 79 +--
tools/lib/bpf/relo_core.h | 42 +-
7 files changed, 1012 insertions(+), 112 deletions(-)
--
2.25.1
next reply other threads:[~2022-01-12 14:27 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-12 14:27 Mauricio Vásquez [this message]
2022-01-12 14:27 ` [PATCH bpf-next v4 1/8] libbpf: split bpf_core_apply_relo() Mauricio Vásquez
2022-01-15 2:01 ` Andrii Nakryiko
2022-01-21 20:40 ` Mauricio Vásquez Bernal
2022-01-12 14:27 ` [PATCH bpf-next v4 2/8] libbpf: Implement changes needed for BTFGen in bpftool Mauricio Vásquez
2022-01-12 18:08 ` Quentin Monnet
2022-01-21 20:44 ` Mauricio Vásquez Bernal
2022-01-15 2:04 ` Andrii Nakryiko
2022-01-12 14:27 ` [PATCH bpf-next v4 3/8] bpftool: Add gen btf command Mauricio Vásquez
2022-01-12 18:08 ` Quentin Monnet
2022-01-21 20:40 ` Mauricio Vásquez Bernal
2022-01-21 21:35 ` Andrii Nakryiko
2022-01-15 2:09 ` Andrii Nakryiko
2022-01-21 20:44 ` Mauricio Vásquez Bernal
2022-01-12 14:27 ` [PATCH bpf-next v4 4/8] bpftool: Implement btf_save_raw() Mauricio Vásquez
2022-01-15 2:10 ` Andrii Nakryiko
2022-01-21 20:45 ` Mauricio Vásquez Bernal
2022-01-12 14:27 ` [PATCH bpf-next v4 5/8] bpftool: Add struct definitions and helpers for BTFGen Mauricio Vásquez
2022-01-12 14:27 ` [PATCH bpf-next v4 6/8] bpftool: Implement btfgen() Mauricio Vásquez
2022-01-12 18:09 ` Quentin Monnet
2022-01-15 2:15 ` Andrii Nakryiko
2022-01-12 14:27 ` [PATCH bpf-next v4 7/8] bpftool: Implement relocations recording for BTFGen Mauricio Vásquez
2022-01-12 18:09 ` Quentin Monnet
2022-01-12 14:27 ` [PATCH bpf-next v4 8/8] bpftool: Implement btfgen_get_btf() Mauricio Vásquez
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=20220112142709.102423-1-mauricio@kinvolk.io \
--to=mauricio@kinvolk.io \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=leonardo.didonato@elastic.co \
--cc=lorenzo.fontana@elastic.co \
--cc=netdev@vger.kernel.org \
--cc=quentin@isovalent.com \
--cc=rafaeldtinoco@gmail.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).