All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add initcall_blacklist kernel parameter [v4]
@ 2014-04-01 15:19 Prarit Bhargava
  2014-04-14 21:29 ` Andrew Morton
  0 siblings, 1 reply; 6+ messages in thread
From: Prarit Bhargava @ 2014-04-01 15:19 UTC (permalink / raw)
  To: linux-kernel
  Cc: Prarit Bhargava, Richard Weinberger, Andi Kleen, Josh Boyer,
	Rob Landley, Andrew Morton, Steven Rostedt, Ingo Molnar,
	Peter Zijlstra, Frederic Weisbecker, linux-doc

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:

	blacklisted initcall sgi_uv_sysfs_init
	...
	...
	function sgi_uv_sysfs_init returning without executing

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

	initcall blacklisted foo_bar
	initcall blacklisted sgi_uv_sysfs_init
	...
	...
	function sgi_uv_sysfs_init returning without executing

Cc: Richard Weinberger <richard.weinberger@gmail.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Josh Boyer <jwboyer@fedoraproject.org>
Cc: Rob Landley <rob@landley.net>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: linux-doc@vger.kernel.org
Signed-off-by: Prarit Bhargava <prarit@redhat.com>

[v2]: A few people recommended that I add code to allow for a list of
initcalls as there maybe dependencies between initcalls such that one cannot
be made without the other.  I also updated the patch description.
[v3]: Andi Kleen - don't worry about free'ing the small amount of memory.
[v4]: Richard Weinberger -- add CONFIG_KALLSYMS dependency.
---
 Documentation/kernel-parameters.txt |    4 +++
 init/main.c                         |   50 +++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 67755ea..ebeb8a5 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1275,6 +1275,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
diff --git a/init/main.c b/init/main.c
index 9c7fd4c..e050c24 100644
--- a/init/main.c
+++ b/init/main.c
@@ -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>
@@ -666,6 +667,42 @@ static void __init do_ctors(void)
 bool initcall_debug;
 core_param(initcall_debug, initcall_debug, bool, 0644);
 
+struct blacklist_entry {
+	struct list_head next;
+	char *buf;
+};
+
+static __initdata_or_module LIST_HEAD(blacklisted_initcalls);
+
+#ifdef CONFIG_KALLSYMS
+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("initcall blacklisted %s \n", str_entry);
+			entry = alloc_bootmem(sizeof(*entry));
+			entry->buf = alloc_bootmem(strlen(str_entry));
+			strncpy(entry->buf, str_entry, strlen(str_entry));
+			list_add(&entry->next, &blacklisted_initcalls);
+		}
+	} while (str_entry);
+
+	return 0;
+}
+#else
+static int __init initcall_blacklist(char *str)
+{
+	pr_warning("initcall_blacklist requires CONFIG_KALLSYMS to be enabled.\n");
+	return 0;
+}
+#endif
+__setup("initcall_blacklist=", initcall_blacklist);
+
 static int __init_or_module do_one_initcall_debug(initcall_t fn)
 {
 	ktime_t calltime, delta, rettime;
@@ -689,6 +726,19 @@ int __init_or_module do_one_initcall(initcall_t fn)
 	int count = preempt_count();
 	int ret;
 	char msgbuf[64];
+	char fn_name[128] = "\0";
+	struct list_head *tmp;
+	struct blacklist_entry *entry;
+
+	snprintf(fn_name, 128, "%pf", fn);
+	list_for_each(tmp, &blacklisted_initcalls) {
+		entry = list_entry(tmp, struct blacklist_entry, next);
+		if (!strcmp(fn_name, entry->buf)) {
+			pr_debug("initcall %pf returning without executing\n",
+				 fn);
+			return -EPERM;
+		}
+	}
 
 	if (initcall_debug)
 		ret = do_one_initcall_debug(fn);
-- 
1.7.9.3


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

* Re: [PATCH] Add initcall_blacklist kernel parameter [v4]
  2014-04-01 15:19 [PATCH] Add initcall_blacklist kernel parameter [v4] Prarit Bhargava
@ 2014-04-14 21:29 ` Andrew Morton
  2014-04-14 22:40   ` Andi Kleen
  2014-04-15 15:15   ` [PATCH] Add initcall_blacklist kernel parameter [v5] Prarit Bhargava
  0 siblings, 2 replies; 6+ messages in thread
From: Andrew Morton @ 2014-04-14 21:29 UTC (permalink / raw)
  To: Prarit Bhargava
  Cc: linux-kernel, Richard Weinberger, Andi Kleen, Josh Boyer,
	Rob Landley, Steven Rostedt, Ingo Molnar, Peter Zijlstra,
	Frederic Weisbecker, linux-doc

On Tue,  1 Apr 2014 11:19:05 -0400 Prarit Bhargava <prarit@redhat.com> wrote:

> 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:
> 
> 	blacklisted initcall sgi_uv_sysfs_init
> 	...
> 	...
> 	function sgi_uv_sysfs_init returning without executing
> 
> ex) added "initcall_blacklist=foo_bar,sgi_uv_sysfs_init" as a kernel parameter
> and the log contains:
> 
> 	initcall blacklisted foo_bar
> 	initcall blacklisted sgi_uv_sysfs_init
> 	...
> 	...
> 	function sgi_uv_sysfs_init returning without executing

I guess the idea is reasonable and can be implemented very cheaply.

> --- a/Documentation/kernel-parameters.txt
> +++ b/Documentation/kernel-parameters.txt
> @@ -1275,6 +1275,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
> diff --git a/init/main.c b/init/main.c
> index 9c7fd4c..e050c24 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -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>
> @@ -666,6 +667,42 @@ static void __init do_ctors(void)
>  bool initcall_debug;
>  core_param(initcall_debug, initcall_debug, bool, 0644);
>  
> +struct blacklist_entry {
> +	struct list_head next;
> +	char *buf;
> +};
> +
> +static __initdata_or_module LIST_HEAD(blacklisted_initcalls);

I suggest this be moved inside #ifdef CONFIG_KALLSYMS, then add

#ifdef CONFIG_KALLSYMS
static bool initcall_blacklisted(const char *id)
{
	...
}
#else
static bool initcall_blacklisted(const char *id)
{
	return false;
}
#endif

than call that from do_one_initcall().

> +#ifdef CONFIG_KALLSYMS
> +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("initcall blacklisted %s \n", str_entry);
> +			entry = alloc_bootmem(sizeof(*entry));
> +			entry->buf = alloc_bootmem(strlen(str_entry));

This needs to be strlen()+1.

> +			strncpy(entry->buf, str_entry, strlen(str_entry));

and strcpy().

Or add a new strdup_bootmem() if it looks like there are (or will be)
other callers.

> +			list_add(&entry->next, &blacklisted_initcalls);
> +		}
> +	} while (str_entry);
> +
> +	return 0;
> +}
> +#else
> +static int __init initcall_blacklist(char *str)
> +{
> +	pr_warning("initcall_blacklist requires CONFIG_KALLSYMS to be enabled.\n");

"initcall_blacklist requires CONFIG_KALLSYMS" is sufficient.

> +	return 0;
> +}
> +#endif
> +__setup("initcall_blacklist=", initcall_blacklist);
> +
>  static int __init_or_module do_one_initcall_debug(initcall_t fn)
>  {
>  	ktime_t calltime, delta, rettime;
> @@ -689,6 +726,19 @@ int __init_or_module do_one_initcall(initcall_t fn)
>  	int count = preempt_count();
>  	int ret;
>  	char msgbuf[64];
> +	char fn_name[128] = "\0";
> +	struct list_head *tmp;
> +	struct blacklist_entry *entry;
> +
> +	snprintf(fn_name, 128, "%pf", fn);

Remove fn_name[], use kasprintf(), remember to free it.

> +	list_for_each(tmp, &blacklisted_initcalls) {
> +		entry = list_entry(tmp, struct blacklist_entry, next);
> +		if (!strcmp(fn_name, entry->buf)) {
> +			pr_debug("initcall %pf returning without executing\n",

"foo returning without executing" is contradictory: how can it return
if it didn't execute?  I suggest something like "skipping blacklisted
initcall %pf".

> +				 fn);
> +			return -EPERM;
> +		}
> +	}

Let's not leak all those blacklist entries when we're finished?


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

* Re: [PATCH] Add initcall_blacklist kernel parameter [v4]
  2014-04-14 21:29 ` Andrew Morton
@ 2014-04-14 22:40   ` Andi Kleen
  2014-04-15 14:08     ` Prarit Bhargava
  2014-04-15 15:15   ` [PATCH] Add initcall_blacklist kernel parameter [v5] Prarit Bhargava
  1 sibling, 1 reply; 6+ messages in thread
From: Andi Kleen @ 2014-04-14 22:40 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Prarit Bhargava, linux-kernel, Richard Weinberger, Andi Kleen,
	Josh Boyer, Rob Landley, Steven Rostedt, Ingo Molnar,
	Peter Zijlstra, Frederic Weisbecker, linux-doc

> Let's not leak all those blacklist entries when we're finished?

It's difficult, because you cannot free bootmem after bootmem is
finished.

For the rare debug case some leaking should be acceptable.

-Andi

-- 
ak@linux.intel.com -- Speaking for myself only.

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

* Re: [PATCH] Add initcall_blacklist kernel parameter [v4]
  2014-04-14 22:40   ` Andi Kleen
@ 2014-04-15 14:08     ` Prarit Bhargava
  0 siblings, 0 replies; 6+ messages in thread
From: Prarit Bhargava @ 2014-04-15 14:08 UTC (permalink / raw)
  To: Andi Kleen
  Cc: Andrew Morton, linux-kernel, Richard Weinberger, Josh Boyer,
	Rob Landley, Steven Rostedt, Ingo Molnar, Peter Zijlstra,
	Frederic Weisbecker, linux-doc



On 04/14/2014 06:40 PM, Andi Kleen wrote:
>> Let's not leak all those blacklist entries when we're finished?
> 
> It's difficult, because you cannot free bootmem after bootmem is
> finished.
> 
> For the rare debug case some leaking should be acceptable.
> 

Andrew, FWIW I agree with Andi on this.  It is a minor leak in a debug
situation.  I'd also like to know in a kdump situation what was specified as
blacklisted so keeping this memory around is IMO a good idea.

P.

> -Andi
> 

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

* [PATCH] Add initcall_blacklist kernel parameter [v5]
  2014-04-14 21:29 ` Andrew Morton
  2014-04-14 22:40   ` Andi Kleen
@ 2014-04-15 15:15   ` Prarit Bhargava
  2014-04-15 20:04     ` Andrew Morton
  1 sibling, 1 reply; 6+ messages in thread
From: Prarit Bhargava @ 2014-04-15 15:15 UTC (permalink / raw)
  To: linux-kernel
  Cc: Prarit Bhargava, Richard Weinberger, Andi Kleen, Josh Boyer,
	Rob Landley, Andrew Morton, Steven Rostedt, Ingo Molnar,
	Peter Zijlstra, Frederic Weisbecker, linux-doc

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:

	blacklisted initcall sgi_uv_sysfs_init
	...
	...
	function sgi_uv_sysfs_init returning without executing

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

	initcall blacklisted foo_bar
	initcall blacklisted sgi_uv_sysfs_init
	...
	...
	function sgi_uv_sysfs_init returning without executing

Cc: Richard Weinberger <richard.weinberger@gmail.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Josh Boyer <jwboyer@fedoraproject.org>
Cc: Rob Landley <rob@landley.net>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: linux-doc@vger.kernel.org
Signed-off-by: Prarit Bhargava <prarit@redhat.com>

[v2]: A few people recommended that I add code to allow for a list of
initcalls as there maybe dependencies between initcalls such that one cannot
be made without the other.  I also updated the patch description.
[v3]: Andi Kleen - don't worry about free'ing the small amount of memory.
[v4]: Richard Weinberger - add CONFIG_KALLSYMS dependency.
[v5]: Andrew Morton - reorganized code, minor fixes, add initcall_blacklisted(),
use kasprintf().
---
 Documentation/kernel-parameters.txt |    4 +++
 init/main.c                         |   68 +++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 03e50b4..7e1ee0c 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1294,6 +1294,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
diff --git a/init/main.c b/init/main.c
index 9c7fd4c..475ee09 100644
--- a/init/main.c
+++ b/init/main.c
@@ -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>
@@ -666,6 +667,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("initcall blacklisted %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;
@@ -690,6 +755,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
-- 
1.7.9.3


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

* Re: [PATCH] Add initcall_blacklist kernel parameter [v5]
  2014-04-15 15:15   ` [PATCH] Add initcall_blacklist kernel parameter [v5] Prarit Bhargava
@ 2014-04-15 20:04     ` Andrew Morton
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2014-04-15 20:04 UTC (permalink / raw)
  To: Prarit Bhargava
  Cc: linux-kernel, Richard Weinberger, Andi Kleen, Josh Boyer,
	Rob Landley, Steven Rostedt, Ingo Molnar, Peter Zijlstra,
	Frederic Weisbecker, linux-doc

On Tue, 15 Apr 2014 11:15:58 -0400 Prarit Bhargava <prarit@redhat.com> wrote:

> 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:
> 
> 	blacklisted initcall sgi_uv_sysfs_init

I think "blacklisting initcall sgi_uv_sysfs_init" makes more sense here.

> 	...
> 	...
> 	function sgi_uv_sysfs_init returning without executing

And this should be "blacklisted sgi_uv_sysfs_init initcall" or
"initcall sgi_uv_sysfs_init blacklisted" (isn't English weird).

I did the below and fixed up the changelog to suit:

--- a/init/main.c~init-mainc-add-initcall_blacklist-kernel-parameter-fix
+++ a/init/main.c
@@ -684,7 +684,7 @@ static int __init initcall_blacklist(cha
 	do {
 		str_entry = strsep(&str, ",");
 		if (str_entry) {
-			pr_debug("initcall blacklisted %s\n", 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);
_


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

end of thread, other threads:[~2014-04-15 20:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-01 15:19 [PATCH] Add initcall_blacklist kernel parameter [v4] Prarit Bhargava
2014-04-14 21:29 ` Andrew Morton
2014-04-14 22:40   ` Andi Kleen
2014-04-15 14:08     ` Prarit Bhargava
2014-04-15 15:15   ` [PATCH] Add initcall_blacklist kernel parameter [v5] Prarit Bhargava
2014-04-15 20:04     ` Andrew Morton

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.