All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 00/13] Add build ID to stacktraces
@ 2021-04-20 21:49 ` Stephen Boyd
  0 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Alexei Starovoitov, Andy Shevchenko, Baoquan He,
	Borislav Petkov, Catalin Marinas, Dave Young, Evan Green,
	Hsin-Yi Wang, Ingo Molnar, Jessica Yu, Jiri Olsa, kexec,
	Konstantin Khlebnikov, linux-arm-kernel, linux-doc,
	Matthew Wilcox, Petr Mladek, Rasmus Villemoes, Sasha Levin,
	Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner, Vivek Goyal,
	Will Deacon, x86, Christoph Hellwig

This series adds the kernel's build ID[1] to the stacktrace header printed
in oops messages, warnings, etc. and the build ID for any module that
appears in the stacktrace after the module name. The goal is to make the
stacktrace more self-contained and descriptive by including the relevant
build IDs in the kernel logs when something goes wrong. This can be used
by post processing tools like script/decode_stacktrace.sh and kernel
developers to easily locate the debug info associated with a kernel
crash and line up what line and file things started falling apart at.

To show how this can be used I've included a patch to
decode_stacktrace.sh that downloads the debuginfo from a debuginfod
server.

This also includes some patches to make the buildid.c file use more
const arguments and consolidate logic into buildid.c from kdump. These
are left to the end as they were mostly cleanup patches. I don't know
who exactly maintains this so I guess Andrew is the best option to merge
all this code.

Here's an example lkdtm stacktrace on arm64.

 WARNING: CPU: 4 PID: 3255 at drivers/misc/lkdtm/bugs.c:83 lkdtm_WARNING+0x28/0x30 [lkdtm]
 Modules linked in: lkdtm rfcomm algif_hash algif_skcipher af_alg xt_cgroup uinput xt_MASQUERADE
 CPU: 4 PID: 3255 Comm: bash Not tainted 5.11 #3 aa23f7a1231c229de205662d5a9e0d4c580f19a1
 Hardware name: Google Lazor (rev3+) with KB Backlight (DT)
 pstate: 00400009 (nzcv daif +PAN -UAO -TCO BTYPE=--)
 pc : lkdtm_WARNING+0x28/0x30 [lkdtm]
 lr : lkdtm_do_action+0x24/0x40 [lkdtm]
 sp : ffffffc0134fbca0
 x29: ffffffc0134fbca0 x28: ffffff92d53ba240
 x27: 0000000000000000 x26: 0000000000000000
 x25: 0000000000000000 x24: ffffffe3622352c0
 x23: 0000000000000020 x22: ffffffe362233366
 x21: ffffffe3622352e0 x20: ffffffc0134fbde0
 x19: 0000000000000008 x18: 0000000000000000
 x17: ffffff929b6536fc x16: 0000000000000000
 x15: 0000000000000000 x14: 0000000000000012
 x13: ffffffe380ed892c x12: ffffffe381d05068
 x11: 0000000000000000 x10: 0000000000000000
 x9 : 0000000000000001 x8 : ffffffe362237000
 x7 : aaaaaaaaaaaaaaaa x6 : 0000000000000000
 x5 : 0000000000000000 x4 : 0000000000000001
 x3 : 0000000000000008 x2 : ffffff93fef25a70
 x1 : ffffff93fef15788 x0 : ffffffe3622352e0
 Call trace:
  lkdtm_WARNING+0x28/0x30 [lkdtm ed5019fdf5e53be37cb1ba7899292d7e143b259e]
  direct_entry+0x16c/0x1b4 [lkdtm ed5019fdf5e53be37cb1ba7899292d7e143b259e]
  full_proxy_write+0x74/0xa4
  vfs_write+0xec/0x2e8
  ksys_write+0x84/0xf0
  __arm64_sys_write+0x24/0x30
  el0_svc_common+0xf4/0x1c0
  do_el0_svc_compat+0x28/0x3c
  el0_svc_compat+0x10/0x1c
  el0_sync_compat_handler+0xa8/0xcc
  el0_sync_compat+0x178/0x180
 ---[ end trace 3d95032303e59e68 ]---

Changes from v4 (https://lore.kernel.org/r/20210410015300.3764485-1-swboyd@chromium.org):
 * Stubbed out more code when CONFIG_STACKTRACE_BUILD_ID=n
 * Use static_assert instead of BUILD_BUG_ON()
 * Dropped bad printk change to IP on x86

Changes from v3 (https://lore.kernel.org/r/20210331030520.3816265-1-swboyd@chromium.org):
 * Fixed compilation warnings due to config changes
 * Fixed kernel-doc on init_vmlinx_build_id()
 * Totally removed add_build_id_vmcoreinfo()
 * Added another printk format %pBb to help x86 print backtraces
 * Some BUILD_BUG_ON() checks to make sure the buildid doesn't get bigger or smaller

Changes from v2 (https://lore.kernel.org/r/20210324020443.1815557-1-swboyd@chromium.org):
 * Renamed symbol printing function to indicate build IDness
 * Put build ID information behind Kconfig knob
 * Build ID for vmlinux is calculated in early init instead of on demand
 * printk format is %pS[R]b

Changes from v1 (https://lore.kernel.org/r/20210301174749.1269154-1-swboyd@chromium.org):
 * New printk format %pSb and %pSr
 * Return binary format instead of hex format string from build ID APIs
 * Some new patches to cleanup buildid/decode_stacktrace.sh
 * A new patch to decode_stacktrace.sh to parse output

[1] https://fedoraproject.org/wiki/Releases/FeatureBuildId

Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: <kexec@lists.infradead.org>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: <linux-doc@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Sasha Levin <sashal@kernel.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Will Deacon <will@kernel.org>
Cc: <x86@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: peter enderborg <peter.
Stephen Boyd (13):
  buildid: Only consider GNU notes for build ID parsing
  buildid: Add API to parse build ID out of buffer
  buildid: Stash away kernels build ID on init
  dump_stack: Add vmlinux build ID to stack traces
  module: Add printk formats to add module build ID to stacktraces
  arm64: stacktrace: Use %pSb for backtrace printing
  x86/dumpstack: Use %pSb/%pBb for backtrace printing
  scripts/decode_stacktrace.sh: Support debuginfod
  scripts/decode_stacktrace.sh: Silence stderr messages from
    addr2line/nm
  scripts/decode_stacktrace.sh: Indicate 'auto' can be used for base
    path
  buildid: Mark some arguments const
  buildid: Fix kernel-doc notation
  kdump: Use vmlinux_build_id to simplify

 Documentation/core-api/printk-formats.rst |  11 +++
 arch/arm64/kernel/stacktrace.c            |   2 +-
 arch/x86/kernel/dumpstack.c               |   2 +-
 include/linux/buildid.h                   |   8 ++
 include/linux/crash_core.h                |  12 +--
 include/linux/kallsyms.h                  |  20 ++++-
 include/linux/module.h                    |   8 +-
 init/main.c                               |   1 +
 kernel/crash_core.c                       |  50 +----------
 kernel/kallsyms.c                         | 101 +++++++++++++++++-----
 kernel/module.c                           |  31 ++++++-
 lib/Kconfig.debug                         |  11 +++
 lib/buildid.c                             |  74 ++++++++++++----
 lib/dump_stack.c                          |  13 ++-
 lib/vsprintf.c                            |   8 +-
 scripts/decode_stacktrace.sh              |  89 +++++++++++++++----
 16 files changed, 327 insertions(+), 114 deletions(-)


base-commit: a38fd8748464831584a19438cbb3082b5a2dab15
-- 
https://chromeos.dev


^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH v5 00/13] Add build ID to stacktraces
@ 2021-04-20 21:49 ` Stephen Boyd
  0 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Alexei Starovoitov, Andy Shevchenko, Baoquan He,
	Borislav Petkov, Catalin Marinas, Dave Young, Evan Green,
	Hsin-Yi Wang, Ingo Molnar, Jessica Yu, Jiri Olsa, kexec,
	Konstantin Khlebnikov, linux-arm-kernel, linux-doc,
	Matthew Wilcox, Petr Mladek, Rasmus Villemoes, Sasha Levin,
	Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner, Vivek Goyal,
	Will Deacon, x86, Christoph Hellwig

This series adds the kernel's build ID[1] to the stacktrace header printed
in oops messages, warnings, etc. and the build ID for any module that
appears in the stacktrace after the module name. The goal is to make the
stacktrace more self-contained and descriptive by including the relevant
build IDs in the kernel logs when something goes wrong. This can be used
by post processing tools like script/decode_stacktrace.sh and kernel
developers to easily locate the debug info associated with a kernel
crash and line up what line and file things started falling apart at.

To show how this can be used I've included a patch to
decode_stacktrace.sh that downloads the debuginfo from a debuginfod
server.

This also includes some patches to make the buildid.c file use more
const arguments and consolidate logic into buildid.c from kdump. These
are left to the end as they were mostly cleanup patches. I don't know
who exactly maintains this so I guess Andrew is the best option to merge
all this code.

Here's an example lkdtm stacktrace on arm64.

 WARNING: CPU: 4 PID: 3255 at drivers/misc/lkdtm/bugs.c:83 lkdtm_WARNING+0x28/0x30 [lkdtm]
 Modules linked in: lkdtm rfcomm algif_hash algif_skcipher af_alg xt_cgroup uinput xt_MASQUERADE
 CPU: 4 PID: 3255 Comm: bash Not tainted 5.11 #3 aa23f7a1231c229de205662d5a9e0d4c580f19a1
 Hardware name: Google Lazor (rev3+) with KB Backlight (DT)
 pstate: 00400009 (nzcv daif +PAN -UAO -TCO BTYPE=--)
 pc : lkdtm_WARNING+0x28/0x30 [lkdtm]
 lr : lkdtm_do_action+0x24/0x40 [lkdtm]
 sp : ffffffc0134fbca0
 x29: ffffffc0134fbca0 x28: ffffff92d53ba240
 x27: 0000000000000000 x26: 0000000000000000
 x25: 0000000000000000 x24: ffffffe3622352c0
 x23: 0000000000000020 x22: ffffffe362233366
 x21: ffffffe3622352e0 x20: ffffffc0134fbde0
 x19: 0000000000000008 x18: 0000000000000000
 x17: ffffff929b6536fc x16: 0000000000000000
 x15: 0000000000000000 x14: 0000000000000012
 x13: ffffffe380ed892c x12: ffffffe381d05068
 x11: 0000000000000000 x10: 0000000000000000
 x9 : 0000000000000001 x8 : ffffffe362237000
 x7 : aaaaaaaaaaaaaaaa x6 : 0000000000000000
 x5 : 0000000000000000 x4 : 0000000000000001
 x3 : 0000000000000008 x2 : ffffff93fef25a70
 x1 : ffffff93fef15788 x0 : ffffffe3622352e0
 Call trace:
  lkdtm_WARNING+0x28/0x30 [lkdtm ed5019fdf5e53be37cb1ba7899292d7e143b259e]
  direct_entry+0x16c/0x1b4 [lkdtm ed5019fdf5e53be37cb1ba7899292d7e143b259e]
  full_proxy_write+0x74/0xa4
  vfs_write+0xec/0x2e8
  ksys_write+0x84/0xf0
  __arm64_sys_write+0x24/0x30
  el0_svc_common+0xf4/0x1c0
  do_el0_svc_compat+0x28/0x3c
  el0_svc_compat+0x10/0x1c
  el0_sync_compat_handler+0xa8/0xcc
  el0_sync_compat+0x178/0x180
 ---[ end trace 3d95032303e59e68 ]---

Changes from v4 (https://lore.kernel.org/r/20210410015300.3764485-1-swboyd@chromium.org):
 * Stubbed out more code when CONFIG_STACKTRACE_BUILD_ID=n
 * Use static_assert instead of BUILD_BUG_ON()
 * Dropped bad printk change to IP on x86

Changes from v3 (https://lore.kernel.org/r/20210331030520.3816265-1-swboyd@chromium.org):
 * Fixed compilation warnings due to config changes
 * Fixed kernel-doc on init_vmlinx_build_id()
 * Totally removed add_build_id_vmcoreinfo()
 * Added another printk format %pBb to help x86 print backtraces
 * Some BUILD_BUG_ON() checks to make sure the buildid doesn't get bigger or smaller

Changes from v2 (https://lore.kernel.org/r/20210324020443.1815557-1-swboyd@chromium.org):
 * Renamed symbol printing function to indicate build IDness
 * Put build ID information behind Kconfig knob
 * Build ID for vmlinux is calculated in early init instead of on demand
 * printk format is %pS[R]b

Changes from v1 (https://lore.kernel.org/r/20210301174749.1269154-1-swboyd@chromium.org):
 * New printk format %pSb and %pSr
 * Return binary format instead of hex format string from build ID APIs
 * Some new patches to cleanup buildid/decode_stacktrace.sh
 * A new patch to decode_stacktrace.sh to parse output

[1] https://fedoraproject.org/wiki/Releases/FeatureBuildId

Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: <kexec@lists.infradead.org>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: <linux-doc@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Sasha Levin <sashal@kernel.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Will Deacon <will@kernel.org>
Cc: <x86@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: peter enderborg <peter.
Stephen Boyd (13):
  buildid: Only consider GNU notes for build ID parsing
  buildid: Add API to parse build ID out of buffer
  buildid: Stash away kernels build ID on init
  dump_stack: Add vmlinux build ID to stack traces
  module: Add printk formats to add module build ID to stacktraces
  arm64: stacktrace: Use %pSb for backtrace printing
  x86/dumpstack: Use %pSb/%pBb for backtrace printing
  scripts/decode_stacktrace.sh: Support debuginfod
  scripts/decode_stacktrace.sh: Silence stderr messages from
    addr2line/nm
  scripts/decode_stacktrace.sh: Indicate 'auto' can be used for base
    path
  buildid: Mark some arguments const
  buildid: Fix kernel-doc notation
  kdump: Use vmlinux_build_id to simplify

 Documentation/core-api/printk-formats.rst |  11 +++
 arch/arm64/kernel/stacktrace.c            |   2 +-
 arch/x86/kernel/dumpstack.c               |   2 +-
 include/linux/buildid.h                   |   8 ++
 include/linux/crash_core.h                |  12 +--
 include/linux/kallsyms.h                  |  20 ++++-
 include/linux/module.h                    |   8 +-
 init/main.c                               |   1 +
 kernel/crash_core.c                       |  50 +----------
 kernel/kallsyms.c                         | 101 +++++++++++++++++-----
 kernel/module.c                           |  31 ++++++-
 lib/Kconfig.debug                         |  11 +++
 lib/buildid.c                             |  74 ++++++++++++----
 lib/dump_stack.c                          |  13 ++-
 lib/vsprintf.c                            |   8 +-
 scripts/decode_stacktrace.sh              |  89 +++++++++++++++----
 16 files changed, 327 insertions(+), 114 deletions(-)


base-commit: a38fd8748464831584a19438cbb3082b5a2dab15
-- 
https://chromeos.dev


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH v5 00/13] Add build ID to stacktraces
@ 2021-04-20 21:49 ` Stephen Boyd
  0 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Alexei Starovoitov, Andy Shevchenko, Baoquan He,
	Borislav Petkov, Catalin Marinas, Dave Young, Evan Green,
	Hsin-Yi Wang, Ingo Molnar, Jessica Yu, Jiri Olsa, kexec,
	Konstantin Khlebnikov, linux-arm-kernel, linux-doc,
	Matthew Wilcox, Petr Mladek, Rasmus Villemoes, Sasha Levin,
	Sergey Senozhatsky, Steven Rostedt, Thomas Gleixner, Vivek Goyal,
	Will Deacon, x86, Christoph Hellwig

This series adds the kernel's build ID[1] to the stacktrace header printed
in oops messages, warnings, etc. and the build ID for any module that
appears in the stacktrace after the module name. The goal is to make the
stacktrace more self-contained and descriptive by including the relevant
build IDs in the kernel logs when something goes wrong. This can be used
by post processing tools like script/decode_stacktrace.sh and kernel
developers to easily locate the debug info associated with a kernel
crash and line up what line and file things started falling apart at.

To show how this can be used I've included a patch to
decode_stacktrace.sh that downloads the debuginfo from a debuginfod
server.

This also includes some patches to make the buildid.c file use more
const arguments and consolidate logic into buildid.c from kdump. These
are left to the end as they were mostly cleanup patches. I don't know
who exactly maintains this so I guess Andrew is the best option to merge
all this code.

Here's an example lkdtm stacktrace on arm64.

 WARNING: CPU: 4 PID: 3255 at drivers/misc/lkdtm/bugs.c:83 lkdtm_WARNING+0x28/0x30 [lkdtm]
 Modules linked in: lkdtm rfcomm algif_hash algif_skcipher af_alg xt_cgroup uinput xt_MASQUERADE
 CPU: 4 PID: 3255 Comm: bash Not tainted 5.11 #3 aa23f7a1231c229de205662d5a9e0d4c580f19a1
 Hardware name: Google Lazor (rev3+) with KB Backlight (DT)
 pstate: 00400009 (nzcv daif +PAN -UAO -TCO BTYPE=--)
 pc : lkdtm_WARNING+0x28/0x30 [lkdtm]
 lr : lkdtm_do_action+0x24/0x40 [lkdtm]
 sp : ffffffc0134fbca0
 x29: ffffffc0134fbca0 x28: ffffff92d53ba240
 x27: 0000000000000000 x26: 0000000000000000
 x25: 0000000000000000 x24: ffffffe3622352c0
 x23: 0000000000000020 x22: ffffffe362233366
 x21: ffffffe3622352e0 x20: ffffffc0134fbde0
 x19: 0000000000000008 x18: 0000000000000000
 x17: ffffff929b6536fc x16: 0000000000000000
 x15: 0000000000000000 x14: 0000000000000012
 x13: ffffffe380ed892c x12: ffffffe381d05068
 x11: 0000000000000000 x10: 0000000000000000
 x9 : 0000000000000001 x8 : ffffffe362237000
 x7 : aaaaaaaaaaaaaaaa x6 : 0000000000000000
 x5 : 0000000000000000 x4 : 0000000000000001
 x3 : 0000000000000008 x2 : ffffff93fef25a70
 x1 : ffffff93fef15788 x0 : ffffffe3622352e0
 Call trace:
  lkdtm_WARNING+0x28/0x30 [lkdtm ed5019fdf5e53be37cb1ba7899292d7e143b259e]
  direct_entry+0x16c/0x1b4 [lkdtm ed5019fdf5e53be37cb1ba7899292d7e143b259e]
  full_proxy_write+0x74/0xa4
  vfs_write+0xec/0x2e8
  ksys_write+0x84/0xf0
  __arm64_sys_write+0x24/0x30
  el0_svc_common+0xf4/0x1c0
  do_el0_svc_compat+0x28/0x3c
  el0_svc_compat+0x10/0x1c
  el0_sync_compat_handler+0xa8/0xcc
  el0_sync_compat+0x178/0x180
 ---[ end trace 3d95032303e59e68 ]---

Changes from v4 (https://lore.kernel.org/r/20210410015300.3764485-1-swboyd@chromium.org):
 * Stubbed out more code when CONFIG_STACKTRACE_BUILD_ID=n
 * Use static_assert instead of BUILD_BUG_ON()
 * Dropped bad printk change to IP on x86

Changes from v3 (https://lore.kernel.org/r/20210331030520.3816265-1-swboyd@chromium.org):
 * Fixed compilation warnings due to config changes
 * Fixed kernel-doc on init_vmlinx_build_id()
 * Totally removed add_build_id_vmcoreinfo()
 * Added another printk format %pBb to help x86 print backtraces
 * Some BUILD_BUG_ON() checks to make sure the buildid doesn't get bigger or smaller

Changes from v2 (https://lore.kernel.org/r/20210324020443.1815557-1-swboyd@chromium.org):
 * Renamed symbol printing function to indicate build IDness
 * Put build ID information behind Kconfig knob
 * Build ID for vmlinux is calculated in early init instead of on demand
 * printk format is %pS[R]b

Changes from v1 (https://lore.kernel.org/r/20210301174749.1269154-1-swboyd@chromium.org):
 * New printk format %pSb and %pSr
 * Return binary format instead of hex format string from build ID APIs
 * Some new patches to cleanup buildid/decode_stacktrace.sh
 * A new patch to decode_stacktrace.sh to parse output

[1] https://fedoraproject.org/wiki/Releases/FeatureBuildId

Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: <kexec@lists.infradead.org>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: <linux-doc@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Sasha Levin <sashal@kernel.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Will Deacon <will@kernel.org>
Cc: <x86@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: peter enderborg <peter.
Stephen Boyd (13):
  buildid: Only consider GNU notes for build ID parsing
  buildid: Add API to parse build ID out of buffer
  buildid: Stash away kernels build ID on init
  dump_stack: Add vmlinux build ID to stack traces
  module: Add printk formats to add module build ID to stacktraces
  arm64: stacktrace: Use %pSb for backtrace printing
  x86/dumpstack: Use %pSb/%pBb for backtrace printing
  scripts/decode_stacktrace.sh: Support debuginfod
  scripts/decode_stacktrace.sh: Silence stderr messages from
    addr2line/nm
  scripts/decode_stacktrace.sh: Indicate 'auto' can be used for base
    path
  buildid: Mark some arguments const
  buildid: Fix kernel-doc notation
  kdump: Use vmlinux_build_id to simplify

 Documentation/core-api/printk-formats.rst |  11 +++
 arch/arm64/kernel/stacktrace.c            |   2 +-
 arch/x86/kernel/dumpstack.c               |   2 +-
 include/linux/buildid.h                   |   8 ++
 include/linux/crash_core.h                |  12 +--
 include/linux/kallsyms.h                  |  20 ++++-
 include/linux/module.h                    |   8 +-
 init/main.c                               |   1 +
 kernel/crash_core.c                       |  50 +----------
 kernel/kallsyms.c                         | 101 +++++++++++++++++-----
 kernel/module.c                           |  31 ++++++-
 lib/Kconfig.debug                         |  11 +++
 lib/buildid.c                             |  74 ++++++++++++----
 lib/dump_stack.c                          |  13 ++-
 lib/vsprintf.c                            |   8 +-
 scripts/decode_stacktrace.sh              |  89 +++++++++++++++----
 16 files changed, 327 insertions(+), 114 deletions(-)


base-commit: a38fd8748464831584a19438cbb3082b5a2dab15
-- 
https://chromeos.dev


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH v5 01/13] buildid: Only consider GNU notes for build ID parsing
  2021-04-20 21:49 ` Stephen Boyd
  (?)
  (?)
@ 2021-04-20 21:49 ` Stephen Boyd
  -1 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Petr Mladek, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang

Some kernel elf files have various notes that also happen to have an elf
note type of '3', which matches NT_GNU_BUILD_ID but the note name isn't
"GNU". For example, this note trips up the existing logic:

 Owner  Data size   Description
 Xen    0x00000008  Unknown note type: (0x00000003) description data: 00 00 00 ffffff80 ffffffff ffffffff ffffffff ffffffff

Let's make sure that it is a GNU note when parsing the build ID so that
we can use this function to parse a vmlinux's build ID too.

Reported-by: Petr Mladek <pmladek@suse.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Fixes: bd7525dacd7e ("bpf: Move stack_map_get_build_id into lib")
Tested-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 lib/buildid.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/buildid.c b/lib/buildid.c
index 6156997c3895..e014636ec3eb 100644
--- a/lib/buildid.c
+++ b/lib/buildid.c
@@ -31,6 +31,7 @@ static inline int parse_build_id(void *page_addr,
 
 		if (nhdr->n_type == BUILD_ID &&
 		    nhdr->n_namesz == sizeof("GNU") &&
+		    !strcmp((char *)(nhdr + 1), "GNU") &&
 		    nhdr->n_descsz > 0 &&
 		    nhdr->n_descsz <= BUILD_ID_SIZE_MAX) {
 			memcpy(build_id,
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 02/13] buildid: Add API to parse build ID out of buffer
  2021-04-20 21:49 ` Stephen Boyd
                   ` (2 preceding siblings ...)
  (?)
@ 2021-04-20 21:49 ` Stephen Boyd
  -1 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jiri Olsa, Alexei Starovoitov, Jessica Yu,
	Evan Green, Hsin-Yi Wang

Add an API that can parse the build ID out of a buffer, instead of a
vma, to support printing a kernel module's build ID for stack traces.

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 include/linux/buildid.h |  1 +
 lib/buildid.c           | 50 ++++++++++++++++++++++++++++++-----------
 2 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/include/linux/buildid.h b/include/linux/buildid.h
index 40232f90db6e..ebce93f26d06 100644
--- a/include/linux/buildid.h
+++ b/include/linux/buildid.h
@@ -8,5 +8,6 @@
 
 int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
 		   __u32 *size);
+int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size);
 
 #endif
diff --git a/lib/buildid.c b/lib/buildid.c
index e014636ec3eb..6aea1c4e5e85 100644
--- a/lib/buildid.c
+++ b/lib/buildid.c
@@ -2,30 +2,23 @@
 
 #include <linux/buildid.h>
 #include <linux/elf.h>
+#include <linux/kernel.h>
 #include <linux/pagemap.h>
 
 #define BUILD_ID 3
+
 /*
  * Parse build id from the note segment. This logic can be shared between
  * 32-bit and 64-bit system, because Elf32_Nhdr and Elf64_Nhdr are
  * identical.
  */
-static inline int parse_build_id(void *page_addr,
-				 unsigned char *build_id,
-				 __u32 *size,
-				 void *note_start,
-				 Elf32_Word note_size)
+static int parse_build_id_buf(unsigned char *build_id,
+			      __u32 *size,
+			      const void *note_start,
+			      Elf32_Word note_size)
 {
 	Elf32_Word note_offs = 0, new_offs;
 
-	/* check for overflow */
-	if (note_start < page_addr || note_start + note_size < note_start)
-		return -EINVAL;
-
-	/* only supports note that fits in the first page */
-	if (note_start + note_size > page_addr + PAGE_SIZE)
-		return -EINVAL;
-
 	while (note_offs + sizeof(Elf32_Nhdr) < note_size) {
 		Elf32_Nhdr *nhdr = (Elf32_Nhdr *)(note_start + note_offs);
 
@@ -50,9 +43,27 @@ static inline int parse_build_id(void *page_addr,
 			break;
 		note_offs = new_offs;
 	}
+
 	return -EINVAL;
 }
 
+static inline int parse_build_id(void *page_addr,
+				 unsigned char *build_id,
+				 __u32 *size,
+				 void *note_start,
+				 Elf32_Word note_size)
+{
+	/* check for overflow */
+	if (note_start < page_addr || note_start + note_size < note_start)
+		return -EINVAL;
+
+	/* only supports note that fits in the first page */
+	if (note_start + note_size > page_addr + PAGE_SIZE)
+		return -EINVAL;
+
+	return parse_build_id_buf(build_id, size, note_start, note_size);
+}
+
 /* Parse build ID from 32-bit ELF */
 static int get_build_id_32(void *page_addr, unsigned char *build_id,
 			   __u32 *size)
@@ -148,3 +159,16 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
 	put_page(page);
 	return ret;
 }
+
+/**
+ * build_id_parse_buf - Get build ID from a buffer
+ * @buf:      Elf note section(s) to parse
+ * @buf_size: Size of @buf in bytes
+ * @build_id: Build ID parsed from @buf, at least BUILD_ID_SIZE_MAX long
+ *
+ * Return: 0 on success, -EINVAL otherwise
+ */
+int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size)
+{
+	return parse_build_id_buf(build_id, NULL, buf, buf_size);
+}
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 03/13] buildid: Stash away kernels build ID on init
  2021-04-20 21:49 ` Stephen Boyd
@ 2021-04-20 21:49   ` Stephen Boyd
  -1 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jiri Olsa, Alexei Starovoitov, Jessica Yu,
	Evan Green, Hsin-Yi Wang, Dave Young, Baoquan He, Vivek Goyal,
	kexec

Parse the kernel's build ID at initialization so that other code can
print a hex format string representation of the running kernel's build
ID. This will be used in the kdump and dump_stack code so that
developers can easily locate the vmlinux debug symbols for a
crash/stacktrace.

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Dave Young <dyoung@redhat.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: <kexec@lists.infradead.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 include/linux/buildid.h |  3 +++
 init/main.c             |  1 +
 lib/buildid.c           | 15 +++++++++++++++
 3 files changed, 19 insertions(+)

diff --git a/include/linux/buildid.h b/include/linux/buildid.h
index ebce93f26d06..f375900cf9ed 100644
--- a/include/linux/buildid.h
+++ b/include/linux/buildid.h
@@ -10,4 +10,7 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
 		   __u32 *size);
 int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size);
 
+extern unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX];
+void init_vmlinux_build_id(void);
+
 #endif
diff --git a/init/main.c b/init/main.c
index 53b278845b88..eaede2f41327 100644
--- a/init/main.c
+++ b/init/main.c
@@ -857,6 +857,7 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	set_task_stack_end_magic(&init_task);
 	smp_setup_processor_id();
 	debug_objects_early_init();
+	init_vmlinux_build_id();
 
 	cgroup_init_early();
 
diff --git a/lib/buildid.c b/lib/buildid.c
index 6aea1c4e5e85..1103ed46214f 100644
--- a/lib/buildid.c
+++ b/lib/buildid.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 #include <linux/buildid.h>
+#include <linux/cache.h>
 #include <linux/elf.h>
 #include <linux/kernel.h>
 #include <linux/pagemap.h>
@@ -172,3 +173,17 @@ int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size)
 {
 	return parse_build_id_buf(build_id, NULL, buf, buf_size);
 }
+
+unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX] __ro_after_init;
+
+/**
+ * init_vmlinux_build_id - Compute and stash the running kernel's build ID
+ */
+void __init init_vmlinux_build_id(void)
+{
+	extern const void __start_notes __weak;
+	extern const void __stop_notes __weak;
+	unsigned int size = &__stop_notes - &__start_notes;
+
+	build_id_parse_buf(&__start_notes, vmlinux_build_id, size);
+}
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 03/13] buildid: Stash away kernels build ID on init
@ 2021-04-20 21:49   ` Stephen Boyd
  0 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jiri Olsa, Alexei Starovoitov, Jessica Yu,
	Evan Green, Hsin-Yi Wang, Dave Young, Baoquan He, Vivek Goyal,
	kexec

Parse the kernel's build ID at initialization so that other code can
print a hex format string representation of the running kernel's build
ID. This will be used in the kdump and dump_stack code so that
developers can easily locate the vmlinux debug symbols for a
crash/stacktrace.

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Dave Young <dyoung@redhat.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: <kexec@lists.infradead.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 include/linux/buildid.h |  3 +++
 init/main.c             |  1 +
 lib/buildid.c           | 15 +++++++++++++++
 3 files changed, 19 insertions(+)

diff --git a/include/linux/buildid.h b/include/linux/buildid.h
index ebce93f26d06..f375900cf9ed 100644
--- a/include/linux/buildid.h
+++ b/include/linux/buildid.h
@@ -10,4 +10,7 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
 		   __u32 *size);
 int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size);
 
+extern unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX];
+void init_vmlinux_build_id(void);
+
 #endif
diff --git a/init/main.c b/init/main.c
index 53b278845b88..eaede2f41327 100644
--- a/init/main.c
+++ b/init/main.c
@@ -857,6 +857,7 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	set_task_stack_end_magic(&init_task);
 	smp_setup_processor_id();
 	debug_objects_early_init();
+	init_vmlinux_build_id();
 
 	cgroup_init_early();
 
diff --git a/lib/buildid.c b/lib/buildid.c
index 6aea1c4e5e85..1103ed46214f 100644
--- a/lib/buildid.c
+++ b/lib/buildid.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 #include <linux/buildid.h>
+#include <linux/cache.h>
 #include <linux/elf.h>
 #include <linux/kernel.h>
 #include <linux/pagemap.h>
@@ -172,3 +173,17 @@ int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size)
 {
 	return parse_build_id_buf(build_id, NULL, buf, buf_size);
 }
+
+unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX] __ro_after_init;
+
+/**
+ * init_vmlinux_build_id - Compute and stash the running kernel's build ID
+ */
+void __init init_vmlinux_build_id(void)
+{
+	extern const void __start_notes __weak;
+	extern const void __stop_notes __weak;
+	unsigned int size = &__stop_notes - &__start_notes;
+
+	build_id_parse_buf(&__start_notes, vmlinux_build_id, size);
+}
-- 
https://chromeos.dev


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 04/13] dump_stack: Add vmlinux build ID to stack traces
  2021-04-20 21:49 ` Stephen Boyd
                   ` (4 preceding siblings ...)
  (?)
@ 2021-04-20 21:49 ` Stephen Boyd
  2021-04-26 11:04   ` Petr Mladek
  -1 siblings, 1 reply; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jiri Olsa, Alexei Starovoitov, Jessica Yu,
	Evan Green, Hsin-Yi Wang, Petr Mladek, Steven Rostedt,
	Andy Shevchenko, Matthew Wilcox

Add the running kernel's build ID[1] to the stacktrace information
header.  This makes it simpler for developers to locate the vmlinux with
full debuginfo for a particular kernel stacktrace. Combined with
scripts/decode_stracktrace.sh, a developer can download the correct
vmlinux from a debuginfod[2] server and find the exact file and line
number for the functions plus offsets in a stacktrace.

This is especially useful for pstore crash debugging where the kernel
crashes are recorded in the pstore logs and the recovery kernel is
different or the debuginfo doesn't exist on the device due to space
concerns (the data can be large and a security concern). The stacktrace
can be analyzed after the crash by using the build ID to find the
matching vmlinux and understand where in the function something went
wrong.

Example stacktrace from lkdtm:

 WARNING: CPU: 4 PID: 3255 at drivers/misc/lkdtm/bugs.c:83 lkdtm_WARNING+0x28/0x30 [lkdtm]
 Modules linked in: lkdtm rfcomm algif_hash algif_skcipher af_alg xt_cgroup uinput xt_MASQUERADE
 CPU: 4 PID: 3255 Comm: bash Not tainted 5.11 #3 aa23f7a1231c229de205662d5a9e0d4c580f19a1
 Hardware name: Google Lazor (rev3+) with KB Backlight (DT)
 pstate: 00400009 (nzcv daif +PAN -UAO -TCO BTYPE=--)
 pc : lkdtm_WARNING+0x28/0x30 [lkdtm]

The hex string aa23f7a1231c229de205662d5a9e0d4c580f19a1 is the build ID,
following the kernel version number. Put it all behind a config option,
STACKTRACE_BUILD_ID, so that kernel developers can remove this
information if they decide it is too much.

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Link: https://fedoraproject.org/wiki/Releases/FeatureBuildId [1]
Link: https://sourceware.org/elfutils/Debuginfod.html [2]
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 include/linux/buildid.h |  4 ++++
 lib/Kconfig.debug       | 11 +++++++++++
 lib/buildid.c           |  2 ++
 lib/dump_stack.c        | 13 +++++++++++--
 4 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/include/linux/buildid.h b/include/linux/buildid.h
index f375900cf9ed..3b7a0ff4642f 100644
--- a/include/linux/buildid.h
+++ b/include/linux/buildid.h
@@ -10,7 +10,11 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
 		   __u32 *size);
 int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size);
 
+#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) || IS_ENABLED(CONFIG_CRASH_CORE)
 extern unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX];
 void init_vmlinux_build_id(void);
+#else
+static inline void init_vmlinux_build_id(void) { }
+#endif
 
 #endif
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 2779c29d9981..5f883e50f406 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -35,6 +35,17 @@ config PRINTK_CALLER
 	  no option to enable/disable at the kernel command line parameter or
 	  sysfs interface.
 
+config STACKTRACE_BUILD_ID
+	bool "Show build ID information in stacktraces"
+	depends on PRINTK
+	help
+	  Selecting this option adds build ID information for symbols in
+	  stacktraces printed with the printk format '%p[SR]b'.
+
+	  This option is intended for distros where debuginfo is not easily
+	  accessible but can be downloaded given the build ID of the vmlinux or
+	  kernel module where the function is located.
+
 config CONSOLE_LOGLEVEL_DEFAULT
 	int "Default console loglevel (1-15)"
 	range 1 15
diff --git a/lib/buildid.c b/lib/buildid.c
index 1103ed46214f..530dbd1f6bbe 100644
--- a/lib/buildid.c
+++ b/lib/buildid.c
@@ -174,6 +174,7 @@ int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size)
 	return parse_build_id_buf(build_id, NULL, buf, buf_size);
 }
 
+#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) || IS_ENABLED(CONFIG_CRASH_CORE)
 unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX] __ro_after_init;
 
 /**
@@ -187,3 +188,4 @@ void __init init_vmlinux_build_id(void)
 
 	build_id_parse_buf(&__start_notes, vmlinux_build_id, size);
 }
+#endif
diff --git a/lib/dump_stack.c b/lib/dump_stack.c
index f5a33b6f773f..d685331b065f 100644
--- a/lib/dump_stack.c
+++ b/lib/dump_stack.c
@@ -5,6 +5,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/buildid.h>
 #include <linux/export.h>
 #include <linux/sched.h>
 #include <linux/sched/debug.h>
@@ -36,6 +37,14 @@ void __init dump_stack_set_arch_desc(const char *fmt, ...)
 	va_end(args);
 }
 
+#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
+#define BUILD_ID_FMT " %20phN"
+#define BUILD_ID_VAL vmlinux_build_id
+#else
+#define BUILD_ID_FMT "%s"
+#define BUILD_ID_VAL ""
+#endif
+
 /**
  * dump_stack_print_info - print generic debug info for dump_stack()
  * @log_lvl: log level
@@ -45,13 +54,13 @@ void __init dump_stack_set_arch_desc(const char *fmt, ...)
  */
 void dump_stack_print_info(const char *log_lvl)
 {
-	printk("%sCPU: %d PID: %d Comm: %.20s %s%s %s %.*s\n",
+	printk("%sCPU: %d PID: %d Comm: %.20s %s%s %s %.*s" BUILD_ID_FMT "\n",
 	       log_lvl, raw_smp_processor_id(), current->pid, current->comm,
 	       kexec_crash_loaded() ? "Kdump: loaded " : "",
 	       print_tainted(),
 	       init_utsname()->release,
 	       (int)strcspn(init_utsname()->version, " "),
-	       init_utsname()->version);
+	       init_utsname()->version, BUILD_ID_VAL);
 
 	if (dump_stack_arch_desc_str[0] != '\0')
 		printk("%sHardware name: %s\n",
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 05/13] module: Add printk formats to add module build ID to stacktraces
  2021-04-20 21:49 ` Stephen Boyd
                   ` (5 preceding siblings ...)
  (?)
@ 2021-04-20 21:49 ` Stephen Boyd
  2021-04-21 11:49   ` Andy Shevchenko
  -1 siblings, 1 reply; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jiri Olsa, Alexei Starovoitov, Jessica Yu,
	Evan Green, Hsin-Yi Wang, Petr Mladek, Steven Rostedt,
	Sergey Senozhatsky, Andy Shevchenko, Rasmus Villemoes, linux-doc,
	Matthew Wilcox

Let's make kernel stacktraces easier to identify by including the build
ID[1] of a module if the stacktrace is printing a symbol from a module.
This makes it simpler for developers to locate a kernel module's full
debuginfo for a particular stacktrace. Combined with
scripts/decode_stracktrace.sh, a developer can download the matching
debuginfo from a debuginfod[2] server and find the exact file and line
number for the functions plus offsets in a stacktrace that match the
module. This is especially useful for pstore crash debugging where the
kernel crashes are recorded in something like console-ramoops and the
recovery kernel/modules are different or the debuginfo doesn't exist on
the device due to space concerns (the debuginfo can be too large for
space limited devices).

Originally, I put this on the %pS format, but that was quickly rejected
given that %pS is used in other places such as ftrace where build IDs
aren't meaningful. There was some discussions on the list to put every
module build ID into the "Modules linked in:" section of the stacktrace
message but that quickly becomes very hard to read once you have more
than three or four modules linked in. It also provides too much
information when we don't expect each module to be traversed in a
stacktrace. Having the build ID for modules that aren't important just
makes things messy. Splitting it to multiple lines for each module
quickly explodes the number of lines printed in an oops too, possibly
wrapping the warning off the console. And finally, trying to stash away
each module used in a callstack to provide the ID of each symbol printed
is cumbersome and would require changes to each architecture to stash
away modules and return their build IDs once unwinding has completed.

Instead, we opt for the simpler approach of introducing new printk
formats '%pS[R]b' for "pointer symbolic backtrace with module build ID"
and '%pBb' for "pointer backtrace with module build ID" and then
updating the few places in the architecture layer where the stacktrace
is printed to use this new format.

Example:

 WARNING: CPU: 3 PID: 3373 at drivers/misc/lkdtm/bugs.c:83 lkdtm_WARNING+0x28/0x30 [lkdtm]
 Modules linked in: lkdtm rfcomm algif_hash algif_skcipher af_alg xt_cgroup uinput xt_MASQUERADE hci_uart <modules trimmed>
 CPU: 3 PID: 3373 Comm: bash Not tainted 5.11 #12 a8c0d47f7051f3e6670ceaea724af66a39c6cec8
 Hardware name: Google Lazor (rev3+) with KB Backlight (DT)
 pstate: 00400009 (nzcv daif +PAN -UAO -TCO BTYPE=--)
 pc : lkdtm_WARNING+0x28/0x30 [lkdtm]
 lr : lkdtm_do_action+0x24/0x40 [lkdtm]
 sp : ffffffc013febca0
 x29: ffffffc013febca0 x28: ffffff88d9438040
 x27: 0000000000000000 x26: 0000000000000000
 x25: 0000000000000000 x24: ffffffdd0e9772c0
 x23: 0000000000000020 x22: ffffffdd0e975366
 x21: ffffffdd0e9772e0 x20: ffffffc013febde0
 x19: 0000000000000008 x18: 0000000000000000
 x17: 0000000000000000 x16: 0000000000000037
 x15: ffffffdd102ab174 x14: 0000000000000003
 x13: 0000000000000004 x12: 0000000000000000
 x11: 0000000000000000 x10: 0000000000000000
 x9 : 0000000000000001 x8 : ffffffdd0e979000
 x7 : 0000000000000000 x6 : ffffffdd10ff6b54
 x5 : 0000000000000000 x4 : 0000000000000000
 x3 : ffffffc013feb938 x2 : ffffff89fef05a70
 x1 : ffffff89feef5788 x0 : ffffffdd0e9772e0
 Call trace:
  lkdtm_WARNING+0x28/0x30 [lkdtm 6c2215028606bda50de823490723dc4bc5bf46f9]
  direct_entry+0x16c/0x1b4 [lkdtm 6c2215028606bda50de823490723dc4bc5bf46f9]
  full_proxy_write+0x74/0xa4
  vfs_write+0xec/0x2e8
  ksys_write+0x84/0xf0
  __arm64_sys_write+0x24/0x30
  el0_svc_common+0xf4/0x1c0
  do_el0_svc_compat+0x28/0x3c
  el0_svc_compat+0x10/0x1c
  el0_sync_compat_handler+0xa8/0xcc
  el0_sync_compat+0x178/0x180
 ---[ end trace f89bc7f5417cbcc6 ]---

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: <linux-doc@vger.kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Link: https://fedoraproject.org/wiki/Releases/FeatureBuildId [1]
Link: https://sourceware.org/elfutils/Debuginfod.html [2]
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 Documentation/core-api/printk-formats.rst |  11 +++
 include/linux/kallsyms.h                  |  20 ++++-
 include/linux/module.h                    |   8 +-
 kernel/kallsyms.c                         | 101 +++++++++++++++++-----
 kernel/module.c                           |  31 ++++++-
 lib/vsprintf.c                            |   8 +-
 6 files changed, 154 insertions(+), 25 deletions(-)

diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index 160e710d992f..5f60533f2a56 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -114,6 +114,17 @@ used when printing stack backtraces. The specifier takes into
 consideration the effect of compiler optimisations which may occur
 when tail-calls are used and marked with the noreturn GCC attribute.
 
+If the pointer is within a module, the module name and optionally build ID is
+printed after the symbol name with an extra ``b`` appended to the end of the
+specifier.
+
+::
+	%pS	versatile_init+0x0/0x110 [module_name]
+	%pSb	versatile_init+0x0/0x110 [module_name ed5019fdf5e53be37cb1ba7899292d7e143b259e]
+	%pSRb	versatile_init+0x9/0x110 [module_name ed5019fdf5e53be37cb1ba7899292d7e143b259e]
+		(with __builtin_extract_return_addr() translation)
+	%pBb	prev_fn_of_versatile_init+0x88/0x88 [module_name ed5019fdf5e53be37cb1ba7899292d7e143b259e]
+
 Probed Pointers from BPF / tracing
 ----------------------------------
 
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 465060acc981..f760cb839775 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -7,6 +7,7 @@
 #define _LINUX_KALLSYMS_H
 
 #include <linux/errno.h>
+#include <linux/buildid.h>
 #include <linux/kernel.h>
 #include <linux/stddef.h>
 #include <linux/mm.h>
@@ -15,8 +16,9 @@
 #include <asm/sections.h>
 
 #define KSYM_NAME_LEN 128
-#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
-			 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)
+#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s %s]") + (KSYM_NAME_LEN - 1) + \
+			 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + \
+			 (BUILD_ID_SIZE_MAX * 2) + 1)
 
 struct cred;
 struct module;
@@ -91,8 +93,10 @@ const char *kallsyms_lookup(unsigned long addr,
 
 /* Look up a kernel symbol and return it in a text buffer. */
 extern int sprint_symbol(char *buffer, unsigned long address);
+extern int sprint_symbol_build_id(char *buffer, unsigned long address);
 extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
 extern int sprint_backtrace(char *buffer, unsigned long address);
+extern int sprint_backtrace_build_id(char *buffer, unsigned long address);
 
 int lookup_symbol_name(unsigned long addr, char *symname);
 int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
@@ -128,6 +132,12 @@ static inline int sprint_symbol(char *buffer, unsigned long addr)
 	return 0;
 }
 
+static inline int sprint_symbol_build_id(char *buffer, unsigned long address)
+{
+	*buffer = '\0';
+	return 0;
+}
+
 static inline int sprint_symbol_no_offset(char *buffer, unsigned long addr)
 {
 	*buffer = '\0';
@@ -140,6 +150,12 @@ static inline int sprint_backtrace(char *buffer, unsigned long addr)
 	return 0;
 }
 
+static inline int sprint_backtrace_build_id(char *buffer, unsigned long addr)
+{
+	*buffer = '\0';
+	return 0;
+}
+
 static inline int lookup_symbol_name(unsigned long addr, char *symname)
 {
 	return -ERANGE;
diff --git a/include/linux/module.h b/include/linux/module.h
index 59f094fa6f74..2416b515ae35 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -11,6 +11,7 @@
 
 #include <linux/list.h>
 #include <linux/stat.h>
+#include <linux/buildid.h>
 #include <linux/compiler.h>
 #include <linux/cache.h>
 #include <linux/kmod.h>
@@ -367,6 +368,11 @@ struct module {
 	/* Unique handle for this module */
 	char name[MODULE_NAME_LEN];
 
+#ifdef CONFIG_STACKTRACE_BUILD_ID
+	/* Module build ID */
+	unsigned char build_id[BUILD_ID_SIZE_MAX];
+#endif
+
 	/* Sysfs stuff. */
 	struct module_kobject mkobj;
 	struct module_attribute *modinfo_attrs;
@@ -630,7 +636,7 @@ void *dereference_module_function_descriptor(struct module *mod, void *ptr);
 const char *module_address_lookup(unsigned long addr,
 			    unsigned long *symbolsize,
 			    unsigned long *offset,
-			    char **modname,
+			    char **modname, const unsigned char **modbuildid,
 			    char *namebuf);
 int lookup_module_symbol_name(unsigned long addr, char *symname);
 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 8043a90aa50e..b1ad3df3d71b 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -25,7 +25,10 @@
 #include <linux/filter.h>
 #include <linux/ftrace.h>
 #include <linux/kprobes.h>
+#include <linux/build_bug.h>
 #include <linux/compiler.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
 
 /*
  * These will be re-linked against their real values
@@ -273,21 +276,13 @@ int kallsyms_lookup_size_offset(unsigned long addr, unsigned long *symbolsize,
 		get_symbol_pos(addr, symbolsize, offset);
 		return 1;
 	}
-	return !!module_address_lookup(addr, symbolsize, offset, NULL, namebuf) ||
+	return !!module_address_lookup(addr, symbolsize, offset, NULL, NULL, namebuf) ||
 	       !!__bpf_address_lookup(addr, symbolsize, offset, namebuf);
 }
 
-/*
- * Lookup an address
- * - modname is set to NULL if it's in the kernel.
- * - We guarantee that the returned name is valid until we reschedule even if.
- *   It resides in a module.
- * - We also guarantee that modname will be valid until rescheduled.
- */
-const char *kallsyms_lookup(unsigned long addr,
-			    unsigned long *symbolsize,
-			    unsigned long *offset,
-			    char **modname, char *namebuf)
+const char *kallsyms_lookup_buildid(unsigned long addr, unsigned long *symbolsize,
+				    unsigned long *offset, char **modname,
+				    const unsigned char **modbuildid, char *namebuf)
 {
 	const char *ret;
 
@@ -303,12 +298,14 @@ const char *kallsyms_lookup(unsigned long addr,
 				       namebuf, KSYM_NAME_LEN);
 		if (modname)
 			*modname = NULL;
+		if (modbuildid)
+			*modbuildid = NULL;
 		return namebuf;
 	}
 
 	/* See if it's in a module or a BPF JITed image. */
 	ret = module_address_lookup(addr, symbolsize, offset,
-				    modname, namebuf);
+				    modname, modbuildid, namebuf);
 	if (!ret)
 		ret = bpf_address_lookup(addr, symbolsize,
 					 offset, modname, namebuf);
@@ -319,6 +316,22 @@ const char *kallsyms_lookup(unsigned long addr,
 	return ret;
 }
 
+/*
+ * Lookup an address
+ * - modname is set to NULL if it's in the kernel.
+ * - We guarantee that the returned name is valid until we reschedule even if.
+ *   It resides in a module.
+ * - We also guarantee that modname will be valid until rescheduled.
+ */
+const char *kallsyms_lookup(unsigned long addr,
+			    unsigned long *symbolsize,
+			    unsigned long *offset,
+			    char **modname, char *namebuf)
+{
+	return kallsyms_lookup_buildid(addr, symbolsize, offset, modname,
+				       NULL, namebuf);
+}
+
 int lookup_symbol_name(unsigned long addr, char *symname)
 {
 	symname[0] = '\0';
@@ -359,15 +372,17 @@ int lookup_symbol_attrs(unsigned long addr, unsigned long *size,
 
 /* Look up a kernel symbol and return it in a text buffer. */
 static int __sprint_symbol(char *buffer, unsigned long address,
-			   int symbol_offset, int add_offset)
+			   int symbol_offset, int add_offset, int add_buildid)
 {
 	char *modname;
+	const unsigned char *buildid;
 	const char *name;
 	unsigned long offset, size;
 	int len;
 
 	address += symbol_offset;
-	name = kallsyms_lookup(address, &size, &offset, &modname, buffer);
+	name = kallsyms_lookup_buildid(address, &size, &offset, &modname, &buildid,
+				       buffer);
 	if (!name)
 		return sprintf(buffer, "0x%lx", address - symbol_offset);
 
@@ -379,8 +394,17 @@ static int __sprint_symbol(char *buffer, unsigned long address,
 	if (add_offset)
 		len += sprintf(buffer + len, "+%#lx/%#lx", offset, size);
 
-	if (modname)
-		len += sprintf(buffer + len, " [%s]", modname);
+	if (modname) {
+		len += sprintf(buffer + len, " [%s", modname);
+#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
+		if (add_buildid && buildid) {
+			/* build ID should match length of sprintf */
+			static_assert(sizeof(typeof_member(struct module, build_id)) == 20);
+			len += sprintf(buffer + len, " %20phN", buildid);
+		}
+#endif
+		len += sprintf(buffer + len, "]");
+	}
 
 	return len;
 }
@@ -398,10 +422,27 @@ static int __sprint_symbol(char *buffer, unsigned long address,
  */
 int sprint_symbol(char *buffer, unsigned long address)
 {
-	return __sprint_symbol(buffer, address, 0, 1);
+	return __sprint_symbol(buffer, address, 0, 1, 0);
 }
 EXPORT_SYMBOL_GPL(sprint_symbol);
 
+/**
+ * sprint_symbol_build_id - Look up a kernel symbol and return it in a text buffer
+ * @buffer: buffer to be stored
+ * @address: address to lookup
+ *
+ * This function looks up a kernel symbol with @address and stores its name,
+ * offset, size, module name and module build ID to @buffer if possible. If no
+ * symbol was found, just saves its @address as is.
+ *
+ * This function returns the number of bytes stored in @buffer.
+ */
+int sprint_symbol_build_id(char *buffer, unsigned long address)
+{
+	return __sprint_symbol(buffer, address, 0, 1, 1);
+}
+EXPORT_SYMBOL_GPL(sprint_symbol_build_id);
+
 /**
  * sprint_symbol_no_offset - Look up a kernel symbol and return it in a text buffer
  * @buffer: buffer to be stored
@@ -415,7 +456,7 @@ EXPORT_SYMBOL_GPL(sprint_symbol);
  */
 int sprint_symbol_no_offset(char *buffer, unsigned long address)
 {
-	return __sprint_symbol(buffer, address, 0, 0);
+	return __sprint_symbol(buffer, address, 0, 0, 0);
 }
 EXPORT_SYMBOL_GPL(sprint_symbol_no_offset);
 
@@ -435,7 +476,27 @@ EXPORT_SYMBOL_GPL(sprint_symbol_no_offset);
  */
 int sprint_backtrace(char *buffer, unsigned long address)
 {
-	return __sprint_symbol(buffer, address, -1, 1);
+	return __sprint_symbol(buffer, address, -1, 1, 0);
+}
+
+/**
+ * sprint_backtrace_build_id - Look up a backtrace symbol and return it in a text buffer
+ * @buffer: buffer to be stored
+ * @address: address to lookup
+ *
+ * This function is for stack backtrace and does the same thing as
+ * sprint_symbol() but with modified/decreased @address. If there is a
+ * tail-call to the function marked "noreturn", gcc optimized out code after
+ * the call so that the stack-saved return address could point outside of the
+ * caller. This function ensures that kallsyms will find the original caller
+ * by decreasing @address. This function also appends the module build ID to
+ * the @buffer if @address is within a kernel module.
+ *
+ * This function returns the number of bytes stored in @buffer.
+ */
+int sprint_backtrace_build_id(char *buffer, unsigned long address)
+{
+	return __sprint_symbol(buffer, address, -1, 1, 1);
 }
 
 /* To avoid using get_symbol_offset for every symbol, we carry prefix along. */
diff --git a/kernel/module.c b/kernel/module.c
index 30479355ab85..a5eaf5188a83 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -13,6 +13,7 @@
 #include <linux/trace_events.h>
 #include <linux/init.h>
 #include <linux/kallsyms.h>
+#include <linux/buildid.h>
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/sysfs.h>
@@ -2780,6 +2781,26 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
 }
 #endif /* CONFIG_KALLSYMS */
 
+#if IS_ENABLED(CONFIG_KALLSYMS) && IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
+static void init_build_id(struct module *mod, const struct load_info *info)
+{
+	const Elf_Shdr *sechdr;
+	unsigned int i;
+
+	for (i = 0; i < info->hdr->e_shnum; i++) {
+		sechdr = &info->sechdrs[i];
+		if (!sect_empty(sechdr) && sechdr->sh_type == SHT_NOTE &&
+		    !build_id_parse_buf((void *)sechdr->sh_addr, mod->build_id,
+					sechdr->sh_size))
+			break;
+	}
+}
+#else
+static void init_build_id(struct module *mod, const struct load_info *info)
+{
+}
+#endif
+
 static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsigned int num)
 {
 	if (!debug)
@@ -4004,6 +4025,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
 		goto free_arch_cleanup;
 	}
 
+	init_build_id(mod, info);
 	dynamic_debug_setup(mod, info->debug, info->num_debug);
 
 	/* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
@@ -4235,7 +4257,7 @@ void * __weak dereference_module_function_descriptor(struct module *mod,
 const char *module_address_lookup(unsigned long addr,
 			    unsigned long *size,
 			    unsigned long *offset,
-			    char **modname,
+			    char **modname, const unsigned char **modbuildid,
 			    char *namebuf)
 {
 	const char *ret = NULL;
@@ -4246,6 +4268,13 @@ const char *module_address_lookup(unsigned long addr,
 	if (mod) {
 		if (modname)
 			*modname = mod->name;
+		if (modbuildid) {
+#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
+			*modbuildid = mod->build_id;
+#else
+			*modbuildid = NULL;
+#endif
+		}
 
 		ret = find_kallsyms_symbol(mod, addr, size, offset);
 	}
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 41ddc353ebb8..fee5282ebb0a 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -966,8 +966,12 @@ char *symbol_string(char *buf, char *end, void *ptr,
 	value = (unsigned long)ptr;
 
 #ifdef CONFIG_KALLSYMS
-	if (*fmt == 'B')
+	if (*fmt == 'B' && fmt[1] == 'b')
+		sprint_backtrace_build_id(sym, value);
+	else if (*fmt == 'B')
 		sprint_backtrace(sym, value);
+	else if (*fmt == 'S' && (fmt[1] == 'b' || (fmt[1] == 'R' && fmt[2] == 'b')))
+		sprint_symbol_build_id(sym, value);
 	else if (*fmt != 's')
 		sprint_symbol(sym, value);
 	else
@@ -2129,9 +2133,11 @@ early_param("no_hash_pointers", no_hash_pointers_enable);
  * - 'S' For symbolic direct pointers (or function descriptors) with offset
  * - 's' For symbolic direct pointers (or function descriptors) without offset
  * - '[Ss]R' as above with __builtin_extract_return_addr() translation
+ * - 'S[R]b' as above with module build ID (for use in backtraces)
  * - '[Ff]' %pf and %pF were obsoleted and later removed in favor of
  *	    %ps and %pS. Be careful when re-using these specifiers.
  * - 'B' For backtraced symbolic direct pointers with offset
+ * - 'Bb' as above with module build ID (for use in backtraces)
  * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
  * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
  * - 'b[l]' For a bitmap, the number of bits is determined by the field
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 06/13] arm64: stacktrace: Use %pSb for backtrace printing
  2021-04-20 21:49 ` Stephen Boyd
@ 2021-04-20 21:49   ` Stephen Boyd
  -1 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Catalin Marinas, Will Deacon, linux-arm-kernel,
	Jiri Olsa, Alexei Starovoitov, Jessica Yu, Evan Green,
	Hsin-Yi Wang, Petr Mladek, Steven Rostedt, Andy Shevchenko,
	Matthew Wilcox

Let's use the new printk format to print the stacktrace entry when
printing a backtrace to the kernel logs. This will include any module's
build ID[1] in it so that offline/crash debugging can easily locate the
debuginfo for a module via something like debuginfod[2].

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Link: https://fedoraproject.org/wiki/Releases/FeatureBuildId [1]
Link: https://sourceware.org/elfutils/Debuginfod.html [2]
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 arch/arm64/kernel/stacktrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index ad20981dfda4..9d38da01ff98 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -129,7 +129,7 @@ NOKPROBE_SYMBOL(walk_stackframe);
 
 static void dump_backtrace_entry(unsigned long where, const char *loglvl)
 {
-	printk("%s %pS\n", loglvl, (void *)where);
+	printk("%s %pSb\n", loglvl, (void *)where);
 }
 
 void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 06/13] arm64: stacktrace: Use %pSb for backtrace printing
@ 2021-04-20 21:49   ` Stephen Boyd
  0 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Catalin Marinas, Will Deacon, linux-arm-kernel,
	Jiri Olsa, Alexei Starovoitov, Jessica Yu, Evan Green,
	Hsin-Yi Wang, Petr Mladek, Steven Rostedt, Andy Shevchenko,
	Matthew Wilcox

Let's use the new printk format to print the stacktrace entry when
printing a backtrace to the kernel logs. This will include any module's
build ID[1] in it so that offline/crash debugging can easily locate the
debuginfo for a module via something like debuginfod[2].

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Link: https://fedoraproject.org/wiki/Releases/FeatureBuildId [1]
Link: https://sourceware.org/elfutils/Debuginfod.html [2]
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 arch/arm64/kernel/stacktrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index ad20981dfda4..9d38da01ff98 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -129,7 +129,7 @@ NOKPROBE_SYMBOL(walk_stackframe);
 
 static void dump_backtrace_entry(unsigned long where, const char *loglvl)
 {
-	printk("%s %pS\n", loglvl, (void *)where);
+	printk("%s %pSb\n", loglvl, (void *)where);
 }
 
 void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
-- 
https://chromeos.dev


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 07/13] x86/dumpstack: Use %pSb/%pBb for backtrace printing
  2021-04-20 21:49 ` Stephen Boyd
                   ` (7 preceding siblings ...)
  (?)
@ 2021-04-20 21:49 ` Stephen Boyd
  -1 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
	Jiri Olsa, Alexei Starovoitov, Jessica Yu, Evan Green,
	Hsin-Yi Wang, Petr Mladek, Steven Rostedt, Andy Shevchenko,
	Matthew Wilcox

Let's use the new printk formats to print the stacktrace entries when
printing a backtrace to the kernel logs. This will include any module's
build ID[1] in it so that offline/crash debugging can easily locate the
debuginfo for a module via something like debuginfod[2].

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: <x86@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Link: https://fedoraproject.org/wiki/Releases/FeatureBuildId [1]
Link: https://sourceware.org/elfutils/Debuginfod.html [2]
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 arch/x86/kernel/dumpstack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index 299c20f0a38b..ea4fe192189d 100644
--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -69,7 +69,7 @@ static void printk_stack_address(unsigned long address, int reliable,
 				 const char *log_lvl)
 {
 	touch_nmi_watchdog();
-	printk("%s %s%pB\n", log_lvl, reliable ? "" : "? ", (void *)address);
+	printk("%s %s%pBb\n", log_lvl, reliable ? "" : "? ", (void *)address);
 }
 
 static int copy_code(struct pt_regs *regs, u8 *buf, unsigned long src,
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 08/13] scripts/decode_stacktrace.sh: Support debuginfod
  2021-04-20 21:49 ` Stephen Boyd
                   ` (8 preceding siblings ...)
  (?)
@ 2021-04-20 21:49 ` Stephen Boyd
  -1 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jiri Olsa, Alexei Starovoitov, Jessica Yu,
	Evan Green, Hsin-Yi Wang, Konstantin Khlebnikov, Sasha Levin,
	Petr Mladek, Steven Rostedt, Andy Shevchenko, Matthew Wilcox

Now that stacktraces contain the build ID information we can update this
script to use debuginfod-find to locate the debuginfo for the vmlinux
and modules automatically. This can replace the existing code that
requires specifying a path to vmlinux or tries to find the vmlinux and
modules automatically by using the release number. Work it into the
script as a fallback option if the vmlinux isn't specified on the
commandline.

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: Sasha Levin <sashal@kernel.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 scripts/decode_stacktrace.sh | 81 +++++++++++++++++++++++++++++++-----
 1 file changed, 70 insertions(+), 11 deletions(-)

diff --git a/scripts/decode_stacktrace.sh b/scripts/decode_stacktrace.sh
index 90398347e366..ca21f8bdf5f2 100755
--- a/scripts/decode_stacktrace.sh
+++ b/scripts/decode_stacktrace.sh
@@ -3,11 +3,10 @@
 # (c) 2014, Sasha Levin <sasha.levin@oracle.com>
 #set -x
 
-if [[ $# < 1 ]]; then
+usage() {
 	echo "Usage:"
 	echo "	$0 -r <release> | <vmlinux> [base path] [modules path]"
-	exit 1
-fi
+}
 
 if [[ $1 == "-r" ]] ; then
 	vmlinux=""
@@ -24,6 +23,7 @@ if [[ $1 == "-r" ]] ; then
 
 	if [[ $vmlinux == "" ]] ; then
 		echo "ERROR! vmlinux image for release $release is not found" >&2
+		usage
 		exit 2
 	fi
 else
@@ -31,12 +31,35 @@ else
 	basepath=${2-auto}
 	modpath=$3
 	release=""
+	debuginfod=
+
+	# Can we use debuginfod-find?
+	if type debuginfod-find >/dev/null 2>&1 ; then
+		debuginfod=${1-only}
+	fi
+
+	if [[ $vmlinux == "" && -z $debuginfod ]] ; then
+		echo "ERROR! vmlinux image must be specified" >&2
+		usage
+		exit 1
+	fi
 fi
 
 declare -A cache
 declare -A modcache
 
 find_module() {
+	if [[ -n $debuginfod ]] ; then
+		if [[ -n $modbuildid ]] ; then
+			debuginfod-find debuginfo $modbuildid && return
+		fi
+
+		# Only using debuginfod so don't try to find vmlinux module path
+		if [[ $debuginfod == "only" ]] ; then
+			return
+		fi
+	fi
+
 	if [[ "$modpath" != "" ]] ; then
 		for fn in $(find "$modpath" -name "${module//_/[-_]}.ko*") ; do
 			if readelf -WS "$fn" | grep -qwF .debug_line ; then
@@ -150,6 +173,27 @@ parse_symbol() {
 	symbol="$segment$name ($code)"
 }
 
+debuginfod_get_vmlinux() {
+	local vmlinux_buildid=${1##* }
+
+	if [[ $vmlinux != "" ]]; then
+		return
+	fi
+
+	if [[ $vmlinux_buildid =~ ^[0-9a-f]+ ]]; then
+		vmlinux=$(debuginfod-find debuginfo $vmlinux_buildid)
+		if [[ $? -ne 0 ]] ; then
+			echo "ERROR! vmlinux image not found via debuginfod-find" >&2
+			usage
+			exit 2
+		fi
+		return
+	fi
+	echo "ERROR! Build ID for vmlinux not found. Try passing -r or specifying vmlinux" >&2
+	usage
+	exit 2
+}
+
 decode_code() {
 	local scripts=`dirname "${BASH_SOURCE[0]}"`
 
@@ -157,6 +201,14 @@ decode_code() {
 }
 
 handle_line() {
+	if [[ $basepath == "auto" && $vmlinux != "" ]] ; then
+		module=""
+		symbol="kernel_init+0x0/0x0"
+		parse_symbol
+		basepath=${symbol#kernel_init (}
+		basepath=${basepath%/init/main.c:*)}
+	fi
+
 	local words
 
 	# Tokenize
@@ -182,16 +234,28 @@ handle_line() {
 		fi
 	done
 
+	if [[ ${words[$last]} =~ ^[0-9a-f]+\] ]]; then
+		words[$last-1]="${words[$last-1]} ${words[$last]}"
+		unset words[$last]
+		last=$(( $last - 1 ))
+	fi
+
 	if [[ ${words[$last]} =~ \[([^]]+)\] ]]; then
 		module=${words[$last]}
 		module=${module#\[}
 		module=${module%\]}
+		modbuildid=${module#* }
+		module=${module% *}
+		if [[ $modbuildid == $module ]]; then
+			modbuildid=
+		fi
 		symbol=${words[$last-1]}
 		unset words[$last-1]
 	else
 		# The symbol is the last element, process it
 		symbol=${words[$last]}
 		module=
+		modbuildid=
 	fi
 
 	unset words[$last]
@@ -201,14 +265,6 @@ handle_line() {
 	echo "${words[@]}" "$symbol $module"
 }
 
-if [[ $basepath == "auto" ]] ; then
-	module=""
-	symbol="kernel_init+0x0/0x0"
-	parse_symbol
-	basepath=${symbol#kernel_init (}
-	basepath=${basepath%/init/main.c:*)}
-fi
-
 while read line; do
 	# Let's see if we have an address in the line
 	if [[ $line =~ \[\<([^]]+)\>\] ]] ||
@@ -218,6 +274,9 @@ while read line; do
 	# Is it a code line?
 	elif [[ $line == *Code:* ]]; then
 		decode_code "$line"
+	# Is it a version line?
+	elif [[ -n $debuginfod && $line =~ PID:\ [0-9]+\ Comm: ]]; then
+		debuginfod_get_vmlinux "$line"
 	else
 		# Nothing special in this line, show it as is
 		echo "$line"
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 09/13] scripts/decode_stacktrace.sh: Silence stderr messages from addr2line/nm
  2021-04-20 21:49 ` Stephen Boyd
                   ` (9 preceding siblings ...)
  (?)
@ 2021-04-20 21:49 ` Stephen Boyd
  -1 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:49 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jiri Olsa, Alexei Starovoitov, Jessica Yu,
	Evan Green, Hsin-Yi Wang, Konstantin Khlebnikov, Sasha Levin

Sometimes if you're using tools that have linked things improperly or
have new features/sections that older tools don't expect you'll see
warnings printed to stderr. We don't really care about these warnings,
so let's just silence these messages to cleanup output of this script.

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: Sasha Levin <sashal@kernel.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 scripts/decode_stacktrace.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/decode_stacktrace.sh b/scripts/decode_stacktrace.sh
index ca21f8bdf5f2..20b5af1ebe5e 100755
--- a/scripts/decode_stacktrace.sh
+++ b/scripts/decode_stacktrace.sh
@@ -74,7 +74,7 @@ find_module() {
 	find_module && return
 
 	if [[ $release == "" ]] ; then
-		release=$(gdb -ex 'print init_uts_ns.name.release' -ex 'quit' -quiet -batch "$vmlinux" | sed -n 's/\$1 = "\(.*\)".*/\1/p')
+		release=$(gdb -ex 'print init_uts_ns.name.release' -ex 'quit' -quiet -batch "$vmlinux" 2>/dev/null | sed -n 's/\$1 = "\(.*\)".*/\1/p')
 	fi
 
 	for dn in {/usr/lib/debug,}/lib/modules/$release ; do
@@ -128,7 +128,7 @@ parse_symbol() {
 	if [[ "${cache[$module,$name]+isset}" == "isset" ]]; then
 		local base_addr=${cache[$module,$name]}
 	else
-		local base_addr=$(nm "$objfile" | awk '$3 == "'$name'" && ($2 == "t" || $2 == "T") {print $1; exit}')
+		local base_addr=$(nm "$objfile" 2>/dev/null | awk '$3 == "'$name'" && ($2 == "t" || $2 == "T") {print $1; exit}')
 		if [[ $base_addr == "" ]] ; then
 			# address not found
 			return
@@ -152,7 +152,7 @@ parse_symbol() {
 	if [[ "${cache[$module,$address]+isset}" == "isset" ]]; then
 		local code=${cache[$module,$address]}
 	else
-		local code=$(${CROSS_COMPILE}addr2line -i -e "$objfile" "$address")
+		local code=$(${CROSS_COMPILE}addr2line -i -e "$objfile" "$address" 2>/dev/null)
 		cache[$module,$address]=$code
 	fi
 
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 10/13] scripts/decode_stacktrace.sh: Indicate 'auto' can be used for base path
  2021-04-20 21:49 ` Stephen Boyd
                   ` (10 preceding siblings ...)
  (?)
@ 2021-04-20 21:50 ` Stephen Boyd
  -1 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:50 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jiri Olsa, Alexei Starovoitov, Jessica Yu,
	Evan Green, Hsin-Yi Wang, Konstantin Khlebnikov, Sasha Levin

Add "auto" to the usage message so that it's a little clearer that you
can pass "auto" as the second argument. When passing "auto" the script
tries to find the base path automatically instead of requiring it be
passed on the commandline. Also use [<variable>] to indicate the
variable argument and that it is optional so that we can differentiate
from the literal "auto" that should be passed.

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: Sasha Levin <sashal@kernel.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 scripts/decode_stacktrace.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/decode_stacktrace.sh b/scripts/decode_stacktrace.sh
index 20b5af1ebe5e..5fbad61fe490 100755
--- a/scripts/decode_stacktrace.sh
+++ b/scripts/decode_stacktrace.sh
@@ -5,7 +5,7 @@
 
 usage() {
 	echo "Usage:"
-	echo "	$0 -r <release> | <vmlinux> [base path] [modules path]"
+	echo "	$0 -r <release> | <vmlinux> [<base path>|auto] [<modules path>]"
 }
 
 if [[ $1 == "-r" ]] ; then
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 11/13] buildid: Mark some arguments const
  2021-04-20 21:49 ` Stephen Boyd
                   ` (11 preceding siblings ...)
  (?)
@ 2021-04-20 21:50 ` Stephen Boyd
  -1 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:50 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jiri Olsa, Alexei Starovoitov, Jessica Yu,
	Evan Green, Hsin-Yi Wang

These arguments are never modified so they can be marked const to
indicate as such.

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 lib/buildid.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/buildid.c b/lib/buildid.c
index 530dbd1f6bbe..a7edab4914e6 100644
--- a/lib/buildid.c
+++ b/lib/buildid.c
@@ -48,10 +48,10 @@ static int parse_build_id_buf(unsigned char *build_id,
 	return -EINVAL;
 }
 
-static inline int parse_build_id(void *page_addr,
+static inline int parse_build_id(const void *page_addr,
 				 unsigned char *build_id,
 				 __u32 *size,
-				 void *note_start,
+				 const void *note_start,
 				 Elf32_Word note_size)
 {
 	/* check for overflow */
@@ -66,7 +66,7 @@ static inline int parse_build_id(void *page_addr,
 }
 
 /* Parse build ID from 32-bit ELF */
-static int get_build_id_32(void *page_addr, unsigned char *build_id,
+static int get_build_id_32(const void *page_addr, unsigned char *build_id,
 			   __u32 *size)
 {
 	Elf32_Ehdr *ehdr = (Elf32_Ehdr *)page_addr;
@@ -91,7 +91,7 @@ static int get_build_id_32(void *page_addr, unsigned char *build_id,
 }
 
 /* Parse build ID from 64-bit ELF */
-static int get_build_id_64(void *page_addr, unsigned char *build_id,
+static int get_build_id_64(const void *page_addr, unsigned char *build_id,
 			   __u32 *size)
 {
 	Elf64_Ehdr *ehdr = (Elf64_Ehdr *)page_addr;
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 12/13] buildid: Fix kernel-doc notation
  2021-04-20 21:49 ` Stephen Boyd
                   ` (12 preceding siblings ...)
  (?)
@ 2021-04-20 21:50 ` Stephen Boyd
  -1 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:50 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jiri Olsa, Alexei Starovoitov, Jessica Yu,
	Evan Green, Hsin-Yi Wang

Kernel doc should use "Return:" instead of "Returns" to properly reflect
the return values.

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 lib/buildid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/buildid.c b/lib/buildid.c
index a7edab4914e6..dfc62625cae4 100644
--- a/lib/buildid.c
+++ b/lib/buildid.c
@@ -121,7 +121,7 @@ static int get_build_id_64(const void *page_addr, unsigned char *build_id,
  * @build_id: buffer to store build id, at least BUILD_ID_SIZE long
  * @size:     returns actual build id size in case of success
  *
- * Returns 0 on success, otherwise error (< 0).
+ * Return: 0 on success, -EINVAL otherwise
  */
 int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
 		   __u32 *size)
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 13/13] kdump: Use vmlinux_build_id to simplify
  2021-04-20 21:49 ` Stephen Boyd
@ 2021-04-20 21:50   ` Stephen Boyd
  -1 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:50 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jiri Olsa, Alexei Starovoitov, Jessica Yu,
	Evan Green, Hsin-Yi Wang, Dave Young, Baoquan He, Vivek Goyal,
	kexec

We can use the vmlinux_build_id array here now instead of open coding
it. This mostly consolidates code.

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Dave Young <dyoung@redhat.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: <kexec@lists.infradead.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 include/linux/crash_core.h | 12 ++++-----
 kernel/crash_core.c        | 50 ++------------------------------------
 2 files changed, 8 insertions(+), 54 deletions(-)

diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
index 206bde8308b2..de62a722431e 100644
--- a/include/linux/crash_core.h
+++ b/include/linux/crash_core.h
@@ -38,8 +38,12 @@ phys_addr_t paddr_vmcoreinfo_note(void);
 
 #define VMCOREINFO_OSRELEASE(value) \
 	vmcoreinfo_append_str("OSRELEASE=%s\n", value)
-#define VMCOREINFO_BUILD_ID(value) \
-	vmcoreinfo_append_str("BUILD-ID=%s\n", value)
+#define VMCOREINFO_BUILD_ID()						\
+	({								\
+		static_assert(sizeof(vmlinux_build_id) == 20);		\
+		vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \
+	})
+
 #define VMCOREINFO_PAGESIZE(value) \
 	vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
 #define VMCOREINFO_SYMBOL(name) \
@@ -69,10 +73,6 @@ extern unsigned char *vmcoreinfo_data;
 extern size_t vmcoreinfo_size;
 extern u32 *vmcoreinfo_note;
 
-/* raw contents of kernel .notes section */
-extern const void __start_notes __weak;
-extern const void __stop_notes __weak;
-
 Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type,
 			  void *data, size_t data_len);
 void final_note(Elf_Word *buf);
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index 825284baaf46..29cc15398ee4 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2002-2004 Eric Biederman  <ebiederm@xmission.com>
  */
 
+#include <linux/buildid.h>
 #include <linux/crash_core.h>
 #include <linux/utsname.h>
 #include <linux/vmalloc.h>
@@ -378,53 +379,6 @@ phys_addr_t __weak paddr_vmcoreinfo_note(void)
 }
 EXPORT_SYMBOL(paddr_vmcoreinfo_note);
 
-#define NOTES_SIZE (&__stop_notes - &__start_notes)
-#define BUILD_ID_MAX SHA1_DIGEST_SIZE
-#define NT_GNU_BUILD_ID 3
-
-struct elf_note_section {
-	struct elf_note	n_hdr;
-	u8 n_data[];
-};
-
-/*
- * Add build ID from .notes section as generated by the GNU ld(1)
- * or LLVM lld(1) --build-id option.
- */
-static void add_build_id_vmcoreinfo(void)
-{
-	char build_id[BUILD_ID_MAX * 2 + 1];
-	int n_remain = NOTES_SIZE;
-
-	while (n_remain >= sizeof(struct elf_note)) {
-		const struct elf_note_section *note_sec =
-			&__start_notes + NOTES_SIZE - n_remain;
-		const u32 n_namesz = note_sec->n_hdr.n_namesz;
-
-		if (note_sec->n_hdr.n_type == NT_GNU_BUILD_ID &&
-		    n_namesz != 0 &&
-		    !strcmp((char *)&note_sec->n_data[0], "GNU")) {
-			if (note_sec->n_hdr.n_descsz <= BUILD_ID_MAX) {
-				const u32 n_descsz = note_sec->n_hdr.n_descsz;
-				const u8 *s = &note_sec->n_data[n_namesz];
-
-				s = PTR_ALIGN(s, 4);
-				bin2hex(build_id, s, n_descsz);
-				build_id[2 * n_descsz] = '\0';
-				VMCOREINFO_BUILD_ID(build_id);
-				return;
-			}
-			pr_warn("Build ID is too large to include in vmcoreinfo: %u > %u\n",
-				note_sec->n_hdr.n_descsz,
-				BUILD_ID_MAX);
-			return;
-		}
-		n_remain -= sizeof(struct elf_note) +
-			ALIGN(note_sec->n_hdr.n_namesz, 4) +
-			ALIGN(note_sec->n_hdr.n_descsz, 4);
-	}
-}
-
 static int __init crash_save_vmcoreinfo_init(void)
 {
 	vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL);
@@ -443,7 +397,7 @@ static int __init crash_save_vmcoreinfo_init(void)
 	}
 
 	VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
-	add_build_id_vmcoreinfo();
+	VMCOREINFO_BUILD_ID();
 	VMCOREINFO_PAGESIZE(PAGE_SIZE);
 
 	VMCOREINFO_SYMBOL(init_uts_ns);
-- 
https://chromeos.dev


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v5 13/13] kdump: Use vmlinux_build_id to simplify
@ 2021-04-20 21:50   ` Stephen Boyd
  0 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-20 21:50 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jiri Olsa, Alexei Starovoitov, Jessica Yu,
	Evan Green, Hsin-Yi Wang, Dave Young, Baoquan He, Vivek Goyal,
	kexec

We can use the vmlinux_build_id array here now instead of open coding
it. This mostly consolidates code.

Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Evan Green <evgreen@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Dave Young <dyoung@redhat.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: <kexec@lists.infradead.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 include/linux/crash_core.h | 12 ++++-----
 kernel/crash_core.c        | 50 ++------------------------------------
 2 files changed, 8 insertions(+), 54 deletions(-)

diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
index 206bde8308b2..de62a722431e 100644
--- a/include/linux/crash_core.h
+++ b/include/linux/crash_core.h
@@ -38,8 +38,12 @@ phys_addr_t paddr_vmcoreinfo_note(void);
 
 #define VMCOREINFO_OSRELEASE(value) \
 	vmcoreinfo_append_str("OSRELEASE=%s\n", value)
-#define VMCOREINFO_BUILD_ID(value) \
-	vmcoreinfo_append_str("BUILD-ID=%s\n", value)
+#define VMCOREINFO_BUILD_ID()						\
+	({								\
+		static_assert(sizeof(vmlinux_build_id) == 20);		\
+		vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \
+	})
+
 #define VMCOREINFO_PAGESIZE(value) \
 	vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
 #define VMCOREINFO_SYMBOL(name) \
@@ -69,10 +73,6 @@ extern unsigned char *vmcoreinfo_data;
 extern size_t vmcoreinfo_size;
 extern u32 *vmcoreinfo_note;
 
-/* raw contents of kernel .notes section */
-extern const void __start_notes __weak;
-extern const void __stop_notes __weak;
-
 Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type,
 			  void *data, size_t data_len);
 void final_note(Elf_Word *buf);
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index 825284baaf46..29cc15398ee4 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2002-2004 Eric Biederman  <ebiederm@xmission.com>
  */
 
+#include <linux/buildid.h>
 #include <linux/crash_core.h>
 #include <linux/utsname.h>
 #include <linux/vmalloc.h>
@@ -378,53 +379,6 @@ phys_addr_t __weak paddr_vmcoreinfo_note(void)
 }
 EXPORT_SYMBOL(paddr_vmcoreinfo_note);
 
-#define NOTES_SIZE (&__stop_notes - &__start_notes)
-#define BUILD_ID_MAX SHA1_DIGEST_SIZE
-#define NT_GNU_BUILD_ID 3
-
-struct elf_note_section {
-	struct elf_note	n_hdr;
-	u8 n_data[];
-};
-
-/*
- * Add build ID from .notes section as generated by the GNU ld(1)
- * or LLVM lld(1) --build-id option.
- */
-static void add_build_id_vmcoreinfo(void)
-{
-	char build_id[BUILD_ID_MAX * 2 + 1];
-	int n_remain = NOTES_SIZE;
-
-	while (n_remain >= sizeof(struct elf_note)) {
-		const struct elf_note_section *note_sec =
-			&__start_notes + NOTES_SIZE - n_remain;
-		const u32 n_namesz = note_sec->n_hdr.n_namesz;
-
-		if (note_sec->n_hdr.n_type == NT_GNU_BUILD_ID &&
-		    n_namesz != 0 &&
-		    !strcmp((char *)&note_sec->n_data[0], "GNU")) {
-			if (note_sec->n_hdr.n_descsz <= BUILD_ID_MAX) {
-				const u32 n_descsz = note_sec->n_hdr.n_descsz;
-				const u8 *s = &note_sec->n_data[n_namesz];
-
-				s = PTR_ALIGN(s, 4);
-				bin2hex(build_id, s, n_descsz);
-				build_id[2 * n_descsz] = '\0';
-				VMCOREINFO_BUILD_ID(build_id);
-				return;
-			}
-			pr_warn("Build ID is too large to include in vmcoreinfo: %u > %u\n",
-				note_sec->n_hdr.n_descsz,
-				BUILD_ID_MAX);
-			return;
-		}
-		n_remain -= sizeof(struct elf_note) +
-			ALIGN(note_sec->n_hdr.n_namesz, 4) +
-			ALIGN(note_sec->n_hdr.n_descsz, 4);
-	}
-}
-
 static int __init crash_save_vmcoreinfo_init(void)
 {
 	vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL);
@@ -443,7 +397,7 @@ static int __init crash_save_vmcoreinfo_init(void)
 	}
 
 	VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
-	add_build_id_vmcoreinfo();
+	VMCOREINFO_BUILD_ID();
 	VMCOREINFO_PAGESIZE(PAGE_SIZE);
 
 	VMCOREINFO_SYMBOL(init_uts_ns);
-- 
https://chromeos.dev


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 06/13] arm64: stacktrace: Use %pSb for backtrace printing
  2021-04-20 21:49   ` Stephen Boyd
@ 2021-04-21  9:58     ` Catalin Marinas
  -1 siblings, 0 replies; 39+ messages in thread
From: Catalin Marinas @ 2021-04-21  9:58 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Will Deacon, linux-arm-kernel,
	Jiri Olsa, Alexei Starovoitov, Jessica Yu, Evan Green,
	Hsin-Yi Wang, Petr Mladek, Steven Rostedt, Andy Shevchenko,
	Matthew Wilcox

On Tue, Apr 20, 2021 at 02:49:56PM -0700, Stephen Boyd wrote:
> Let's use the new printk format to print the stacktrace entry when
> printing a backtrace to the kernel logs. This will include any module's
> build ID[1] in it so that offline/crash debugging can easily locate the
> debuginfo for a module via something like debuginfod[2].
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: <linux-arm-kernel@lists.infradead.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Jessica Yu <jeyu@kernel.org>
> Cc: Evan Green <evgreen@chromium.org>
> Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> Cc: Petr Mladek <pmladek@suse.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Matthew Wilcox <willy@infradead.org>
> Link: https://fedoraproject.org/wiki/Releases/FeatureBuildId [1]
> Link: https://sourceware.org/elfutils/Debuginfod.html [2]
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 06/13] arm64: stacktrace: Use %pSb for backtrace printing
@ 2021-04-21  9:58     ` Catalin Marinas
  0 siblings, 0 replies; 39+ messages in thread
From: Catalin Marinas @ 2021-04-21  9:58 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Will Deacon, linux-arm-kernel,
	Jiri Olsa, Alexei Starovoitov, Jessica Yu, Evan Green,
	Hsin-Yi Wang, Petr Mladek, Steven Rostedt, Andy Shevchenko,
	Matthew Wilcox

On Tue, Apr 20, 2021 at 02:49:56PM -0700, Stephen Boyd wrote:
> Let's use the new printk format to print the stacktrace entry when
> printing a backtrace to the kernel logs. This will include any module's
> build ID[1] in it so that offline/crash debugging can easily locate the
> debuginfo for a module via something like debuginfod[2].
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: <linux-arm-kernel@lists.infradead.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Jessica Yu <jeyu@kernel.org>
> Cc: Evan Green <evgreen@chromium.org>
> Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> Cc: Petr Mladek <pmladek@suse.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Matthew Wilcox <willy@infradead.org>
> Link: https://fedoraproject.org/wiki/Releases/FeatureBuildId [1]
> Link: https://sourceware.org/elfutils/Debuginfod.html [2]
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 05/13] module: Add printk formats to add module build ID to stacktraces
  2021-04-20 21:49 ` [PATCH v5 05/13] module: Add printk formats to add module build ID to stacktraces Stephen Boyd
@ 2021-04-21 11:49   ` Andy Shevchenko
  2021-04-22 23:46     ` Stephen Boyd
  0 siblings, 1 reply; 39+ messages in thread
From: Andy Shevchenko @ 2021-04-21 11:49 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Petr Mladek,
	Steven Rostedt, Sergey Senozhatsky, Rasmus Villemoes, linux-doc,
	Matthew Wilcox

On Tue, Apr 20, 2021 at 02:49:55PM -0700, Stephen Boyd wrote:
> Let's make kernel stacktraces easier to identify by including the build
> ID[1] of a module if the stacktrace is printing a symbol from a module.
> This makes it simpler for developers to locate a kernel module's full
> debuginfo for a particular stacktrace. Combined with
> scripts/decode_stracktrace.sh, a developer can download the matching
> debuginfo from a debuginfod[2] server and find the exact file and line
> number for the functions plus offsets in a stacktrace that match the
> module. This is especially useful for pstore crash debugging where the
> kernel crashes are recorded in something like console-ramoops and the
> recovery kernel/modules are different or the debuginfo doesn't exist on
> the device due to space concerns (the debuginfo can be too large for
> space limited devices).
> 
> Originally, I put this on the %pS format, but that was quickly rejected
> given that %pS is used in other places such as ftrace where build IDs
> aren't meaningful. There was some discussions on the list to put every
> module build ID into the "Modules linked in:" section of the stacktrace
> message but that quickly becomes very hard to read once you have more
> than three or four modules linked in. It also provides too much
> information when we don't expect each module to be traversed in a
> stacktrace. Having the build ID for modules that aren't important just
> makes things messy. Splitting it to multiple lines for each module
> quickly explodes the number of lines printed in an oops too, possibly
> wrapping the warning off the console. And finally, trying to stash away
> each module used in a callstack to provide the ID of each symbol printed
> is cumbersome and would require changes to each architecture to stash
> away modules and return their build IDs once unwinding has completed.
> 
> Instead, we opt for the simpler approach of introducing new printk
> formats '%pS[R]b' for "pointer symbolic backtrace with module build ID"
> and '%pBb' for "pointer backtrace with module build ID" and then
> updating the few places in the architecture layer where the stacktrace
> is printed to use this new format.
> 
> Example:

Please, shrink the example to leave only meaningful lines.

Why, e.g., do we need to see register dump, is it somehow different?

...

> +#ifdef CONFIG_STACKTRACE_BUILD_ID
> +	/* Module build ID */
> +	unsigned char build_id[BUILD_ID_SIZE_MAX];

Is it really string of characters? Perhaps u8 will be more explicit.

...

> +#include <linux/kernel.h>

What do you need this header for?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 05/13] module: Add printk formats to add module build ID to stacktraces
  2021-04-21 11:49   ` Andy Shevchenko
@ 2021-04-22 23:46     ` Stephen Boyd
  2021-04-23 13:24       ` Andy Shevchenko
  0 siblings, 1 reply; 39+ messages in thread
From: Stephen Boyd @ 2021-04-22 23:46 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Petr Mladek,
	Steven Rostedt, Sergey Senozhatsky, Rasmus Villemoes, linux-doc,
	Matthew Wilcox

Quoting Andy Shevchenko (2021-04-21 04:49:33)
> On Tue, Apr 20, 2021 at 02:49:55PM -0700, Stephen Boyd wrote:
> > Let's make kernel stacktraces easier to identify by including the build
> > ID[1] of a module if the stacktrace is printing a symbol from a module.
> > This makes it simpler for developers to locate a kernel module's full
> > debuginfo for a particular stacktrace. Combined with
> > scripts/decode_stracktrace.sh, a developer can download the matching
> > debuginfo from a debuginfod[2] server and find the exact file and line
> > number for the functions plus offsets in a stacktrace that match the
> > module. This is especially useful for pstore crash debugging where the
> > kernel crashes are recorded in something like console-ramoops and the
> > recovery kernel/modules are different or the debuginfo doesn't exist on
> > the device due to space concerns (the debuginfo can be too large for
> > space limited devices).
> > 
> > Originally, I put this on the %pS format, but that was quickly rejected
> > given that %pS is used in other places such as ftrace where build IDs
> > aren't meaningful. There was some discussions on the list to put every
> > module build ID into the "Modules linked in:" section of the stacktrace
> > message but that quickly becomes very hard to read once you have more
> > than three or four modules linked in. It also provides too much
> > information when we don't expect each module to be traversed in a
> > stacktrace. Having the build ID for modules that aren't important just
> > makes things messy. Splitting it to multiple lines for each module
> > quickly explodes the number of lines printed in an oops too, possibly
> > wrapping the warning off the console. And finally, trying to stash away
> > each module used in a callstack to provide the ID of each symbol printed
> > is cumbersome and would require changes to each architecture to stash
> > away modules and return their build IDs once unwinding has completed.
> > 
> > Instead, we opt for the simpler approach of introducing new printk
> > formats '%pS[R]b' for "pointer symbolic backtrace with module build ID"
> > and '%pBb' for "pointer backtrace with module build ID" and then
> > updating the few places in the architecture layer where the stacktrace
> > is printed to use this new format.
> > 
> > Example:
> 
> Please, shrink the example to leave only meaningful lines.
> 
> Why, e.g., do we need to see register dump, is it somehow different?

Can you format it how you would like to see it? Should it be a unified
diff? I agree it would help to see "what changed" but also don't know
what you want so opted to provide more information, not less. I was
worried about the questions like "do you change other parts of a splat?"
so I just put the whole thing there.

> 
> ...
> 
> > +#ifdef CONFIG_STACKTRACE_BUILD_ID
> > +     /* Module build ID */
> > +     unsigned char build_id[BUILD_ID_SIZE_MAX];
> 
> Is it really string of characters? Perhaps u8 will be more explicit.

I'm just matching the build ID API that uses unsigned char. If you want
u8 then we should update more places. I could do that in a followup
patch, but this one is already sorta big.

> 
> ...
> 
> > +#include <linux/kernel.h>
> 
> What do you need this header for?
> 

For typeof_member().

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 05/13] module: Add printk formats to add module build ID to stacktraces
  2021-04-22 23:46     ` Stephen Boyd
@ 2021-04-23 13:24       ` Andy Shevchenko
  2021-04-23 13:45         ` Rasmus Villemoes
  2021-04-26 23:42         ` Stephen Boyd
  0 siblings, 2 replies; 39+ messages in thread
From: Andy Shevchenko @ 2021-04-23 13:24 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Petr Mladek,
	Steven Rostedt, Sergey Senozhatsky, Rasmus Villemoes, linux-doc,
	Matthew Wilcox

On Thu, Apr 22, 2021 at 04:46:40PM -0700, Stephen Boyd wrote:
> Quoting Andy Shevchenko (2021-04-21 04:49:33)
> > On Tue, Apr 20, 2021 at 02:49:55PM -0700, Stephen Boyd wrote:

...

> > > Example:
> > 
> > Please, shrink the example to leave only meaningful lines.
> > 
> > Why, e.g., do we need to see register dump, is it somehow different?
> 
> Can you format it how you would like to see it? Should it be a unified
> diff? I agree it would help to see "what changed" but also don't know
> what you want so opted to provide more information, not less. I was
> worried about the questions like "do you change other parts of a splat?"
> so I just put the whole thing there.


Before:
 ...line X...
 ...
 ...line Y...

After:
 ...line X'...
 ...
 ...line Y'...

Three lines of example per each paragraph, in each of them the middle one is
simply [...].

...

> > > +#ifdef CONFIG_STACKTRACE_BUILD_ID
> > > +     /* Module build ID */
> > > +     unsigned char build_id[BUILD_ID_SIZE_MAX];
> > 
> > Is it really string of characters? Perhaps u8 will be more explicit.
> 
> I'm just matching the build ID API that uses unsigned char. If you want
> u8 then we should update more places. I could do that in a followup
> patch, but this one is already sorta big.

Unsigned char here is confusing. I would prefer a prerequisite patch to fix
other places first.

...

> > > +#include <linux/kernel.h>
> > 
> > What do you need this header for?
> > 
> 
> For typeof_member().

Argh... We really need to split this and container_of to something else. Having
entire kernel.h for that is an overkill.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 05/13] module: Add printk formats to add module build ID to stacktraces
  2021-04-23 13:24       ` Andy Shevchenko
@ 2021-04-23 13:45         ` Rasmus Villemoes
  2021-04-23 14:08           ` Andy Shevchenko
  2021-04-26 23:42         ` Stephen Boyd
  1 sibling, 1 reply; 39+ messages in thread
From: Rasmus Villemoes @ 2021-04-23 13:45 UTC (permalink / raw)
  To: Andy Shevchenko, Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Petr Mladek,
	Steven Rostedt, Sergey Senozhatsky, linux-doc, Matthew Wilcox

On 23/04/2021 15.24, Andy Shevchenko wrote:
> On Thu, Apr 22, 2021 at 04:46:40PM -0700, Stephen Boyd wrote:

>>>> +#include <linux/kernel.h>
>>>
>>> What do you need this header for?
>>>
>>
>> For typeof_member().
> 
> Argh... We really need to split this and container_of to something else. Having
> entire kernel.h for that is an overkill.
> 

Yeah, we should have a type-macros.h (or type-helpers or whatever) that
doesn't include any other kernel headers, just stddef.h (which is
compiler-provided) for offsetof(), providing

typeof_member
sizeof_member
container_of
same_type
type_min
type_max
is_signed_type
__choose_type

or whatever their names are currently.

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 05/13] module: Add printk formats to add module build ID to stacktraces
  2021-04-23 13:45         ` Rasmus Villemoes
@ 2021-04-23 14:08           ` Andy Shevchenko
  0 siblings, 0 replies; 39+ messages in thread
From: Andy Shevchenko @ 2021-04-23 14:08 UTC (permalink / raw)
  To: Rasmus Villemoes
  Cc: Stephen Boyd, Andrew Morton, linux-kernel, Jiri Olsa,
	Alexei Starovoitov, Jessica Yu, Evan Green, Hsin-Yi Wang,
	Petr Mladek, Steven Rostedt, Sergey Senozhatsky, linux-doc,
	Matthew Wilcox

On Fri, Apr 23, 2021 at 03:45:56PM +0200, Rasmus Villemoes wrote:
> On 23/04/2021 15.24, Andy Shevchenko wrote:
> > On Thu, Apr 22, 2021 at 04:46:40PM -0700, Stephen Boyd wrote:
> 
> >>>> +#include <linux/kernel.h>
> >>>
> >>> What do you need this header for?
> >>>
> >>
> >> For typeof_member().
> > 
> > Argh... We really need to split this and container_of to something else. Having
> > entire kernel.h for that is an overkill.
> > 
> 
> Yeah, we should have a type-macros.h (or type-helpers or whatever) that
> doesn't include any other kernel headers, just stddef.h (which is
> compiler-provided) for offsetof(), providing
> 
> typeof_member
> sizeof_member
> container_of
> same_type
> type_min
> type_max
> is_signed_type
> __choose_type
> 
> or whatever their names are currently.

Put in my TODO list. Not sure when it will go, though.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 04/13] dump_stack: Add vmlinux build ID to stack traces
  2021-04-20 21:49 ` [PATCH v5 04/13] dump_stack: Add vmlinux build ID to stack traces Stephen Boyd
@ 2021-04-26 11:04   ` Petr Mladek
  2021-04-26 23:40     ` Stephen Boyd
  0 siblings, 1 reply; 39+ messages in thread
From: Petr Mladek @ 2021-04-26 11:04 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Steven Rostedt,
	Andy Shevchenko, Matthew Wilcox

On Tue 2021-04-20 14:49:54, Stephen Boyd wrote:
> Add the running kernel's build ID[1] to the stacktrace information
> header.  This makes it simpler for developers to locate the vmlinux with
> full debuginfo for a particular kernel stacktrace. Combined with
> scripts/decode_stracktrace.sh, a developer can download the correct
> vmlinux from a debuginfod[2] server and find the exact file and line
> number for the functions plus offsets in a stacktrace.
> 
> diff --git a/include/linux/buildid.h b/include/linux/buildid.h
> index f375900cf9ed..3b7a0ff4642f 100644
> --- a/include/linux/buildid.h
> +++ b/include/linux/buildid.h
> @@ -10,7 +10,11 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
>  		   __u32 *size);
>  int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size);
>  
> +#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) || IS_ENABLED(CONFIG_CRASH_CORE)

Why is this enabled for CONFIG_CRASH_CORE, please?

Is some crash_core code going to printk it id even when
CONFIG_STACKTRACE_BUILD_ID is disabled?

Anyway, this condition should be added in the patch when a code is
really going to depend on it. Or the intention should be explained
in the commit message at least.


>  extern unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX];
>  void init_vmlinux_build_id(void);
> +#else
> +static inline void init_vmlinux_build_id(void) { }
> +#endif

Otherwise, the patch looks good to me.

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 04/13] dump_stack: Add vmlinux build ID to stack traces
  2021-04-26 11:04   ` Petr Mladek
@ 2021-04-26 23:40     ` Stephen Boyd
  0 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-26 23:40 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Steven Rostedt,
	Andy Shevchenko, Matthew Wilcox

Quoting Petr Mladek (2021-04-26 04:04:28)
> On Tue 2021-04-20 14:49:54, Stephen Boyd wrote:
> > Add the running kernel's build ID[1] to the stacktrace information
> > header.  This makes it simpler for developers to locate the vmlinux with
> > full debuginfo for a particular kernel stacktrace. Combined with
> > scripts/decode_stracktrace.sh, a developer can download the correct
> > vmlinux from a debuginfod[2] server and find the exact file and line
> > number for the functions plus offsets in a stacktrace.
> >
> > diff --git a/include/linux/buildid.h b/include/linux/buildid.h
> > index f375900cf9ed..3b7a0ff4642f 100644
> > --- a/include/linux/buildid.h
> > +++ b/include/linux/buildid.h
> > @@ -10,7 +10,11 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
> >                  __u32 *size);
> >  int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size);
> >
> > +#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) || IS_ENABLED(CONFIG_CRASH_CORE)
>
> Why is this enabled for CONFIG_CRASH_CORE, please?
>
> Is some crash_core code going to printk it id even when
> CONFIG_STACKTRACE_BUILD_ID is disabled?
>
> Anyway, this condition should be added in the patch when a code is
> really going to depend on it. Or the intention should be explained
> in the commit message at least.

Sure I'll move the latter condition to the crash patch at the end.

>
>
> >  extern unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX];
> >  void init_vmlinux_build_id(void);
> > +#else
> > +static inline void init_vmlinux_build_id(void) { }
> > +#endif
>
> Otherwise, the patch looks good to me.
>

Thanks.

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 05/13] module: Add printk formats to add module build ID to stacktraces
  2021-04-23 13:24       ` Andy Shevchenko
  2021-04-23 13:45         ` Rasmus Villemoes
@ 2021-04-26 23:42         ` Stephen Boyd
  1 sibling, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-26 23:42 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Petr Mladek,
	Steven Rostedt, Sergey Senozhatsky, Rasmus Villemoes, linux-doc,
	Matthew Wilcox

Quoting Andy Shevchenko (2021-04-23 06:24:53)
> On Thu, Apr 22, 2021 at 04:46:40PM -0700, Stephen Boyd wrote:
> > Quoting Andy Shevchenko (2021-04-21 04:49:33)
> > > On Tue, Apr 20, 2021 at 02:49:55PM -0700, Stephen Boyd wrote:
>
> ...
>
> > > > Example:
> > >
> > > Please, shrink the example to leave only meaningful lines.
> > >
> > > Why, e.g., do we need to see register dump, is it somehow different?
> >
> > Can you format it how you would like to see it? Should it be a unified
> > diff? I agree it would help to see "what changed" but also don't know
> > what you want so opted to provide more information, not less. I was
> > worried about the questions like "do you change other parts of a splat?"
> > so I just put the whole thing there.
>
>
> Before:
>  ...line X...
>  ...
>  ...line Y...
>
> After:
>  ...line X'...
>  ...
>  ...line Y'...
>
> Three lines of example per each paragraph, in each of them the middle one is
> simply [...].

Ok got it. Thanks for clarifying.

>
> ...
>
> > > > +#ifdef CONFIG_STACKTRACE_BUILD_ID
> > > > +     /* Module build ID */
> > > > +     unsigned char build_id[BUILD_ID_SIZE_MAX];
> > >
> > > Is it really string of characters? Perhaps u8 will be more explicit.
> >
> > I'm just matching the build ID API that uses unsigned char. If you want
> > u8 then we should update more places. I could do that in a followup
> > patch, but this one is already sorta big.
>
> Unsigned char here is confusing. I would prefer a prerequisite patch to fix
> other places first.
>

Does anyone else want this to happen first? Andrew? I'm inclined to fix
this in a followup. As I said before, this would make this an even
bigger patch series which I'd like to avoid.

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 03/13] buildid: Stash away kernels build ID on init
  2021-04-20 21:49   ` Stephen Boyd
@ 2021-04-28 10:02     ` Baoquan He
  -1 siblings, 0 replies; 39+ messages in thread
From: Baoquan He @ 2021-04-28 10:02 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Dave Young, Vivek Goyal,
	kexec

On 04/20/21 at 02:49pm, Stephen Boyd wrote:
> Parse the kernel's build ID at initialization so that other code can
> print a hex format string representation of the running kernel's build
> ID. This will be used in the kdump and dump_stack code so that
> developers can easily locate the vmlinux debug symbols for a
> crash/stacktrace.
> 
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Jessica Yu <jeyu@kernel.org>
> Cc: Evan Green <evgreen@chromium.org>
> Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> Cc: Dave Young <dyoung@redhat.com>
> Cc: Baoquan He <bhe@redhat.com>
> Cc: Vivek Goyal <vgoyal@redhat.com>
> Cc: <kexec@lists.infradead.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
>  include/linux/buildid.h |  3 +++
>  init/main.c             |  1 +
>  lib/buildid.c           | 15 +++++++++++++++
>  3 files changed, 19 insertions(+)
> 
> diff --git a/include/linux/buildid.h b/include/linux/buildid.h
> index ebce93f26d06..f375900cf9ed 100644
> --- a/include/linux/buildid.h
> +++ b/include/linux/buildid.h
> @@ -10,4 +10,7 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
>  		   __u32 *size);
>  int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size);
>  
> +extern unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX];
> +void init_vmlinux_build_id(void);
> +
>  #endif
> diff --git a/init/main.c b/init/main.c
> index 53b278845b88..eaede2f41327 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -857,6 +857,7 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
>  	set_task_stack_end_magic(&init_task);
>  	smp_setup_processor_id();
>  	debug_objects_early_init();
> +	init_vmlinux_build_id();
>  
>  	cgroup_init_early();
>  
> diff --git a/lib/buildid.c b/lib/buildid.c
> index 6aea1c4e5e85..1103ed46214f 100644
> --- a/lib/buildid.c
> +++ b/lib/buildid.c
> @@ -1,6 +1,7 @@
>  // SPDX-License-Identifier: GPL-2.0
>  
>  #include <linux/buildid.h>
> +#include <linux/cache.h>
>  #include <linux/elf.h>
>  #include <linux/kernel.h>
>  #include <linux/pagemap.h>
> @@ -172,3 +173,17 @@ int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size)
>  {
>  	return parse_build_id_buf(build_id, NULL, buf, buf_size);
>  }
> +
> +unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX] __ro_after_init;
> +
> +/**
> + * init_vmlinux_build_id - Compute and stash the running kernel's build ID
> + */
> +void __init init_vmlinux_build_id(void)
> +{
> +	extern const void __start_notes __weak;
> +	extern const void __stop_notes __weak;
> +	unsigned int size = &__stop_notes - &__start_notes;
> +
> +	build_id_parse_buf(&__start_notes, vmlinux_build_id, size);
> +}

LGTM, thx.

Acked-by: Baoquan He <bhe@redhat.com>


^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 03/13] buildid: Stash away kernels build ID on init
@ 2021-04-28 10:02     ` Baoquan He
  0 siblings, 0 replies; 39+ messages in thread
From: Baoquan He @ 2021-04-28 10:02 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Dave Young, Vivek Goyal,
	kexec

On 04/20/21 at 02:49pm, Stephen Boyd wrote:
> Parse the kernel's build ID at initialization so that other code can
> print a hex format string representation of the running kernel's build
> ID. This will be used in the kdump and dump_stack code so that
> developers can easily locate the vmlinux debug symbols for a
> crash/stacktrace.
> 
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Jessica Yu <jeyu@kernel.org>
> Cc: Evan Green <evgreen@chromium.org>
> Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> Cc: Dave Young <dyoung@redhat.com>
> Cc: Baoquan He <bhe@redhat.com>
> Cc: Vivek Goyal <vgoyal@redhat.com>
> Cc: <kexec@lists.infradead.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
>  include/linux/buildid.h |  3 +++
>  init/main.c             |  1 +
>  lib/buildid.c           | 15 +++++++++++++++
>  3 files changed, 19 insertions(+)
> 
> diff --git a/include/linux/buildid.h b/include/linux/buildid.h
> index ebce93f26d06..f375900cf9ed 100644
> --- a/include/linux/buildid.h
> +++ b/include/linux/buildid.h
> @@ -10,4 +10,7 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
>  		   __u32 *size);
>  int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size);
>  
> +extern unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX];
> +void init_vmlinux_build_id(void);
> +
>  #endif
> diff --git a/init/main.c b/init/main.c
> index 53b278845b88..eaede2f41327 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -857,6 +857,7 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
>  	set_task_stack_end_magic(&init_task);
>  	smp_setup_processor_id();
>  	debug_objects_early_init();
> +	init_vmlinux_build_id();
>  
>  	cgroup_init_early();
>  
> diff --git a/lib/buildid.c b/lib/buildid.c
> index 6aea1c4e5e85..1103ed46214f 100644
> --- a/lib/buildid.c
> +++ b/lib/buildid.c
> @@ -1,6 +1,7 @@
>  // SPDX-License-Identifier: GPL-2.0
>  
>  #include <linux/buildid.h>
> +#include <linux/cache.h>
>  #include <linux/elf.h>
>  #include <linux/kernel.h>
>  #include <linux/pagemap.h>
> @@ -172,3 +173,17 @@ int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size)
>  {
>  	return parse_build_id_buf(build_id, NULL, buf, buf_size);
>  }
> +
> +unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX] __ro_after_init;
> +
> +/**
> + * init_vmlinux_build_id - Compute and stash the running kernel's build ID
> + */
> +void __init init_vmlinux_build_id(void)
> +{
> +	extern const void __start_notes __weak;
> +	extern const void __stop_notes __weak;
> +	unsigned int size = &__stop_notes - &__start_notes;
> +
> +	build_id_parse_buf(&__start_notes, vmlinux_build_id, size);
> +}

LGTM, thx.

Acked-by: Baoquan He <bhe@redhat.com>


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 13/13] kdump: Use vmlinux_build_id to simplify
  2021-04-20 21:50   ` Stephen Boyd
@ 2021-04-28 10:13     ` Baoquan He
  -1 siblings, 0 replies; 39+ messages in thread
From: Baoquan He @ 2021-04-28 10:13 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Dave Young, Vivek Goyal,
	kexec

On 04/20/21 at 02:50pm, Stephen Boyd wrote:
> We can use the vmlinux_build_id array here now instead of open coding
> it. This mostly consolidates code.
> 
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Jessica Yu <jeyu@kernel.org>
> Cc: Evan Green <evgreen@chromium.org>
> Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> Cc: Dave Young <dyoung@redhat.com>
> Cc: Baoquan He <bhe@redhat.com>
> Cc: Vivek Goyal <vgoyal@redhat.com>
> Cc: <kexec@lists.infradead.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
>  include/linux/crash_core.h | 12 ++++-----
>  kernel/crash_core.c        | 50 ++------------------------------------
>  2 files changed, 8 insertions(+), 54 deletions(-)
> 
> diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
> index 206bde8308b2..de62a722431e 100644
> --- a/include/linux/crash_core.h
> +++ b/include/linux/crash_core.h
> @@ -38,8 +38,12 @@ phys_addr_t paddr_vmcoreinfo_note(void);
>  
>  #define VMCOREINFO_OSRELEASE(value) \
>  	vmcoreinfo_append_str("OSRELEASE=%s\n", value)
> -#define VMCOREINFO_BUILD_ID(value) \
> -	vmcoreinfo_append_str("BUILD-ID=%s\n", value)
> +#define VMCOREINFO_BUILD_ID()						\
> +	({								\
> +		static_assert(sizeof(vmlinux_build_id) == 20);		\
> +		vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \

Since there has been static_assert at above, can we remove the magic
number '20'? 

And I checked format_decode(), didn't find which type corresponds to
'N', could you tell?

Other than these, this patch looks good to me, thanks for the effort.

Thanks
Baoquan

> +	})
> +
>  #define VMCOREINFO_PAGESIZE(value) \
>  	vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
>  #define VMCOREINFO_SYMBOL(name) \
> @@ -69,10 +73,6 @@ extern unsigned char *vmcoreinfo_data;
>  extern size_t vmcoreinfo_size;
>  extern u32 *vmcoreinfo_note;
>  
> -/* raw contents of kernel .notes section */
> -extern const void __start_notes __weak;
> -extern const void __stop_notes __weak;
> -
>  Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type,
>  			  void *data, size_t data_len);
>  void final_note(Elf_Word *buf);
> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
> index 825284baaf46..29cc15398ee4 100644
> --- a/kernel/crash_core.c
> +++ b/kernel/crash_core.c
> @@ -4,6 +4,7 @@
>   * Copyright (C) 2002-2004 Eric Biederman  <ebiederm@xmission.com>
>   */
>  
> +#include <linux/buildid.h>
>  #include <linux/crash_core.h>
>  #include <linux/utsname.h>
>  #include <linux/vmalloc.h>
> @@ -378,53 +379,6 @@ phys_addr_t __weak paddr_vmcoreinfo_note(void)
>  }
>  EXPORT_SYMBOL(paddr_vmcoreinfo_note);
>  
> -#define NOTES_SIZE (&__stop_notes - &__start_notes)
> -#define BUILD_ID_MAX SHA1_DIGEST_SIZE
> -#define NT_GNU_BUILD_ID 3
> -
> -struct elf_note_section {
> -	struct elf_note	n_hdr;
> -	u8 n_data[];
> -};
> -
> -/*
> - * Add build ID from .notes section as generated by the GNU ld(1)
> - * or LLVM lld(1) --build-id option.
> - */
> -static void add_build_id_vmcoreinfo(void)
> -{
> -	char build_id[BUILD_ID_MAX * 2 + 1];
> -	int n_remain = NOTES_SIZE;
> -
> -	while (n_remain >= sizeof(struct elf_note)) {
> -		const struct elf_note_section *note_sec =
> -			&__start_notes + NOTES_SIZE - n_remain;
> -		const u32 n_namesz = note_sec->n_hdr.n_namesz;
> -
> -		if (note_sec->n_hdr.n_type == NT_GNU_BUILD_ID &&
> -		    n_namesz != 0 &&
> -		    !strcmp((char *)&note_sec->n_data[0], "GNU")) {
> -			if (note_sec->n_hdr.n_descsz <= BUILD_ID_MAX) {
> -				const u32 n_descsz = note_sec->n_hdr.n_descsz;
> -				const u8 *s = &note_sec->n_data[n_namesz];
> -
> -				s = PTR_ALIGN(s, 4);
> -				bin2hex(build_id, s, n_descsz);
> -				build_id[2 * n_descsz] = '\0';
> -				VMCOREINFO_BUILD_ID(build_id);
> -				return;
> -			}
> -			pr_warn("Build ID is too large to include in vmcoreinfo: %u > %u\n",
> -				note_sec->n_hdr.n_descsz,
> -				BUILD_ID_MAX);
> -			return;
> -		}
> -		n_remain -= sizeof(struct elf_note) +
> -			ALIGN(note_sec->n_hdr.n_namesz, 4) +
> -			ALIGN(note_sec->n_hdr.n_descsz, 4);
> -	}
> -}
> -
>  static int __init crash_save_vmcoreinfo_init(void)
>  {
>  	vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL);
> @@ -443,7 +397,7 @@ static int __init crash_save_vmcoreinfo_init(void)
>  	}
>  
>  	VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
> -	add_build_id_vmcoreinfo();
> +	VMCOREINFO_BUILD_ID();
>  	VMCOREINFO_PAGESIZE(PAGE_SIZE);
>  
>  	VMCOREINFO_SYMBOL(init_uts_ns);
> -- 
> https://chromeos.dev
> 
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 


^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 13/13] kdump: Use vmlinux_build_id to simplify
@ 2021-04-28 10:13     ` Baoquan He
  0 siblings, 0 replies; 39+ messages in thread
From: Baoquan He @ 2021-04-28 10:13 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Dave Young, Vivek Goyal,
	kexec

On 04/20/21 at 02:50pm, Stephen Boyd wrote:
> We can use the vmlinux_build_id array here now instead of open coding
> it. This mostly consolidates code.
> 
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Jessica Yu <jeyu@kernel.org>
> Cc: Evan Green <evgreen@chromium.org>
> Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> Cc: Dave Young <dyoung@redhat.com>
> Cc: Baoquan He <bhe@redhat.com>
> Cc: Vivek Goyal <vgoyal@redhat.com>
> Cc: <kexec@lists.infradead.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
>  include/linux/crash_core.h | 12 ++++-----
>  kernel/crash_core.c        | 50 ++------------------------------------
>  2 files changed, 8 insertions(+), 54 deletions(-)
> 
> diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
> index 206bde8308b2..de62a722431e 100644
> --- a/include/linux/crash_core.h
> +++ b/include/linux/crash_core.h
> @@ -38,8 +38,12 @@ phys_addr_t paddr_vmcoreinfo_note(void);
>  
>  #define VMCOREINFO_OSRELEASE(value) \
>  	vmcoreinfo_append_str("OSRELEASE=%s\n", value)
> -#define VMCOREINFO_BUILD_ID(value) \
> -	vmcoreinfo_append_str("BUILD-ID=%s\n", value)
> +#define VMCOREINFO_BUILD_ID()						\
> +	({								\
> +		static_assert(sizeof(vmlinux_build_id) == 20);		\
> +		vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \

Since there has been static_assert at above, can we remove the magic
number '20'? 

And I checked format_decode(), didn't find which type corresponds to
'N', could you tell?

Other than these, this patch looks good to me, thanks for the effort.

Thanks
Baoquan

> +	})
> +
>  #define VMCOREINFO_PAGESIZE(value) \
>  	vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
>  #define VMCOREINFO_SYMBOL(name) \
> @@ -69,10 +73,6 @@ extern unsigned char *vmcoreinfo_data;
>  extern size_t vmcoreinfo_size;
>  extern u32 *vmcoreinfo_note;
>  
> -/* raw contents of kernel .notes section */
> -extern const void __start_notes __weak;
> -extern const void __stop_notes __weak;
> -
>  Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type,
>  			  void *data, size_t data_len);
>  void final_note(Elf_Word *buf);
> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
> index 825284baaf46..29cc15398ee4 100644
> --- a/kernel/crash_core.c
> +++ b/kernel/crash_core.c
> @@ -4,6 +4,7 @@
>   * Copyright (C) 2002-2004 Eric Biederman  <ebiederm@xmission.com>
>   */
>  
> +#include <linux/buildid.h>
>  #include <linux/crash_core.h>
>  #include <linux/utsname.h>
>  #include <linux/vmalloc.h>
> @@ -378,53 +379,6 @@ phys_addr_t __weak paddr_vmcoreinfo_note(void)
>  }
>  EXPORT_SYMBOL(paddr_vmcoreinfo_note);
>  
> -#define NOTES_SIZE (&__stop_notes - &__start_notes)
> -#define BUILD_ID_MAX SHA1_DIGEST_SIZE
> -#define NT_GNU_BUILD_ID 3
> -
> -struct elf_note_section {
> -	struct elf_note	n_hdr;
> -	u8 n_data[];
> -};
> -
> -/*
> - * Add build ID from .notes section as generated by the GNU ld(1)
> - * or LLVM lld(1) --build-id option.
> - */
> -static void add_build_id_vmcoreinfo(void)
> -{
> -	char build_id[BUILD_ID_MAX * 2 + 1];
> -	int n_remain = NOTES_SIZE;
> -
> -	while (n_remain >= sizeof(struct elf_note)) {
> -		const struct elf_note_section *note_sec =
> -			&__start_notes + NOTES_SIZE - n_remain;
> -		const u32 n_namesz = note_sec->n_hdr.n_namesz;
> -
> -		if (note_sec->n_hdr.n_type == NT_GNU_BUILD_ID &&
> -		    n_namesz != 0 &&
> -		    !strcmp((char *)&note_sec->n_data[0], "GNU")) {
> -			if (note_sec->n_hdr.n_descsz <= BUILD_ID_MAX) {
> -				const u32 n_descsz = note_sec->n_hdr.n_descsz;
> -				const u8 *s = &note_sec->n_data[n_namesz];
> -
> -				s = PTR_ALIGN(s, 4);
> -				bin2hex(build_id, s, n_descsz);
> -				build_id[2 * n_descsz] = '\0';
> -				VMCOREINFO_BUILD_ID(build_id);
> -				return;
> -			}
> -			pr_warn("Build ID is too large to include in vmcoreinfo: %u > %u\n",
> -				note_sec->n_hdr.n_descsz,
> -				BUILD_ID_MAX);
> -			return;
> -		}
> -		n_remain -= sizeof(struct elf_note) +
> -			ALIGN(note_sec->n_hdr.n_namesz, 4) +
> -			ALIGN(note_sec->n_hdr.n_descsz, 4);
> -	}
> -}
> -
>  static int __init crash_save_vmcoreinfo_init(void)
>  {
>  	vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL);
> @@ -443,7 +397,7 @@ static int __init crash_save_vmcoreinfo_init(void)
>  	}
>  
>  	VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
> -	add_build_id_vmcoreinfo();
> +	VMCOREINFO_BUILD_ID();
>  	VMCOREINFO_PAGESIZE(PAGE_SIZE);
>  
>  	VMCOREINFO_SYMBOL(init_uts_ns);
> -- 
> https://chromeos.dev
> 
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 13/13] kdump: Use vmlinux_build_id to simplify
  2021-04-28 10:13     ` Baoquan He
@ 2021-04-28 23:14       ` Stephen Boyd
  -1 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-28 23:14 UTC (permalink / raw)
  To: Baoquan He
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Dave Young, Vivek Goyal,
	kexec

Quoting Baoquan He (2021-04-28 03:13:55)
> On 04/20/21 at 02:50pm, Stephen Boyd wrote:
> > We can use the vmlinux_build_id array here now instead of open coding
> > it. This mostly consolidates code.
> >
> > Cc: Jiri Olsa <jolsa@kernel.org>
> > Cc: Alexei Starovoitov <ast@kernel.org>
> > Cc: Jessica Yu <jeyu@kernel.org>
> > Cc: Evan Green <evgreen@chromium.org>
> > Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> > Cc: Dave Young <dyoung@redhat.com>
> > Cc: Baoquan He <bhe@redhat.com>
> > Cc: Vivek Goyal <vgoyal@redhat.com>
> > Cc: <kexec@lists.infradead.org>
> > Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> > ---
> >  include/linux/crash_core.h | 12 ++++-----
> >  kernel/crash_core.c        | 50 ++------------------------------------
> >  2 files changed, 8 insertions(+), 54 deletions(-)
> >
> > diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
> > index 206bde8308b2..de62a722431e 100644
> > --- a/include/linux/crash_core.h
> > +++ b/include/linux/crash_core.h
> > @@ -38,8 +38,12 @@ phys_addr_t paddr_vmcoreinfo_note(void);
> >
> >  #define VMCOREINFO_OSRELEASE(value) \
> >       vmcoreinfo_append_str("OSRELEASE=%s\n", value)
> > -#define VMCOREINFO_BUILD_ID(value) \
> > -     vmcoreinfo_append_str("BUILD-ID=%s\n", value)
> > +#define VMCOREINFO_BUILD_ID()                                                \
> > +     ({                                                              \
> > +             static_assert(sizeof(vmlinux_build_id) == 20);          \
> > +             vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \
>
> Since there has been static_assert at above, can we remove the magic
> number '20'?
>
> And I checked format_decode(), didn't find which type corresponds to
> 'N', could you tell?

It is documented in Documentation/core-api/printk-formats.rst (see "Raw
buffer as a hex string") where the '20' replaces the '*' to specify a
fixed size buffer to format. We could pass the 20 as an argument instead
of encoding it in the format, but then it would still be there twice. We
could use a #define but then it would have to be passed as an argument.

I don't know of a good way to enforce in printk that the buffer is the
size that matches the format size. Maybe it shouldn't be an option to
have a size in the format string if it's a problem to put the size of
the buffer in there.

>
> Other than these, this patch looks good to me, thanks for the effort.
>

Thanks.

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 13/13] kdump: Use vmlinux_build_id to simplify
@ 2021-04-28 23:14       ` Stephen Boyd
  0 siblings, 0 replies; 39+ messages in thread
From: Stephen Boyd @ 2021-04-28 23:14 UTC (permalink / raw)
  To: Baoquan He
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Dave Young, Vivek Goyal,
	kexec

Quoting Baoquan He (2021-04-28 03:13:55)
> On 04/20/21 at 02:50pm, Stephen Boyd wrote:
> > We can use the vmlinux_build_id array here now instead of open coding
> > it. This mostly consolidates code.
> >
> > Cc: Jiri Olsa <jolsa@kernel.org>
> > Cc: Alexei Starovoitov <ast@kernel.org>
> > Cc: Jessica Yu <jeyu@kernel.org>
> > Cc: Evan Green <evgreen@chromium.org>
> > Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> > Cc: Dave Young <dyoung@redhat.com>
> > Cc: Baoquan He <bhe@redhat.com>
> > Cc: Vivek Goyal <vgoyal@redhat.com>
> > Cc: <kexec@lists.infradead.org>
> > Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> > ---
> >  include/linux/crash_core.h | 12 ++++-----
> >  kernel/crash_core.c        | 50 ++------------------------------------
> >  2 files changed, 8 insertions(+), 54 deletions(-)
> >
> > diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
> > index 206bde8308b2..de62a722431e 100644
> > --- a/include/linux/crash_core.h
> > +++ b/include/linux/crash_core.h
> > @@ -38,8 +38,12 @@ phys_addr_t paddr_vmcoreinfo_note(void);
> >
> >  #define VMCOREINFO_OSRELEASE(value) \
> >       vmcoreinfo_append_str("OSRELEASE=%s\n", value)
> > -#define VMCOREINFO_BUILD_ID(value) \
> > -     vmcoreinfo_append_str("BUILD-ID=%s\n", value)
> > +#define VMCOREINFO_BUILD_ID()                                                \
> > +     ({                                                              \
> > +             static_assert(sizeof(vmlinux_build_id) == 20);          \
> > +             vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \
>
> Since there has been static_assert at above, can we remove the magic
> number '20'?
>
> And I checked format_decode(), didn't find which type corresponds to
> 'N', could you tell?

It is documented in Documentation/core-api/printk-formats.rst (see "Raw
buffer as a hex string") where the '20' replaces the '*' to specify a
fixed size buffer to format. We could pass the 20 as an argument instead
of encoding it in the format, but then it would still be there twice. We
could use a #define but then it would have to be passed as an argument.

I don't know of a good way to enforce in printk that the buffer is the
size that matches the format size. Maybe it shouldn't be an option to
have a size in the format string if it's a problem to put the size of
the buffer in there.

>
> Other than these, this patch looks good to me, thanks for the effort.
>

Thanks.

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 13/13] kdump: Use vmlinux_build_id to simplify
  2021-04-28 23:14       ` Stephen Boyd
@ 2021-05-07  3:54         ` Baoquan He
  -1 siblings, 0 replies; 39+ messages in thread
From: Baoquan He @ 2021-05-07  3:54 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Dave Young, Vivek Goyal,
	kexec

On 04/29/21 at 01:14am, Stephen Boyd wrote:
> Quoting Baoquan He (2021-04-28 03:13:55)
> > On 04/20/21 at 02:50pm, Stephen Boyd wrote:
> > > We can use the vmlinux_build_id array here now instead of open coding
> > > it. This mostly consolidates code.
> > >
> > > Cc: Jiri Olsa <jolsa@kernel.org>
> > > Cc: Alexei Starovoitov <ast@kernel.org>
> > > Cc: Jessica Yu <jeyu@kernel.org>
> > > Cc: Evan Green <evgreen@chromium.org>
> > > Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> > > Cc: Dave Young <dyoung@redhat.com>
> > > Cc: Baoquan He <bhe@redhat.com>
> > > Cc: Vivek Goyal <vgoyal@redhat.com>
> > > Cc: <kexec@lists.infradead.org>
> > > Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> > > ---
> > >  include/linux/crash_core.h | 12 ++++-----
> > >  kernel/crash_core.c        | 50 ++------------------------------------
> > >  2 files changed, 8 insertions(+), 54 deletions(-)
> > >
> > > diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
> > > index 206bde8308b2..de62a722431e 100644
> > > --- a/include/linux/crash_core.h
> > > +++ b/include/linux/crash_core.h
> > > @@ -38,8 +38,12 @@ phys_addr_t paddr_vmcoreinfo_note(void);
> > >
> > >  #define VMCOREINFO_OSRELEASE(value) \
> > >       vmcoreinfo_append_str("OSRELEASE=%s\n", value)
> > > -#define VMCOREINFO_BUILD_ID(value) \
> > > -     vmcoreinfo_append_str("BUILD-ID=%s\n", value)
> > > +#define VMCOREINFO_BUILD_ID()                                                \
> > > +     ({                                                              \
> > > +             static_assert(sizeof(vmlinux_build_id) == 20);          \
> > > +             vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \
> >
> > Since there has been static_assert at above, can we remove the magic
> > number '20'?
> >
> > And I checked format_decode(), didn't find which type corresponds to
> > 'N', could you tell?
> 
> It is documented in Documentation/core-api/printk-formats.rst (see "Raw
> buffer as a hex string") where the '20' replaces the '*' to specify a
> fixed size buffer to format. We could pass the 20 as an argument instead
> of encoding it in the format, but then it would still be there twice. We
> could use a #define but then it would have to be passed as an argument.

Thanks for telling, I can see 'phN' is used in many places, but haven't
figured out how it's parsed, e.g in format_decode() it's not related.
Anyway, I may need dig further or search to get it.

> 
> I don't know of a good way to enforce in printk that the buffer is the
> size that matches the format size. Maybe it shouldn't be an option to
> have a size in the format string if it's a problem to put the size of
> the buffer in there.

Oh, I meant that we may not need to enforce that because the size of
vmlinux_build_id can be guaranteed, always 20, we do not need to specify
the '20'? Afaik, we usually specify the format size when the string size
is variable, and we want to add '0' to make the width of printing is
fixed. Anyway, this dones't matter much.

Acked-by: Baoquan He <bhe@redhat.com>

Thanks
Baoquan

> 
> >
> > Other than these, this patch looks good to me, thanks for the effort.
> >
> 
> Thanks.
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 


^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 13/13] kdump: Use vmlinux_build_id to simplify
@ 2021-05-07  3:54         ` Baoquan He
  0 siblings, 0 replies; 39+ messages in thread
From: Baoquan He @ 2021-05-07  3:54 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Dave Young, Vivek Goyal,
	kexec

On 04/29/21 at 01:14am, Stephen Boyd wrote:
> Quoting Baoquan He (2021-04-28 03:13:55)
> > On 04/20/21 at 02:50pm, Stephen Boyd wrote:
> > > We can use the vmlinux_build_id array here now instead of open coding
> > > it. This mostly consolidates code.
> > >
> > > Cc: Jiri Olsa <jolsa@kernel.org>
> > > Cc: Alexei Starovoitov <ast@kernel.org>
> > > Cc: Jessica Yu <jeyu@kernel.org>
> > > Cc: Evan Green <evgreen@chromium.org>
> > > Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> > > Cc: Dave Young <dyoung@redhat.com>
> > > Cc: Baoquan He <bhe@redhat.com>
> > > Cc: Vivek Goyal <vgoyal@redhat.com>
> > > Cc: <kexec@lists.infradead.org>
> > > Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> > > ---
> > >  include/linux/crash_core.h | 12 ++++-----
> > >  kernel/crash_core.c        | 50 ++------------------------------------
> > >  2 files changed, 8 insertions(+), 54 deletions(-)
> > >
> > > diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
> > > index 206bde8308b2..de62a722431e 100644
> > > --- a/include/linux/crash_core.h
> > > +++ b/include/linux/crash_core.h
> > > @@ -38,8 +38,12 @@ phys_addr_t paddr_vmcoreinfo_note(void);
> > >
> > >  #define VMCOREINFO_OSRELEASE(value) \
> > >       vmcoreinfo_append_str("OSRELEASE=%s\n", value)
> > > -#define VMCOREINFO_BUILD_ID(value) \
> > > -     vmcoreinfo_append_str("BUILD-ID=%s\n", value)
> > > +#define VMCOREINFO_BUILD_ID()                                                \
> > > +     ({                                                              \
> > > +             static_assert(sizeof(vmlinux_build_id) == 20);          \
> > > +             vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \
> >
> > Since there has been static_assert at above, can we remove the magic
> > number '20'?
> >
> > And I checked format_decode(), didn't find which type corresponds to
> > 'N', could you tell?
> 
> It is documented in Documentation/core-api/printk-formats.rst (see "Raw
> buffer as a hex string") where the '20' replaces the '*' to specify a
> fixed size buffer to format. We could pass the 20 as an argument instead
> of encoding it in the format, but then it would still be there twice. We
> could use a #define but then it would have to be passed as an argument.

Thanks for telling, I can see 'phN' is used in many places, but haven't
figured out how it's parsed, e.g in format_decode() it's not related.
Anyway, I may need dig further or search to get it.

> 
> I don't know of a good way to enforce in printk that the buffer is the
> size that matches the format size. Maybe it shouldn't be an option to
> have a size in the format string if it's a problem to put the size of
> the buffer in there.

Oh, I meant that we may not need to enforce that because the size of
vmlinux_build_id can be guaranteed, always 20, we do not need to specify
the '20'? Afaik, we usually specify the format size when the string size
is variable, and we want to add '0' to make the width of printing is
fixed. Anyway, this dones't matter much.

Acked-by: Baoquan He <bhe@redhat.com>

Thanks
Baoquan

> 
> >
> > Other than these, this patch looks good to me, thanks for the effort.
> >
> 
> Thanks.
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 13/13] kdump: Use vmlinux_build_id to simplify
  2021-05-07  3:54         ` Baoquan He
@ 2021-05-07  4:04           ` Baoquan He
  -1 siblings, 0 replies; 39+ messages in thread
From: Baoquan He @ 2021-05-07  4:04 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Dave Young, Vivek Goyal,
	kexec

On 05/07/21 at 11:54am, Baoquan He wrote:
> On 04/29/21 at 01:14am, Stephen Boyd wrote:
> > Quoting Baoquan He (2021-04-28 03:13:55)
> > > On 04/20/21 at 02:50pm, Stephen Boyd wrote:
> > > > We can use the vmlinux_build_id array here now instead of open coding
> > > > it. This mostly consolidates code.
> > > >
> > > > Cc: Jiri Olsa <jolsa@kernel.org>
> > > > Cc: Alexei Starovoitov <ast@kernel.org>
> > > > Cc: Jessica Yu <jeyu@kernel.org>
> > > > Cc: Evan Green <evgreen@chromium.org>
> > > > Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> > > > Cc: Dave Young <dyoung@redhat.com>
> > > > Cc: Baoquan He <bhe@redhat.com>
> > > > Cc: Vivek Goyal <vgoyal@redhat.com>
> > > > Cc: <kexec@lists.infradead.org>
> > > > Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> > > > ---
> > > >  include/linux/crash_core.h | 12 ++++-----
> > > >  kernel/crash_core.c        | 50 ++------------------------------------
> > > >  2 files changed, 8 insertions(+), 54 deletions(-)
> > > >
> > > > diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
> > > > index 206bde8308b2..de62a722431e 100644
> > > > --- a/include/linux/crash_core.h
> > > > +++ b/include/linux/crash_core.h
> > > > @@ -38,8 +38,12 @@ phys_addr_t paddr_vmcoreinfo_note(void);
> > > >
> > > >  #define VMCOREINFO_OSRELEASE(value) \
> > > >       vmcoreinfo_append_str("OSRELEASE=%s\n", value)
> > > > -#define VMCOREINFO_BUILD_ID(value) \
> > > > -     vmcoreinfo_append_str("BUILD-ID=%s\n", value)
> > > > +#define VMCOREINFO_BUILD_ID()                                                \
> > > > +     ({                                                              \
> > > > +             static_assert(sizeof(vmlinux_build_id) == 20);          \
> > > > +             vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \
> > >
> > > Since there has been static_assert at above, can we remove the magic
> > > number '20'?
> > >
> > > And I checked format_decode(), didn't find which type corresponds to
> > > 'N', could you tell?
> > 
> > It is documented in Documentation/core-api/printk-formats.rst (see "Raw
> > buffer as a hex string") where the '20' replaces the '*' to specify a
> > fixed size buffer to format. We could pass the 20 as an argument instead
> > of encoding it in the format, but then it would still be there twice. We
> > could use a #define but then it would have to be passed as an argument.
> 
> Thanks for telling, I can see 'phN' is used in many places, but haven't
> figured out how it's parsed, e.g in format_decode() it's not related.
> Anyway, I may need dig further or search to get it.
> 
> > 
> > I don't know of a good way to enforce in printk that the buffer is the
> > size that matches the format size. Maybe it shouldn't be an option to
> > have a size in the format string if it's a problem to put the size of
> > the buffer in there.
> 
> Oh, I meant that we may not need to enforce that because the size of
> vmlinux_build_id can be guaranteed, always 20, we do not need to specify
> the '20'? Afaik, we usually specify the format size when the string size
> is variable, and we want to add '0' to make the width of printing is
                                  ~'space' I meant
> fixed. Anyway, this dones't matter much.
> 
> Acked-by: Baoquan He <bhe@redhat.com>
> 
> Thanks
> Baoquan
> 
> > 
> > >
> > > Other than these, this patch looks good to me, thanks for the effort.
> > >
> > 
> > Thanks.
> > 
> > _______________________________________________
> > kexec mailing list
> > kexec@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/kexec
> > 
> 
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 


^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v5 13/13] kdump: Use vmlinux_build_id to simplify
@ 2021-05-07  4:04           ` Baoquan He
  0 siblings, 0 replies; 39+ messages in thread
From: Baoquan He @ 2021-05-07  4:04 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Andrew Morton, linux-kernel, Jiri Olsa, Alexei Starovoitov,
	Jessica Yu, Evan Green, Hsin-Yi Wang, Dave Young, Vivek Goyal,
	kexec

On 05/07/21 at 11:54am, Baoquan He wrote:
> On 04/29/21 at 01:14am, Stephen Boyd wrote:
> > Quoting Baoquan He (2021-04-28 03:13:55)
> > > On 04/20/21 at 02:50pm, Stephen Boyd wrote:
> > > > We can use the vmlinux_build_id array here now instead of open coding
> > > > it. This mostly consolidates code.
> > > >
> > > > Cc: Jiri Olsa <jolsa@kernel.org>
> > > > Cc: Alexei Starovoitov <ast@kernel.org>
> > > > Cc: Jessica Yu <jeyu@kernel.org>
> > > > Cc: Evan Green <evgreen@chromium.org>
> > > > Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> > > > Cc: Dave Young <dyoung@redhat.com>
> > > > Cc: Baoquan He <bhe@redhat.com>
> > > > Cc: Vivek Goyal <vgoyal@redhat.com>
> > > > Cc: <kexec@lists.infradead.org>
> > > > Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> > > > ---
> > > >  include/linux/crash_core.h | 12 ++++-----
> > > >  kernel/crash_core.c        | 50 ++------------------------------------
> > > >  2 files changed, 8 insertions(+), 54 deletions(-)
> > > >
> > > > diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
> > > > index 206bde8308b2..de62a722431e 100644
> > > > --- a/include/linux/crash_core.h
> > > > +++ b/include/linux/crash_core.h
> > > > @@ -38,8 +38,12 @@ phys_addr_t paddr_vmcoreinfo_note(void);
> > > >
> > > >  #define VMCOREINFO_OSRELEASE(value) \
> > > >       vmcoreinfo_append_str("OSRELEASE=%s\n", value)
> > > > -#define VMCOREINFO_BUILD_ID(value) \
> > > > -     vmcoreinfo_append_str("BUILD-ID=%s\n", value)
> > > > +#define VMCOREINFO_BUILD_ID()                                                \
> > > > +     ({                                                              \
> > > > +             static_assert(sizeof(vmlinux_build_id) == 20);          \
> > > > +             vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \
> > >
> > > Since there has been static_assert at above, can we remove the magic
> > > number '20'?
> > >
> > > And I checked format_decode(), didn't find which type corresponds to
> > > 'N', could you tell?
> > 
> > It is documented in Documentation/core-api/printk-formats.rst (see "Raw
> > buffer as a hex string") where the '20' replaces the '*' to specify a
> > fixed size buffer to format. We could pass the 20 as an argument instead
> > of encoding it in the format, but then it would still be there twice. We
> > could use a #define but then it would have to be passed as an argument.
> 
> Thanks for telling, I can see 'phN' is used in many places, but haven't
> figured out how it's parsed, e.g in format_decode() it's not related.
> Anyway, I may need dig further or search to get it.
> 
> > 
> > I don't know of a good way to enforce in printk that the buffer is the
> > size that matches the format size. Maybe it shouldn't be an option to
> > have a size in the format string if it's a problem to put the size of
> > the buffer in there.
> 
> Oh, I meant that we may not need to enforce that because the size of
> vmlinux_build_id can be guaranteed, always 20, we do not need to specify
> the '20'? Afaik, we usually specify the format size when the string size
> is variable, and we want to add '0' to make the width of printing is
                                  ~'space' I meant
> fixed. Anyway, this dones't matter much.
> 
> Acked-by: Baoquan He <bhe@redhat.com>
> 
> Thanks
> Baoquan
> 
> > 
> > >
> > > Other than these, this patch looks good to me, thanks for the effort.
> > >
> > 
> > Thanks.
> > 
> > _______________________________________________
> > kexec mailing list
> > kexec@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/kexec
> > 
> 
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2021-05-07  4:05 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 21:49 [PATCH v5 00/13] Add build ID to stacktraces Stephen Boyd
2021-04-20 21:49 ` Stephen Boyd
2021-04-20 21:49 ` Stephen Boyd
2021-04-20 21:49 ` [PATCH v5 01/13] buildid: Only consider GNU notes for build ID parsing Stephen Boyd
2021-04-20 21:49 ` [PATCH v5 02/13] buildid: Add API to parse build ID out of buffer Stephen Boyd
2021-04-20 21:49 ` [PATCH v5 03/13] buildid: Stash away kernels build ID on init Stephen Boyd
2021-04-20 21:49   ` Stephen Boyd
2021-04-28 10:02   ` Baoquan He
2021-04-28 10:02     ` Baoquan He
2021-04-20 21:49 ` [PATCH v5 04/13] dump_stack: Add vmlinux build ID to stack traces Stephen Boyd
2021-04-26 11:04   ` Petr Mladek
2021-04-26 23:40     ` Stephen Boyd
2021-04-20 21:49 ` [PATCH v5 05/13] module: Add printk formats to add module build ID to stacktraces Stephen Boyd
2021-04-21 11:49   ` Andy Shevchenko
2021-04-22 23:46     ` Stephen Boyd
2021-04-23 13:24       ` Andy Shevchenko
2021-04-23 13:45         ` Rasmus Villemoes
2021-04-23 14:08           ` Andy Shevchenko
2021-04-26 23:42         ` Stephen Boyd
2021-04-20 21:49 ` [PATCH v5 06/13] arm64: stacktrace: Use %pSb for backtrace printing Stephen Boyd
2021-04-20 21:49   ` Stephen Boyd
2021-04-21  9:58   ` Catalin Marinas
2021-04-21  9:58     ` Catalin Marinas
2021-04-20 21:49 ` [PATCH v5 07/13] x86/dumpstack: Use %pSb/%pBb " Stephen Boyd
2021-04-20 21:49 ` [PATCH v5 08/13] scripts/decode_stacktrace.sh: Support debuginfod Stephen Boyd
2021-04-20 21:49 ` [PATCH v5 09/13] scripts/decode_stacktrace.sh: Silence stderr messages from addr2line/nm Stephen Boyd
2021-04-20 21:50 ` [PATCH v5 10/13] scripts/decode_stacktrace.sh: Indicate 'auto' can be used for base path Stephen Boyd
2021-04-20 21:50 ` [PATCH v5 11/13] buildid: Mark some arguments const Stephen Boyd
2021-04-20 21:50 ` [PATCH v5 12/13] buildid: Fix kernel-doc notation Stephen Boyd
2021-04-20 21:50 ` [PATCH v5 13/13] kdump: Use vmlinux_build_id to simplify Stephen Boyd
2021-04-20 21:50   ` Stephen Boyd
2021-04-28 10:13   ` Baoquan He
2021-04-28 10:13     ` Baoquan He
2021-04-28 23:14     ` Stephen Boyd
2021-04-28 23:14       ` Stephen Boyd
2021-05-07  3:54       ` Baoquan He
2021-05-07  3:54         ` Baoquan He
2021-05-07  4:04         ` Baoquan He
2021-05-07  4:04           ` Baoquan He

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.