Skip to content

Commit e14af7e

Browse files
fenrus75Ingo Molnar
authored andcommitted
debug: track and print last unloaded module in the oops trace
Based on a suggestion from Andi: In various cases, the unload of a module may leave some bad state around that causes a kernel crash AFTER a module is unloaded; and it's then hard to find which module caused that. This patch tracks the last unloaded module, and prints this as part of the module list in the oops trace. Right now, only the last 1 module is tracked; I expect that this is enough for the vast majority of cases where this information matters; if it turns out that tracking more is important, we can always extend it to that. [ mingo@elte.hu: build fix ] Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 21aa928 commit e14af7e

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎kernel/module.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ static struct module_attribute modinfo_##field = { \
496496
MODINFO_ATTR(version);
497497
MODINFO_ATTR(srcversion);
498498

499+
static char last_unloaded_module[MODULE_NAME_LEN+1];
500+
499501
#ifdef CONFIG_MODULE_UNLOAD
500502
/* Init the unload section of the module. */
501503
static void module_unload_init(struct module *mod)
@@ -719,6 +721,8 @@ sys_delete_module(const char __user *name_user, unsigned int flags)
719721
mod->exit();
720722
mutex_lock(&module_mutex);
721723
}
724+
/* Store the name of the last unloaded module for diagnostic purposes */
725+
sprintf(last_unloaded_module, mod->name);
722726
free_module(mod);
723727

724728
out:
@@ -2503,6 +2507,8 @@ void print_modules(void)
25032507
printk("Modules linked in:");
25042508
list_for_each_entry(mod, &modules, list)
25052509
printk(" %s%s", mod->name, module_flags(mod, buf));
2510+
if (last_unloaded_module[0])
2511+
printk(" [last unloaded: %s]", last_unloaded_module);
25062512
printk("\n");
25072513
}
25082514

0 commit comments

Comments
 (0)