Hello,
CONFIG_IKCONFIG is really nice, in particular, for debuggers. Interpreting data
structures becomes much easier if you know how the kernel was configured.
However, most distributions end up disabling it because it consumes quite a bit
of kernel memory at runtime when built-in. The result is that debuggers have to
find workarounds, like checking for the existence of symbols which would only be
present on certain configurations. However, this isn't always possible.
Building CONFIG_IKCONFIG=m is supposed to address this: users get the choice to
load the module if they want it, and if not, the .ko is there so that a tool
could read it with logic like "scripts/extract-ikconfig". In practice, this
leads to a few issues. First, many distributions still end up disabling this
option, and second, debuggers are more and more frequently relying on "build ID"
to fetch the corresponding debug information. This means that they may not have
the entire debuginfo package containing configs.ko - they only have the vmlinux
and modules corresponding to what was actually loaded in the kernel. So we are
once again stuck with expecting users to load a module containing a blob of data
that can't be paged out.
I'd like to propose an alternative, which I named CONFIG_DEBUG_INFO_IKCONFIG.
When IKCONFIG is not built-in, this adds the gzipped kernel configuration to a
new section on the vmlinux file: .debug_linux_ikconfig. Since it is named with
the ".debug" prefix, it is stripped out of any bootable images, but remains in
the debug info vmlinux file. It can still be used with scripts/extract-ikconfig.
But now, debuggers can hope to find configuration information automatically,
without asking users to dedicate runtime memory to holding this information.
The hope is that this will be enabled by most distributions since it has no
runtime cost and a very minimal cost for debuginfo (which is usually on the
order of hundreds of megabytes, not a few tens of kilobytes).
Thanks,
Stephen
Stephen Brennan (1):
kernel/config: Introduce CONFIG_DEBUG_INFO_IKCONFIG
include/asm-generic/vmlinux.lds.h | 3 ++-
kernel/Makefile | 1 +
kernel/configs-debug.S | 18 ++++++++++++++++++
lib/Kconfig.debug | 14 ++++++++++++++
4 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 kernel/configs-debug.S
--
2.39.3
The option CONFIG_IKCONFIG allows the gzip compressed kernel
configuration to be included into vmlinux or a module. In these cases,
debuggers can access the config data and use it to adjust their behavior
according to the configuration. However, distributions rarely enable
this, likely because it uses a fair bit of kernel memory which cannot be
swapped out.
This means that in practice, the kernel configuration is rarely
available to debuggers.
So, introduce an alternative, CONFIG_DEBUG_INFO_IKCONFIG. This strategy,
which is only available if IKCONFIG is not already built-in, adds a
section ".debug_linux_ikconfig", to the vmlinux ELF. It will be stripped
out of the final images, but will remain in the debuginfo files. So
debuggers which rely on vmlinux debuginfo can have access to the kernel
configuration, without incurring a cost to the kernel at runtime.
Signed-off-by: Stephen Brennan <[email protected]>
---
include/asm-generic/vmlinux.lds.h | 3 ++-
kernel/Makefile | 1 +
kernel/configs-debug.S | 18 ++++++++++++++++++
lib/Kconfig.debug | 14 ++++++++++++++
4 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 kernel/configs-debug.S
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 9c59409104f6..025b0bfe17bf 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -824,7 +824,8 @@
.comment 0 : { *(.comment) } \
.symtab 0 : { *(.symtab) } \
.strtab 0 : { *(.strtab) } \
- .shstrtab 0 : { *(.shstrtab) }
+ .shstrtab 0 : { *(.shstrtab) } \
+ .debug_linux_ikconfig 0 : { *(.debug_linux_ikconfig) }
#ifdef CONFIG_GENERIC_BUG
#define BUG_TABLE \
diff --git a/kernel/Makefile b/kernel/Makefile
index 3947122d618b..e2f517a10f04 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -138,6 +138,7 @@ KCSAN_SANITIZE_stackleak.o := n
KCOV_INSTRUMENT_stackleak.o := n
obj-$(CONFIG_SCF_TORTURE_TEST) += scftorture.o
+obj-$(CONFIG_DEBUG_INFO_IKCONFIG) += configs-debug.o
$(obj)/configs.o: $(obj)/config_data.gz
diff --git a/kernel/configs-debug.S b/kernel/configs-debug.S
new file mode 100644
index 000000000000..d0dd5c2f7bd5
--- /dev/null
+++ b/kernel/configs-debug.S
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Inline kernel configuration for debuginfo files
+ *
+ * Copyright (c) 2023, Oracle and/or its affiliates.
+ */
+
+/*
+ * By using the same "IKCFG_ST" and "IKCFG_ED" markers found in configs.c, we
+ * can ensure that the resulting debuginfo files can be read by
+ * scripts/extract-ikconfig. Unfortunately, this means that the contents of the
+ * section cannot be directly extracted and used. Since debuggers should be able
+ * to trim these markers off trivially, this is a good tradeoff.
+ */
+ .section .debug_linux_ikconfig
+ .ascii "IKCFG_ST"
+ .incbin "kernel/config_data.gz"
+ .ascii "IKCFG_ED"
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index fa307f93fa2e..4ebd1bcd49c7 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -429,6 +429,20 @@ config GDB_SCRIPTS
instance. See Documentation/dev-tools/gdb-kernel-debugging.rst
for further details.
+config DEBUG_INFO_IKCONFIG
+ bool "Embed KConfig in debuginfo, if not already present"
+ depends on IKCONFIG!=y
+ help
+ This provides the gzip-compressed KConfig information in an ELF
+ section called .ikconfig which will be stripped out of the final
+ bootable image, but remain in the debuginfo. Debuggers that are aware
+ of this can use this to customize their behavior to the kernel
+ configuration, without requiring the configuration information to be
+ stored in the kernel like CONFIG_IKCONFIG does. This configuration is
+ unnecessary when CONFIG_IKCONFIG is enabled, since the data can be
+ found in the .rodata section in that case (see
+ scripts/extract-ikconfig).
+
endif # DEBUG_INFO
config FRAME_WARN
--
2.39.3
Hi,
On 10/4/23 09:58, Stephen Brennan wrote:
> The option CONFIG_IKCONFIG allows the gzip compressed kernel
> configuration to be included into vmlinux or a module. In these cases,
> debuggers can access the config data and use it to adjust their behavior
> according to the configuration. However, distributions rarely enable
> this, likely because it uses a fair bit of kernel memory which cannot be
> swapped out.
x86_64 allmodconfig is 91 KB gzipped... oh well.
Reviewed-by: Randy Dunlap <[email protected]>
> This means that in practice, the kernel configuration is rarely
> available to debuggers.
>
> So, introduce an alternative, CONFIG_DEBUG_INFO_IKCONFIG. This strategy,
> which is only available if IKCONFIG is not already built-in, adds a
> section ".debug_linux_ikconfig", to the vmlinux ELF. It will be stripped
> out of the final images, but will remain in the debuginfo files. So
> debuggers which rely on vmlinux debuginfo can have access to the kernel
> configuration, without incurring a cost to the kernel at runtime.
>
> Signed-off-by: Stephen Brennan <[email protected]>
> ---
> include/asm-generic/vmlinux.lds.h | 3 ++-
> kernel/Makefile | 1 +
> kernel/configs-debug.S | 18 ++++++++++++++++++
> lib/Kconfig.debug | 14 ++++++++++++++
> 4 files changed, 35 insertions(+), 1 deletion(-)
> create mode 100644 kernel/configs-debug.S
--
~Randy
Randy Dunlap <[email protected]> writes:
> Hi,
>
> On 10/4/23 09:58, Stephen Brennan wrote:
>> The option CONFIG_IKCONFIG allows the gzip compressed kernel
>> configuration to be included into vmlinux or a module. In these cases,
>> debuggers can access the config data and use it to adjust their behavior
>> according to the configuration. However, distributions rarely enable
>> this, likely because it uses a fair bit of kernel memory which cannot be
>> swapped out.
>
> x86_64 allmodconfig is 91 KB gzipped... oh well.
Yeah, and info like BTF is much larger, yet this is the config setting
that gets trimmed out by distros :(
(This is not a criticism of BTF, just an observation)
Unfortunately I don't control it and am just trying to work around it :)
> Reviewed-by: Randy Dunlap <[email protected]>
Thanks!
Stephen
>> This means that in practice, the kernel configuration is rarely
>> available to debuggers.
>>
>> So, introduce an alternative, CONFIG_DEBUG_INFO_IKCONFIG. This strategy,
>> which is only available if IKCONFIG is not already built-in, adds a
>> section ".debug_linux_ikconfig", to the vmlinux ELF. It will be stripped
>> out of the final images, but will remain in the debuginfo files. So
>> debuggers which rely on vmlinux debuginfo can have access to the kernel
>> configuration, without incurring a cost to the kernel at runtime.
>>
>> Signed-off-by: Stephen Brennan <[email protected]>
>> ---
>> include/asm-generic/vmlinux.lds.h | 3 ++-
>> kernel/Makefile | 1 +
>> kernel/configs-debug.S | 18 ++++++++++++++++++
>> lib/Kconfig.debug | 14 ++++++++++++++
>> 4 files changed, 35 insertions(+), 1 deletion(-)
>> create mode 100644 kernel/configs-debug.S
>
>
> --
> ~Randy