linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Boyd <swboyd@chromium.org>
To: Petr Mladek <pmladek@suse.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>, Jessica Yu <jeyu@kernel.org>,
	Evan Green <evgreen@chromium.org>,
	Hsin-Yi Wang <hsinyi@chromium.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	linux-doc@vger.kernel.org, Matthew Wilcox <willy@infradead.org>
Subject: Re: [PATCH v2 04/12] module: Add printk format to add module build ID to stacktraces
Date: Tue, 30 Mar 2021 12:12:29 -0700	[thread overview]
Message-ID: <161713154989.2260335.1975274918938126463@swboyd.mtv.corp.google.com> (raw)
In-Reply-To: <YGL9hHFg9Pm4xaNM@alley>

Quoting Petr Mladek (2021-03-30 03:29:24)
> On Tue 2021-03-23 19:04:35, 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.
> > 
> > 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
> 
> I tested it with "echo l >/proc/sysrq-trigger" and I got the following
> output:
> 
> [   71.905593] CPU: 0 PID: 1762 Comm: bash Kdump: loaded Not tainted 5.12.0-rc5-default+ #167 00000080ffffffff0000000000000000
> 00000000
> 
> It does not looks like an unique build-id.
> Any idea what was going wrong?

Hmm not sure. What does 'hexdump /sys/kernel/notes' show or 'file
vmlinux' parse out of the kernel image?

> 
> > --- a/include/linux/kallsyms.h
> > +++ b/include/linux/kallsyms.h
> > @@ -91,6 +93,7 @@ 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_stacktrace(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);
> 
> Could we use a more clear name? It is hard to guess what is
> the difference between sprint_*_stacktrace() and sprint_backtrace().
> 
> What about sprint_symbol_build_id() ?

Sure.

> 
> 
> > diff --git a/kernel/module.c b/kernel/module.c
> > index 30479355ab85..9e9cb502fb33 100644
> > --- a/kernel/module.c
> > +++ b/kernel/module.c
> > @@ -2770,6 +2771,20 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
> >       }
> >       mod->core_kallsyms.num_symtab = ndst;
> >  }
> > +
> > +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;
> > +     }
> 
> Just to be sure. Is this really reliable way how to find the build ID,
> please?
> 

The build ID is always part of a note section, so if we parse the notes
and find a build ID type of section (see nhdr->n_type == BUILD_ID) with
a GNU name then we know we have the right section and will be able to
parse the ID out of the buffer.

  reply	other threads:[~2021-03-30 19:13 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24  2:04 [PATCH v2 00/12] Add build ID to stacktraces Stephen Boyd
2021-03-24  2:04 ` [PATCH v2 01/12] buildid: Add API to parse build ID out of buffer Stephen Boyd
2021-03-24  2:04 ` [PATCH v2 02/12] buildid: Add method to get running kernel's build ID Stephen Boyd
2021-03-24  9:24   ` Rasmus Villemoes
2021-03-24 19:06     ` Stephen Boyd
2021-03-24  2:04 ` [PATCH v2 03/12] dump_stack: Add vmlinux build ID to stack traces Stephen Boyd
2021-03-24 11:22   ` Andy Shevchenko
2021-03-24 19:01     ` Stephen Boyd
2021-03-24  2:04 ` [PATCH v2 04/12] module: Add printk format to add module build ID to stacktraces Stephen Boyd
2021-03-24  9:57   ` Rasmus Villemoes
2021-03-24 19:11     ` Stephen Boyd
2021-03-24 22:21       ` Rasmus Villemoes
2021-03-24 22:28         ` Stephen Boyd
2021-03-30 10:51           ` Petr Mladek
2021-03-30 10:29   ` Petr Mladek
2021-03-30 19:12     ` Stephen Boyd [this message]
2021-03-24  2:04 ` [PATCH v2 05/12] arm64: stacktrace: Use %pSb for backtrace printing Stephen Boyd
2021-03-24  2:04 ` [PATCH v2 06/12] x86/dumpstack: " Stephen Boyd
2021-03-24  2:04 ` [PATCH v2 07/12] scripts/decode_stacktrace.sh: Support debuginfod Stephen Boyd
2021-03-24 11:27   ` Andy Shevchenko
2021-03-24 22:22     ` Stephen Boyd
2021-03-24  2:04 ` [PATCH v2 08/12] scripts/decode_stacktrace.sh: Silence stderr messages from addr2line/nm Stephen Boyd
2021-03-24  2:04 ` [PATCH v2 09/12] scripts/decode_stacktrace.sh: Indicate 'auto' can be used for base path Stephen Boyd
2021-03-24  2:04 ` [PATCH v2 10/12] buildid: Mark some arguments const Stephen Boyd
2021-03-24  2:04 ` [PATCH v2 11/12] buildid: Fix kernel-doc notation Stephen Boyd
2021-03-24  2:04 ` [PATCH v2 12/12] kdump: Use vmlinux_build_id() to simplify Stephen Boyd
2021-03-24  8:55 ` [PATCH v2 00/12] Add build ID to stacktraces Christoph Hellwig
2021-03-25 11:06   ` peter enderborg
2021-03-25 23:21     ` Stephen Boyd
2021-03-30 10:59       ` Petr Mladek
     [not found] ` <32011616573677@mail.yandex-team.ru>
2021-03-24 19:04   ` Stephen Boyd
2021-03-25 11:14 ` peter enderborg
2021-03-25 23:18   ` Stephen Boyd

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=161713154989.2260335.1975274918938126463@swboyd.mtv.corp.google.com \
    --to=swboyd@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ast@kernel.org \
    --cc=evgreen@chromium.org \
    --cc=hsinyi@chromium.org \
    --cc=jeyu@kernel.org \
    --cc=jolsa@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).