Linux kbuild/kconfig development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jay Wang" <wanjay@amazon.com>,
	bpf@vger.kernel.org, "Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: "Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"Alan Maguire" <almagui@kernel.org>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	linux-trace-kernel@vger.kernel.org,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>,
	linux-kbuild@vger.kernel.org, "Arnd Bergmann" <arnd@arndb.de>,
	x86@kernel.org, "Hazem Mohamed Abuelfotoh" <abuehaze@amazon.com>,
	"Bjoern Doebel" <doebel@amazon.de>,
	"Martin Pohlack" <mpohlack@amazon.de>,
	jay.wang.upstream@gmail.com
Subject: Re: [PATCH bpf-next 09/13] bpf: keep the vmlinux BTF zstd-compressed in the kernel image
Date: Sat, 31 Oct 2026 13:33:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-191977@kernel.org> (raw)
In-Reply-To: <20261031130959.23472-10-wanjay@amazon.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] bpf: non-standard multi-line comment style in btf_free()
- [Low] bpf: unresolved TODO-NEEDS-IHOR placeholder before Signed-off-by tag
--

commit 569512ffc44983e01a69cb1de127bbcd4ca67c62
Author: Jay Wang <wanjay@amazon.com>

bpf: keep the vmlinux BTF zstd-compressed in the kernel image

This commit adds CONFIG_DEBUG_INFO_BTF_LAZY to store the vmlinux BTF
zstd-compressed in the kernel image and decompress it on first access via
btf_vmlinux_data().

>     bpf: keep the vmlinux BTF zstd-compressed in the kernel image
>     
>     The vmlinux BTF is 5-7 MB of read-only data in every kernel built with
>     CONFIG_DEBUG_INFO_BTF=y, resident whether or not anything on the system
>     ever uses BTF.  Add CONFIG_DEBUG_INFO_BTF_LAZY to keep it compressed
>     with zstd in the image instead, at about a quarter of the size, and
>     decompress it in the kernel when it is first needed.  This is the
>     transport half of the option; the next two patches defer the
>     parsing.
>     
>     kbuild: gen_btf_o() in scripts/gen-btf.sh compresses the final
>     ${ELF}.BTF with zstd -19 and adds it as a second section, .init.BTF.zst,
>     of the same .btf.o, so neither an extra link pass nor a size
>     reservation is needed.  .BTF stays in the vmlinux ELF file as a
>     non-alloc section: pahole --btf_base, resolve_btfids for modules,
>     bpftool and libbpf's on-disk fallback find it by name and keep working
>     unchanged, and so do out-of-tree module builds.  The linker script
>     puts .init.BTF.zst in INIT_DATA, bounded by __start_BTF_zst and
>     __stop_BTF_zst, and .BTF in ELF_DETAILS at address 0.  The BTF macro
>     is renamed RO_BTF, because the token BTF in ".BTF 0 : { ... }" would
>     otherwise be macro-expanded.  x86 strips .BTF from the ELF it puts in
>     the compressed boot image, and arm64 makes its Image with objcopy
>     -O binary, which drops non-alloc sections.  The option is limited to
>     these two architectures for now: several others build their boot
>     image from a stripped ELF copy of vmlinux, which keeps non-alloc
>     sections and would carry the uncompressed BTF.  The inline BTF
>     (CONFIG_DEBUG_INFO_BTF_INLINE) is left as it is: built in, .BTF.inline
>     stays in the image; as a module it is not in memory anyway.
>     
>     kernel: btf_vmlinux_data() returns the raw BTF.  With the option it
>     decompresses the blob once, under a leaf mutex, into vmalloc_user()
>     memory that is never freed; the size comes from the zstd frame header,
>     so /sys/kernel/btf/vmlinux gets its size without decompressing.  A
>     late_initcall_sync copies the blob out of init memory before that is
>     freed, unless it is decompressed by then, and the copy is freed after
>     decompression, so a system that uses BTF ends up with the same
>     footprint as today.  The copy uses vmalloc(): kvmemdup() of the
>     ~1.4 MB blob would get a 2 MB kmalloc_large() allocation.  If the copy
>     fails, the BTF is unavailable for the rest of the boot: that is logged
>     once, and later fetches fail with -ENOMEM right away instead of
>     allocating the raw buffer for nothing each time.  A blob that does not
>     decompress is logged once and dropped, and fetches fail with -EINVAL
>     from then on.  btf_parse_vmlinux() and the read and mmap handlers of
>     /sys/kernel/btf/vmlinux use btf_vmlinux_data(); mmap of the
>     decompressed copy uses remap_vmalloc_range().  Without the option
>     btf_vmlinux_data() returns __start_BTF, and the sysfs file keeps its
>     current handlers.
>     
>     btf_vmlinux_data() lives in sysfs_btf.c, which is now built whenever
>     CONFIG_DEBUG_INFO_BTF is enabled, with the sysfs file itself still
>     under CONFIG_SYSFS: btf_parse_vmlinux() needs the data without sysfs
>     too, and with the option the blob has to be copied out of init memory
>     either way.
>     
>     Reading /sys/kernel/btf/vmlinux decompresses but never parses, and
>     only vmalloc and zstd run under btf_vmlinux_data_lock, so the sysfs
>     mmap path (mmap_lock -> kernfs -> btf_vmlinux_data_lock) cannot form
>     a cycle with module or cand_cache locks.
>     
>     On its own this patch only changes where the bytes come from: initcall
>     kfunc registrations still parse the vmlinux BTF at boot.
>     
>     Measured with a distribution config: the raw .BTF is 5.47 MB on x86_64
>     and 5.57 MB on arm64, and 1.44 and 1.46 MB with zstd -19.  xz -9e would
>     save another 0.17 MB but decodes about 6 times slower (72 vs 12 ms in
>     user space).  Decompression in the kernel takes ~7 ms on x86_64.
>     
>     Trade-offs: the compressed blob stays resident on systems that never
>     use BTF (~1.4 MB), so with the next two patches they save about 80% of
>     what the BTF costs rather than all of it (~6 of ~7.5 MB, the raw BTF
>     plus what parsing it allocates); the x86 bzImage on disk is ~0.3 MB
>     smaller; building needs the zstd tool; __start_BTF/__stop_BTF do not
>     exist with the option (the ksyms and linked_vars selftests use them; a
>     later patch adapts them).
>     
>     Co-developed-by: Ihor Solodrai <ihor.solodrai@linux.dev>
>     TODO-NEEDS-IHOR: Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
>     Signed-off-by: Jay Wang <wanjay@amazon.com>

[Severity: Low]
This isn't a bug in the code, but the commit message still has an
unresolved TODO-NEEDS-IHOR prefix on the Signed-off-by trailer pairing with
Co-developed-by. Should this placeholder be resolved to a clean
Signed-off-by tag?

[ ... ]

> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 70adc52f5d7c7..a7bb780743fb2 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -1901,7 +1901,8 @@ static void btf_free(struct btf *btf)
>  	kvfree(btf->resolved_sizes);
>  	kvfree(btf->resolved_ids);
>  	/* vmlinux does not allocate btf->data, it simply points it at
> -	 * __start_BTF.
> +	 * __start_BTF, or at the decompressed copy with
> +	 * CONFIG_DEBUG_INFO_BTF_LAZY, which is never freed either.
>  	 */

[Severity: Low]
This isn't a bug, but when updating this multi-line comment in btf_free()
in kernel/bpf/btf.c, could the opening /* be placed on its own line to
follow the BPF coding style?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261031130959.23472-1-wanjay@amazon.com?part=9

  reply	other threads:[~2026-10-31 13:33 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31 13:09 [PATCH bpf-next 00/13] bpf: keep the vmlinux BTF compressed until first use (CONFIG_DEBUG_INFO_BTF_LAZY) to save ~6 MB memory Jay Wang
2026-10-31 13:09 ` [PATCH bpf-next 01/13] bpf: match program context types by name without vmlinux BTF Jay Wang
2026-10-31 13:43   ` bot+bpf-ci
2026-10-31 13:09 ` [PATCH bpf-next 02/13] bpf: fetch the vmlinux BTF where kernel types enter a program Jay Wang
2026-10-31 13:42   ` sashiko-bot
2026-10-31 13:55   ` bot+bpf-ci
2026-10-31 13:09 ` [PATCH bpf-next 03/13] bpf: check CAP_SYS_ADMIN before looking up bpffs delegation names Jay Wang
2026-10-31 13:43   ` bot+bpf-ci
2026-10-31 17:03   ` Alexei Starovoitov
2026-10-31 13:09 ` [PATCH bpf-next 04/13] bpf: move bpf_get_btf_vmlinux() to btf.c Jay Wang
2026-10-31 13:43   ` bot+bpf-ci
2026-10-31 13:09 ` [PATCH bpf-next 05/13] bpf: let btf_parse_module() adopt the caller's copy of the module BTF Jay Wang
2026-10-31 13:09 ` [PATCH bpf-next 06/13] bpf: look up the struct_ops common value type in the given BTF Jay Wang
2026-10-31 13:09 ` [PATCH bpf-next 07/13] bpf: parse the vmlinux BTF before taking cand_cache_mutex Jay Wang
2026-10-31 13:43   ` bot+bpf-ci
2026-10-31 13:09 ` [PATCH bpf-next 08/13] tracing: parse the vmlinux BTF when BTF-typed output is enabled Jay Wang
2026-10-31 13:37   ` sashiko-bot
2026-10-31 13:43   ` bot+bpf-ci
2026-10-31 13:09 ` [PATCH bpf-next 09/13] bpf: keep the vmlinux BTF zstd-compressed in the kernel image Jay Wang
2026-10-31 13:33   ` sashiko-bot [this message]
2026-10-31 13:55   ` bot+bpf-ci
2026-10-31 13:09 ` [PATCH bpf-next 10/13] bpf: defer kfunc and struct_ops registrations until first BTF use Jay Wang
2026-10-31 13:38   ` sashiko-bot
2026-10-31 13:55   ` bot+bpf-ci
2026-10-31 17:07   ` Alexei Starovoitov
2026-10-31 13:09 ` [PATCH bpf-next 11/13] bpf: keep module BTF until the vmlinux BTF is parsed Jay Wang
2026-10-31 13:37   ` sashiko-bot
2026-10-31 13:55   ` bot+bpf-ci
2026-10-31 17:10     ` Alexei Starovoitov
2026-10-31 13:09 ` [PATCH bpf-next 12/13] selftests/bpf: keep ksyms and linked_vars working without __start_BTF Jay Wang
2026-10-31 13:09 ` [PATCH bpf-next 13/13] Documentation/bpf: describe CONFIG_DEBUG_INFO_BTF_LAZY Jay Wang

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=sashiko-outbox-191977@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=abuehaze@amazon.com \
    --cc=almagui@kernel.org \
    --cc=andrii@kernel.org \
    --cc=arnd@arndb.de \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=doebel@amazon.de \
    --cc=eddyz87@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jay.wang.upstream@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=memxor@gmail.com \
    --cc=mhiramat@kernel.org \
    --cc=mpohlack@amazon.de \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wanjay@amazon.com \
    --cc=x86@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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