Skip to content

Commit

Permalink
init/main.c: add initcall_blacklist kernel parameter
Browse files Browse the repository at this point in the history
When a module is built into the kernel the module_init() function
becomes an initcall.  Sometimes debugging through dynamic debug can
help, however, debugging built in kernel modules is typically done by
changing the .config, recompiling, and booting the new kernel in an
effort to determine exactly which module caused a problem.

This patchset can be useful stand-alone or combined with initcall_debug.
There are cases where some initcalls can hang the machine before the
console can be flushed, which can make initcall_debug output inaccurate.
Having the ability to skip initcalls can help further debugging of these
scenarios.

Usage: initcall_blacklist=<list of comma separated initcalls>

ex) added "initcall_blacklist=sgi_uv_sysfs_init" as a kernel parameter and
the log contains:

	blacklisting initcall sgi_uv_sysfs_init
	...
	...
	initcall sgi_uv_sysfs_init blacklisted

ex) added "initcall_blacklist=foo_bar,sgi_uv_sysfs_init" as a kernel parameter
and the log contains:

	blacklisting initcall foo_bar
	blacklisting initcall sgi_uv_sysfs_init
	...
	...
	initcall sgi_uv_sysfs_init blacklisted

[[email protected]: tweak printk text]
Signed-off-by: Prarit Bhargava <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Josh Boyer <[email protected]>
Cc: Rob Landley <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
prarit authored and torvalds committed Jun 4, 2014
1 parent d62cf81 commit 7b0b73d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Documentation/kernel-parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
for working out where the kernel is dying during
startup.

initcall_blacklist= [KNL] Do not execute a comma-separated list of
initcall functions. Useful for debugging built-in
modules and initcalls.

initrd= [BOOT] Specify the location of the initial ramdisk

inport.irq= [HW] Inport (ATI XL and Microsoft) busmouse driver
Expand Down
68 changes: 68 additions & 0 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include <linux/sched_clock.h>
#include <linux/context_tracking.h>
#include <linux/random.h>
#include <linux/list.h>

#include <asm/io.h>
#include <asm/bugs.h>
Expand Down Expand Up @@ -665,6 +666,70 @@ static void __init do_ctors(void)
bool initcall_debug;
core_param(initcall_debug, initcall_debug, bool, 0644);

#ifdef CONFIG_KALLSYMS
struct blacklist_entry {
struct list_head next;
char *buf;
};

static __initdata_or_module LIST_HEAD(blacklisted_initcalls);

static int __init initcall_blacklist(char *str)
{
char *str_entry;
struct blacklist_entry *entry;

/* str argument is a comma-separated list of functions */
do {
str_entry = strsep(&str, ",");
if (str_entry) {
pr_debug("blacklisting initcall %s\n", str_entry);
entry = alloc_bootmem(sizeof(*entry));
entry->buf = alloc_bootmem(strlen(str_entry) + 1);
strcpy(entry->buf, str_entry);
list_add(&entry->next, &blacklisted_initcalls);
}
} while (str_entry);

return 0;
}

static bool __init_or_module initcall_blacklisted(initcall_t fn)
{
struct list_head *tmp;
struct blacklist_entry *entry;
char *fn_name;

fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
if (!fn_name)
return false;

list_for_each(tmp, &blacklisted_initcalls) {
entry = list_entry(tmp, struct blacklist_entry, next);
if (!strcmp(fn_name, entry->buf)) {
pr_debug("initcall %s blacklisted\n", fn_name);
kfree(fn_name);
return true;
}
}

kfree(fn_name);
return false;
}
#else
static int __init initcall_blacklist(char *str)
{
pr_warn("initcall_blacklist requires CONFIG_KALLSYMS\n");
return 0;
}

static bool __init_or_module initcall_blacklisted(initcall_t fn)
{
return false;
}
#endif
__setup("initcall_blacklist=", initcall_blacklist);

static int __init_or_module do_one_initcall_debug(initcall_t fn)
{
ktime_t calltime, delta, rettime;
Expand All @@ -689,6 +754,9 @@ int __init_or_module do_one_initcall(initcall_t fn)
int ret;
char msgbuf[64];

if (initcall_blacklisted(fn))
return -EPERM;

if (initcall_debug)
ret = do_one_initcall_debug(fn);
else
Expand Down

0 comments on commit 7b0b73d

Please sign in to comment.