* [PATCH v2 0/1] Introduce CONFIG_DEBUG_INFO_IKCONFIG
@ 2023-10-25 22:36 Stephen Brennan
2023-10-25 22:36 ` [PATCH v2 1/1] kernel/config: " Stephen Brennan
0 siblings, 1 reply; 5+ messages in thread
From: Stephen Brennan @ 2023-10-25 22:36 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Randy Dunlap, Stephen Brennan, linux-arch, linux-kernel,
linux-debuggers
Hello All,
This is an updated submission of the patch to add an alternative for
CONFIG_IKCONFIG. I wanted to bring it up again for consideration, and I also
made one small but important update.
v1: https://lore.kernel.org/linux-debuggers/20231004165804.659482-1-stephen.s.brennan@oracle.com/T/#t
Changes since v1:
* I added "default y if IKCONFIG!=y". The result is that whenever DEBUG_INFO=y
is enabled, and IKCONFIG is not built-in, then DEBUG_INFO_IKCONFIG will get
enabled automatically. The whole point of this patch is for kernel debuggers
to be able to rely on having kernel configuration information. The IKCONFIG
data is quite small compared to kernel debuginfo, and it doesn't change
anything at runtime. It's safe to enable this automatically, and it's
important so that distributions (who create debuginfo explicitly to allow
kernel debugging) will automatically begin creating this info for debuggers.
* Randy Dunlap did review this, but I didn't apply that tag with the update,
since I understand changing defaults is a major update, and it's a small patch
to begin with, so I didn't want to misrepresent the review.
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 | 15 +++++++++++++++
4 files changed, 36 insertions(+), 1 deletion(-)
create mode 100644 kernel/configs-debug.S
--
2.39.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/1] kernel/config: Introduce CONFIG_DEBUG_INFO_IKCONFIG
2023-10-25 22:36 [PATCH v2 0/1] Introduce CONFIG_DEBUG_INFO_IKCONFIG Stephen Brennan
@ 2023-10-25 22:36 ` Stephen Brennan
2023-10-26 15:02 ` Petr Tesařík
2023-10-26 22:52 ` kernel test robot
0 siblings, 2 replies; 5+ messages in thread
From: Stephen Brennan @ 2023-10-25 22:36 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Randy Dunlap, Stephen Brennan, linux-arch, linux-kernel,
linux-debuggers
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.
The configuration is enabled whenever DEBUG_INFO=y and IKCONFIG!=y. The
added section is not large compared to debug info sizes. It won't affect
the runtime kernel at all, and this default will ensure that
distributions intending to create useful debuginfo will get this new
addition for kernel debuggers.
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
---
include/asm-generic/vmlinux.lds.h | 3 ++-
kernel/Makefile | 1 +
kernel/configs-debug.S | 18 ++++++++++++++++++
lib/Kconfig.debug | 15 +++++++++++++++
4 files changed, 36 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..c43a874ea584 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -429,6 +429,21 @@ 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
+ default y if 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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] kernel/config: Introduce CONFIG_DEBUG_INFO_IKCONFIG
2023-10-25 22:36 ` [PATCH v2 1/1] kernel/config: " Stephen Brennan
@ 2023-10-26 15:02 ` Petr Tesařík
2023-10-26 22:52 ` kernel test robot
1 sibling, 0 replies; 5+ messages in thread
From: Petr Tesařík @ 2023-10-26 15:02 UTC (permalink / raw)
To: Stephen Brennan; +Cc: linux-debuggers
Hi Stephen,
you mentioned yesterday that you couldn't figure out how binutils
determines which sections contain debugging information. I was curious.
As expected, the logic is in libbfd. There is some helpful code and
comment in _bfd_elf_make_section_from_shdr():
if ((flags & SEC_ALLOC) == 0)
{
/* The debugging sections appear to be recognized only by name,
not any sort of flag. Their SEC_ALLOC bits are cleared. */
if (name [0] == '.')
{
if (startswith (name, ".debug")
|| startswith (name, ".gnu.debuglto_.debug_")
|| startswith (name, ".gnu.linkonce.wi.")
|| startswith (name, ".zdebug"))
flags |= SEC_DEBUGGING | SEC_ELF_OCTETS;
else if (startswith (name, GNU_BUILD_ATTRS_SECTION_NAME)
|| startswith (name, ".note.gnu"))
{
flags |= SEC_ELF_OCTETS;
opb = 1;
}
else if (startswith (name, ".line")
|| startswith (name, ".stab")
|| strcmp (name, ".gdb_index") == 0)
flags |= SEC_DEBUGGING;
}
}
Your section name starts with .debug, which looks good to me, and
definitely better than any of the alternatives.
Petr T
On Wed, 25 Oct 2023 15:36:40 -0700
Stephen Brennan <stephen.s.brennan@oracle.com> 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.
>
> 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.
>
> The configuration is enabled whenever DEBUG_INFO=y and IKCONFIG!=y. The
> added section is not large compared to debug info sizes. It won't affect
> the runtime kernel at all, and this default will ensure that
> distributions intending to create useful debuginfo will get this new
> addition for kernel debuggers.
>
> Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
> ---
> include/asm-generic/vmlinux.lds.h | 3 ++-
> kernel/Makefile | 1 +
> kernel/configs-debug.S | 18 ++++++++++++++++++
> lib/Kconfig.debug | 15 +++++++++++++++
> 4 files changed, 36 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..c43a874ea584 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -429,6 +429,21 @@ 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
> + default y if 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] kernel/config: Introduce CONFIG_DEBUG_INFO_IKCONFIG
2023-10-25 22:36 ` [PATCH v2 1/1] kernel/config: " Stephen Brennan
2023-10-26 15:02 ` Petr Tesařík
@ 2023-10-26 22:52 ` kernel test robot
2023-10-27 16:37 ` Stephen Brennan
1 sibling, 1 reply; 5+ messages in thread
From: kernel test robot @ 2023-10-26 22:52 UTC (permalink / raw)
To: Stephen Brennan, Arnd Bergmann
Cc: oe-kbuild-all, Randy Dunlap, Stephen Brennan, linux-arch,
linux-kernel, linux-debuggers
Hi Stephen,
kernel test robot noticed the following build errors:
[auto build test ERROR on soc/for-next]
[also build test ERROR on arnd-asm-generic/master linus/master v6.6-rc7 next-20231026]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Stephen-Brennan/kernel-config-Introduce-CONFIG_DEBUG_INFO_IKCONFIG/20231026-063844
base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next
patch link: https://lore.kernel.org/r/20231025223640.1132047-2-stephen.s.brennan%40oracle.com
patch subject: [PATCH v2 1/1] kernel/config: Introduce CONFIG_DEBUG_INFO_IKCONFIG
config: alpha-defconfig (https://download.01.org/0day-ci/archive/20231027/202310270605.GjEqZtAA-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231027/202310270605.GjEqZtAA-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202310270605.GjEqZtAA-lkp@intel.com/
All errors (new ones prefixed by >>):
kernel/configs-debug.S: Assembler messages:
>> kernel/configs-debug.S:17: Error: file not found: kernel/config_data.gz
vim +17 kernel/configs-debug.S
> 17 .incbin "kernel/config_data.gz"
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] kernel/config: Introduce CONFIG_DEBUG_INFO_IKCONFIG
2023-10-26 22:52 ` kernel test robot
@ 2023-10-27 16:37 ` Stephen Brennan
0 siblings, 0 replies; 5+ messages in thread
From: Stephen Brennan @ 2023-10-27 16:37 UTC (permalink / raw)
To: kernel test robot, Arnd Bergmann
Cc: oe-kbuild-all, Randy Dunlap, linux-arch, linux-kernel,
linux-debuggers
kernel test robot <lkp@intel.com> writes:
> Hi Stephen,
>
> kernel test robot noticed the following build errors:
>
> [auto build test ERROR on soc/for-next]
> [also build test ERROR on arnd-asm-generic/master linus/master v6.6-rc7 next-20231026]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url: https://github.com/intel-lab-lkp/linux/commits/Stephen-Brennan/kernel-config-Introduce-CONFIG_DEBUG_INFO_IKCONFIG/20231026-063844
> base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next
> patch link: https://lore.kernel.org/r/20231025223640.1132047-2-stephen.s.brennan%40oracle.com
> patch subject: [PATCH v2 1/1] kernel/config: Introduce CONFIG_DEBUG_INFO_IKCONFIG
> config: alpha-defconfig (https://download.01.org/0day-ci/archive/20231027/202310270605.GjEqZtAA-lkp@intel.com/config)
> compiler: alpha-linux-gcc (GCC) 13.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231027/202310270605.GjEqZtAA-lkp@intel.com/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202310270605.GjEqZtAA-lkp@intel.com/
>
> All errors (new ones prefixed by >>):
>
> kernel/configs-debug.S: Assembler messages:
>>> kernel/configs-debug.S:17: Error: file not found: kernel/config_data.gz
A silly omission on my part, v3 incoming will fix this.
> vim +17 kernel/configs-debug.S
>
> > 17 .incbin "kernel/config_data.gz"
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-27 16:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-25 22:36 [PATCH v2 0/1] Introduce CONFIG_DEBUG_INFO_IKCONFIG Stephen Brennan
2023-10-25 22:36 ` [PATCH v2 1/1] kernel/config: " Stephen Brennan
2023-10-26 15:02 ` Petr Tesařík
2023-10-26 22:52 ` kernel test robot
2023-10-27 16:37 ` Stephen Brennan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.