forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: add printk formats to add module build ID to stacktraces
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. Before: Call trace: lkdtm_WARNING+0x28/0x30 [lkdtm] direct_entry+0x16c/0x1b4 [lkdtm] full_proxy_write+0x74/0xa4 vfs_write+0xec/0x2e8 After: Call trace: lkdtm_WARNING+0x28/0x30 [lkdtm 6c2215028606bda50de823490723dc4bc5bf46f9] direct_entry+0x16c/0x1b4 [lkdtm 6c2215028606bda50de823490723dc4bc5bf46f9] full_proxy_write+0x74/0xa4 vfs_write+0xec/0x2e8 [[email protected]: fix build with CONFIG_MODULES=n, tweak code layout] [[email protected]: fix build when CONFIG_MODULES is not set] Link: https://lkml.kernel.org/r/[email protected] [[email protected]: make kallsyms_lookup_buildid() static] [[email protected]: fix build error when CONFIG_SYSFS is disabled] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Link: https://fedoraproject.org/wiki/Releases/FeatureBuildId [1] Link: https://sourceware.org/elfutils/Debuginfod.html [2] Signed-off-by: Stephen Boyd <[email protected]> Signed-off-by: Bixuan Cui <[email protected]> Signed-off-by: Randy Dunlap <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Jessica Yu <[email protected]> Cc: Evan Green <[email protected]> Cc: Hsin-Yi Wang <[email protected]> Cc: Petr Mladek <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: Rasmus Villemoes <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Baoquan He <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Dave Young <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Konstantin Khlebnikov <[email protected]> Cc: Sasha Levin <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vivek Goyal <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
- Loading branch information
Showing
6 changed files
with
166 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -1465,18 +1466,20 @@ resolve_symbol_wait(struct module *mod, | |
return ksym; | ||
} | ||
|
||
#ifdef CONFIG_KALLSYMS | ||
static inline bool sect_empty(const Elf_Shdr *sect) | ||
{ | ||
return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0; | ||
} | ||
#endif | ||
|
||
/* | ||
* /sys/module/foo/sections stuff | ||
* J. Corbet <[email protected]> | ||
*/ | ||
#ifdef CONFIG_SYSFS | ||
|
||
#ifdef CONFIG_KALLSYMS | ||
static inline bool sect_empty(const Elf_Shdr *sect) | ||
{ | ||
return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0; | ||
} | ||
|
||
struct module_sect_attr { | ||
struct bin_attribute battr; | ||
unsigned long address; | ||
|
@@ -2797,6 +2800,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) | ||
|
@@ -4021,6 +4044,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 */ | ||
|
@@ -4254,6 +4278,7 @@ const char *module_address_lookup(unsigned long addr, | |
unsigned long *size, | ||
unsigned long *offset, | ||
char **modname, | ||
const unsigned char **modbuildid, | ||
char *namebuf) | ||
{ | ||
const char *ret = NULL; | ||
|
@@ -4264,6 +4289,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); | ||
} | ||
|
Oops, something went wrong.