[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250207012045.2129841-3-stephen.s.brennan@oracle.com>
Date: Thu, 6 Feb 2025 17:20:44 -0800
From: Stephen Brennan <stephen.s.brennan@...cle.com>
To: Masahiro Yamada <masahiroy@...nel.org>
Cc: Andrii Nakryiko <andrii@...nel.org>, Nicolas Schier <nicolas@...sle.eu>,
Kees Cook <kees@...nel.org>, KP Singh <kpsingh@...nel.org>,
Stephen Brennan <stephen.s.brennan@...cle.com>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Sami Tolvanen <samitolvanen@...gle.com>,
Eduard Zingerman <eddyz87@...il.com>, linux-arch@...r.kernel.org,
Stanislav Fomichev <sdf@...ichev.me>,
Kent Overstreet <kent.overstreet@...ux.dev>,
Pasha Tatashin <pasha.tatashin@...een.com>,
Jiri Olsa <jolsa@...nel.org>,
John Fastabend <john.fastabend@...il.com>,
Jann Horn <jannh@...gle.com>, Ard Biesheuvel <ardb@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>, Hao Luo <haoluo@...gle.com>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-kbuild@...r.kernel.org, Daniel Borkmann <daniel@...earbox.net>,
Arnd Bergmann <arnd@...db.de>, Nathan Chancellor <nathan@...nel.org>,
linux-debuggers@...r.kernel.org, Alexei Starovoitov <ast@...nel.org>,
Song Liu <song@...nel.org>, linux-kernel@...r.kernel.org,
bpf@...r.kernel.org
Subject: [PATCH 2/2] btf: Add the option to include global variable types
Since pahole 1.28, BTF can now include types for all global variables.
Previously, BTF has only included types for functions, as well as percpu
variables.
There are a few applications for this type information. For one, runtime
debuggers like drgn[1] can consume it in the absence of DWARF debuginfo.
The support in drgn is currently implemented and moving through the
review process, see [2]. For distributions which don't distribute DWARF
debuginfo, or for situations where it can't be made available, the
compact BTF, combined with ORC for stack unwinding, and the kallsyms
symbol table, can be used for simple runtime debugging and
introspection.
Another application is verifying types of ksyms in BPF programs. libbpf
already supports resolving global variables with "__ksym", but they must
be declared as void. For example, in
tools/bpf/bpftool/skeleton/pid_iter.bpf.c we have:
extern const void bpf_map_fops __ksym;
With global variable information, declarations like these would be able
to use the actual variable types, for example:
extern const struct file_operations bpf_map_fops __ksym;
When the feature was implemented in pahole, my measurements indicated
that vmlinux BTF size increased by about 25.8%, and module BTF size
increased by 53.2%. Due to these increases, the feature is implemented
behind a new config option, allowing users sensitive to increased memory
usage to disable it.
[1]: https://github.com/osandov/drgn
[2]: https://github.com/osandov/drgn/issues/176
Signed-off-by: Stephen Brennan <stephen.s.brennan@...cle.com>
---
lib/Kconfig.debug | 10 ++++++++++
scripts/Makefile.btf | 3 +++
2 files changed, 13 insertions(+)
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 1af972a92d06f..3fbdc5ba2d017 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -409,6 +409,16 @@ config PAHOLE_HAS_LANG_EXCLUDE
otherwise it would emit malformed kernel and module binaries when
using DEBUG_INFO_BTF_MODULES.
+config DEBUG_INFO_BTF_GLOBAL_VARS
+ bool "Generate BTF type information for all global variables"
+ default y
+ depends on DEBUG_INFO_BTF && PAHOLE_VERSION >= 128
+ help
+ Include type information for all global variables in the BTF. This
+ increases the size of the BTF information, which increases memory
+ usage at runtime. With global variable types available, runtime
+ debugging and tracers may be able to provide more detail.
+
config DEBUG_INFO_BTF_MODULES
bool "Generate BTF type information for kernel modules"
default y
diff --git a/scripts/Makefile.btf b/scripts/Makefile.btf
index c3cbeb13de503..ad3c05a96a010 100644
--- a/scripts/Makefile.btf
+++ b/scripts/Makefile.btf
@@ -31,5 +31,8 @@ endif
pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) += --lang_exclude=rust
+# Requires v1.28 or later, enforced by KConfig
+pahole-flags-$(CONFIG_DEBUG_INFO_BTF_GLOBAL_VARS) += --btf_features=global_var
+
export PAHOLE_FLAGS := $(pahole-flags-y)
export MODULE_PAHOLE_FLAGS := $(module-pahole-flags-y)
--
2.43.5
Powered by blists - more mailing lists