Skip to contentSkip to conversation

Dynamic Debug module.ddebug fake param enhancements

PATCH In review Thomas Renninger 4 participants 23 messages Sep 15, 2010 – Oct 6, 2010

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

This is the replacment of a patch Greg queued up recently, but it had issues.

I am not happy with some parts of the code, but it works:
Compile tested on different architectures with different .configs Tested on X86 32 and 64 bit.

Cleanups, comments, suggestions are very welcome.
I spent more time on this as expected. I can take care for minor cleanups, etc. and repost.
Jason: if it gets more, you have to take over again, sorry.

I picked out the pnp layer to show ddebug enhancements and how built-in drivers/components can make use of it.
First I thought about pci, but some parts are initialized long before dynamic debug, still similar changes might also make sense there.

Thomas

#1 lore raw

PATCH 1/4 Dynamic Debug: Introduce global fake module param module.ddebug - V3

Dynamic Debug allows enabling of pr_debug and dev_dbg messages at runtime. This is controlled via /sys/kernel/debug/dynamic_debug/control. One major drawback is that the whole initialization of a module cannot be tracked, because ddebug is only aware of debug strings of loaded modules. But this is the most interesting part...

This patch introduces a fake module parameter module.ddebug(not shown in /sys/module/*/parameters, thus it does not use any resources/memory).

If a module passes ddebug as a module parameter (e.g. via module.ddebug kernel boot param or via "modprobe module ddebug"), all debug strings of this module get activated by issuing "module module_name +p" internally (not via sysfs) when the module gets loaded.

Possible enhancements for the future if ddebug might get extended with further flags:
module.ddebug=flags
Then module.ddebug="p" would be the same as module.ddebug, but if there is a "x" ddebug flag added, one could pass:
module.ddebug="xp"
which would result in such a dynamic debug query:
module module_name +xp

Modules must not use "ddebug" as module parameter or it will get ignored. If it's tried, a warning will show up at module load time that it will get ignored (only works for not built-in modules).

Tested with (additional added pr_debug messages):
options hp-wmi ddebug
in modprobe.conf
-> works and pr_debug messages issued at module initialization time show up. Also "p" flag gets set for the whole hp-wmi module:
grep hp-wmi /sys/../dynamic_debug/control
also tested with compiled-in modules, e.g. pnp.ddebug and an additional patch later in the patch series which instruments pnp code to work with ddebug.

CC Bjorn Helgaas <[email protected]>
CC Jason Baron <[email protected]>
CC Greg KH <[email protected]>
---
 Documentation/dynamic-debug-howto.txt |   28 ++++++++++-
 include/linux/dynamic_debug.h         |   15 ++++++
 include/linux/moduleparam.h           |    3 +
 kernel/module.c                       |    1 +
 kernel/params.c                       |   13 +++++-
 lib/dynamic_debug.c                   |   86 +++++++++++++++++++++++++++++++-
 6 files changed, 141 insertions(+), 5 deletions(-)
Documentation/dynamic-debug-howto.txt +27 -1
index 58ea64a..ebbbbdd 100644
@@ -213,7 +213,7 @@ Note also that there is no convenient syntax to remove all
 the flags at once, you need to use "-psc".
 
 
-Debug messages during boot process
+Debug Messages during Boot Process
 ==================================
 
 To be able to activate debug messages during the boot process,
@@ -232,6 +232,32 @@ PCI (or other devices) initialization also is a hot candidate for using
 this boot parameter for debugging purposes.
 
 
+Debug Messages at Module Initialization Time
+============================================
+
+Enabling debug messages inside a module is only possible if the module itself
+is loaded already. If you unload a module, the dynamic debug flags associated
+to its debug messages are lost.
+Therefore, enabling debug messages that get processed at module initialization
+time through the <debugfs>/dynamic_debug/control interface is not possible.
+Instead, a "ddebug" module paramter can be passed:
+
+	- via kernel boot parameter:
+	  module.ddebug
+
+	- as an ordinary module parameter via modprobe
+	  modprobe module ddebug
+
+	- or the parameter can be used permanently via modprobe.conf(.local)
+	  options module ddebug
+
+The ddebug option is not implemented as an ordinary module parameter and thus
+will not show up in /sys/module/module_name/parameters/ddebug
+The settings can get reverted through the sysfs interface again when the
+module got loaded as soon as debug messages are not needed anymore:
+echo "module module_name -p" > <debugfs>/dynamic_debug/control
+as described in the "Command Language Reference" chapter above.
+
 Examples
 ========
 
include/linux/dynamic_debug.h +15 -0
index 52c0da4..56c0c3a 100644
@@ -39,8 +39,13 @@ struct _ddebug {
 int ddebug_add_module(struct _ddebug *tab, unsigned int n,
 				const char *modname);
 
+struct kernel_param;
+
 #if defined(CONFIG_DYNAMIC_DEBUG)
 extern int ddebug_remove_module(const char *mod_name);
+extern int ddebug_exec_query(char *query_string);
+extern void ddebug_module_parse_args(const char *name, char* args,
+				     struct kernel_param *params, unsigned num);
 
 #define __dynamic_dbg_enabled(dd)  ({	     \
 	int __ret = 0;							     \
@@ -77,6 +82,16 @@ static inline int ddebug_remove_module(const char *mod)
 {
 	return 0;
 }
+static inline int ddebug_exec_query(char *query_string)
+{
+	return 0;
+}
+static incline void ddebug_module_parse_args(const char *name, char* args,
+					     struct kernel_param *params,
+					     unsigned num)
+{
+	return 0;
+}
 
 #define dynamic_pr_debug(fmt, ...)					\
 	do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
include/linux/moduleparam.h +3 -0
index 82a9124..ab0c88c 100644
@@ -251,4 +251,7 @@ static inline void module_param_sysfs_remove(struct module *mod)
 { }
 #endif
 
+/* For being able to parse parameters the same way params.c does */
+extern char *next_arg(char *args, char **param, char **val);
+
 #endif /* _LINUX_MODULE_PARAMS_H */
kernel/module.c +1 -0
index d0b5f8d..3912e12 100644
@@ -2628,6 +2628,7 @@ static struct module *load_module(void __user *umod,
 	list_add_rcu(&mod->list, &modules);
 	mutex_unlock(&module_mutex);
 
+	ddebug_module_parse_args(mod->name, mod->args, mod->kp, mod->num_kp);
 	/* Module is ready to execute: parsing args may do that. */
 	err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL);
 	if (err < 0)
kernel/params.c +12 -1
index 0b30ecd..df06dc0 100644
@@ -54,6 +54,7 @@ static int parse_one(char *param,
 		     int (*handle_unknown)(char *param, char *val))
 {
 	unsigned int i;
+	char *tmp;
 
 	/* Find parameter */
 	for (i = 0; i < num_params; i++) {
@@ -64,6 +65,16 @@ static int parse_one(char *param,
 		}
 	}
 
+	/*
+	 * Ignore ddebug module params and module.ddebug boot params:
+	 * Documentation/dynamic-debug-howto.txt
+	 */
+	tmp = strstr(param, ".ddebug");
+	if (parameq(param, "ddebug") || (tmp && strlen(tmp) == 7)) {
+		DEBUGP("Ignoring ddebug parameter %s\n", param);
+		return 0;
+	}
+
 	if (handle_unknown) {
 		DEBUGP("Unknown argument: calling %p\n", handle_unknown);
 		return handle_unknown(param, val);
@@ -75,7 +86,7 @@ static int parse_one(char *param,
 
 /* You can use " around spaces, but can't escape ". */
 /* Hyphens and underscores equivalent in parameter names. */
-static char *next_arg(char *args, char **param, char **val)
+char *next_arg(char *args, char **param, char **val)
 {
 	unsigned int i, equals = 0;
 	int in_quote = 0, quoted = 0;
lib/dynamic_debug.c +83 -3

133 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#2 lore raw

Re: [PATCH 1/4] Dynamic Debug: Introduce global fake module param module.ddebug - V3

Quoted 340 lines · Thomas Renninger

Dynamic Debug allows enabling of pr_debug and dev_dbg messages at runtime. This is controlled via /sys/kernel/debug/dynamic_debug/control. One major drawback is that the whole initialization of a module cannot be tracked, because ddebug is only aware of debug strings of loaded modules. But this is the most interesting part...

This patch introduces a fake module parameter module.ddebug(not shown in /sys/module/*/parameters, thus it does not use any resources/memory).

If a module passes ddebug as a module parameter (e.g. via module.ddebug kernel boot param or via "modprobe module ddebug"), all debug strings of this module get activated by issuing "module module_name +p" internally (not via sysfs) when the module gets loaded.

Possible enhancements for the future if ddebug might get extended with further flags:
module.ddebug=flags
Then module.ddebug="p" would be the same as module.ddebug, but if there is a "x" ddebug flag added, one could pass:
module.ddebug="xp"
which would result in such a dynamic debug query:
module module_name +xp

Modules must not use "ddebug" as module parameter or it will get ignored. If it's tried, a warning will show up at module load time that it will get ignored (only works for not built-in modules).

Tested with (additional added pr_debug messages):
options hp-wmi ddebug
in modprobe.conf
-> works and pr_debug messages issued at module initialization time show up. Also "p" flag gets set for the whole hp-wmi module:
grep hp-wmi /sys/../dynamic_debug/control
also tested with compiled-in modules, e.g. pnp.ddebug and an additional patch later in the patch series which instruments pnp code to work with ddebug.

CC Bjorn Helgaas <[email protected]>
CC Jason Baron <[email protected]>
CC Greg KH <[email protected]>
---
 Documentation/dynamic-debug-howto.txt |   28 ++++++++++-
 include/linux/dynamic_debug.h         |   15 ++++++
 include/linux/moduleparam.h           |    3 +
 kernel/module.c                       |    1 +
 kernel/params.c                       |   13 +++++-
 lib/dynamic_debug.c                   |   86 +++++++++++++++++++++++++++++++-
 6 files changed, 141 insertions(+), 5 deletions(-)
Documentation/dynamic-debug-howto.txt +27 -1
index 58ea64a..ebbbbdd 100644
@@ -213,7 +213,7 @@ Note also that there is no convenient syntax to remove all
 the flags at once, you need to use "-psc".
 
 
-Debug messages during boot process
+Debug Messages during Boot Process
 ==================================
 
 To be able to activate debug messages during the boot process,
@@ -232,6 +232,32 @@ PCI (or other devices) initialization also is a hot candidate for using
 this boot parameter for debugging purposes.
 
 
+Debug Messages at Module Initialization Time
+============================================
+
+Enabling debug messages inside a module is only possible if the module itself
+is loaded already. If you unload a module, the dynamic debug flags associated
+to its debug messages are lost.
+Therefore, enabling debug messages that get processed at module initialization
+time through the <debugfs>/dynamic_debug/control interface is not possible.
+Instead, a "ddebug" module paramter can be passed:
+
+	- via kernel boot parameter:
+	  module.ddebug
+
+	- as an ordinary module parameter via modprobe
+	  modprobe module ddebug
+
+	- or the parameter can be used permanently via modprobe.conf(.local)
+	  options module ddebug
+
+The ddebug option is not implemented as an ordinary module parameter and thus
+will not show up in /sys/module/module_name/parameters/ddebug
+The settings can get reverted through the sysfs interface again when the
+module got loaded as soon as debug messages are not needed anymore:
+echo "module module_name -p" > <debugfs>/dynamic_debug/control
+as described in the "Command Language Reference" chapter above.
+
 Examples
 ========
 
include/linux/dynamic_debug.h +15 -0
index 52c0da4..56c0c3a 100644
@@ -39,8 +39,13 @@ struct _ddebug {
 int ddebug_add_module(struct _ddebug *tab, unsigned int n,
 				const char *modname);
 
+struct kernel_param;
+
 #if defined(CONFIG_DYNAMIC_DEBUG)
 extern int ddebug_remove_module(const char *mod_name);
+extern int ddebug_exec_query(char *query_string);
+extern void ddebug_module_parse_args(const char *name, char* args,
+				     struct kernel_param *params, unsigned num);
 
 #define __dynamic_dbg_enabled(dd)  ({	     \
 	int __ret = 0;							     \
@@ -77,6 +82,16 @@ static inline int ddebug_remove_module(const char *mod)
 {
 	return 0;
 }
+static inline int ddebug_exec_query(char *query_string)
+{
+	return 0;
+}
+static incline void ddebug_module_parse_args(const char *name, char* args,
+					     struct kernel_param *params,
+					     unsigned num)
+{
+	return 0;
+}
 
 #define dynamic_pr_debug(fmt, ...)					\
 	do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
include/linux/moduleparam.h +3 -0
index 82a9124..ab0c88c 100644
@@ -251,4 +251,7 @@ static inline void module_param_sysfs_remove(struct module *mod)
 { }
 #endif
 
+/* For being able to parse parameters the same way params.c does */
+extern char *next_arg(char *args, char **param, char **val);
+
 #endif /* _LINUX_MODULE_PARAMS_H */
kernel/module.c +1 -0
index d0b5f8d..3912e12 100644
@@ -2628,6 +2628,7 @@ static struct module *load_module(void __user *umod,
 	list_add_rcu(&mod->list, &modules);
 	mutex_unlock(&module_mutex);
 
+	ddebug_module_parse_args(mod->name, mod->args, mod->kp, mod->num_kp);
 	/* Module is ready to execute: parsing args may do that. */
 	err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL);
 	if (err < 0)
kernel/params.c +12 -1
index 0b30ecd..df06dc0 100644
@@ -54,6 +54,7 @@ static int parse_one(char *param,
 		     int (*handle_unknown)(char *param, char *val))
 {
 	unsigned int i;
+	char *tmp;
 
 	/* Find parameter */
 	for (i = 0; i < num_params; i++) {
@@ -64,6 +65,16 @@ static int parse_one(char *param,
 		}
 	}
 
+	/*
+	 * Ignore ddebug module params and module.ddebug boot params:
+	 * Documentation/dynamic-debug-howto.txt
+	 */
+	tmp = strstr(param, ".ddebug");
+	if (parameq(param, "ddebug") || (tmp && strlen(tmp) == 7)) {
+		DEBUGP("Ignoring ddebug parameter %s\n", param);
+		return 0;
+	}
+
 	if (handle_unknown) {
 		DEBUGP("Unknown argument: calling %p\n", handle_unknown);
 		return handle_unknown(param, val);
@@ -75,7 +86,7 @@ static int parse_one(char *param,
 
 /* You can use " around spaces, but can't escape ". */
 /* Hyphens and underscores equivalent in parameter names. */
-static char *next_arg(char *args, char **param, char **val)
+char *next_arg(char *args, char **param, char **val)
 {
 	unsigned int i, equals = 0;
 	int in_quote = 0, quoted = 0;
lib/dynamic_debug.c +83 -3
index a687d90..826ea2e 100644
@@ -10,6 +10,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/init.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kallsyms.h>
@@ -27,9 +28,13 @@
 #include <linux/debugfs.h>
 #include <linux/slab.h>
 
+#include <asm/setup.h>
+
 extern struct _ddebug __start___verbose[];
 extern struct _ddebug __stop___verbose[];
 
+#define DDEBUG_STRING_SIZE 1024
+
 /* dynamic_debug_enabled, and dynamic_debug_enabled2 are bitmasks in which
  * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
  * use independent hash functions, to reduce the chance of false positives.
@@ -429,7 +434,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
 	return 0;
 }
 
-static int ddebug_exec_query(char *query_string)
+int ddebug_exec_query(char *query_string)
 {
 	unsigned int flags = 0, mask = 0;
 	struct ddebug_query query;
@@ -437,6 +442,9 @@ static int ddebug_exec_query(char *query_string)
 	int nwords;
 	char *words[MAXWORDS];
 
+	if (verbose)
+		printk(KERN_INFO "%s: got query: %s\n", __func__, query_string);
+
 	nwords = ddebug_tokenize(query_string, words, MAXWORDS);
 	if (nwords <= 0)
 		return -EINVAL;
@@ -450,10 +458,10 @@ static int ddebug_exec_query(char *query_string)
 	return 0;
 }
 
-static __initdata char ddebug_setup_string[1024];
+static __initdata char ddebug_setup_string[DDEBUG_STRING_SIZE];
 static __init int ddebug_setup_query(char *str)
 {
-	if (strlen(str) >= 1024) {
+	if (strlen(str) >= DDEBUG_STRING_SIZE) {
 		pr_warning("ddebug boot param string too large\n");
 		return 0;
 	}
@@ -704,6 +712,76 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
 }
 EXPORT_SYMBOL_GPL(ddebug_add_module);
 
+/* We search for *ddebug* module params */
+void ddebug_module_parse_args(const char *name, char* args,
+			      struct kernel_param *params, unsigned num)
+{
+	char ddebug[DDEBUG_STRING_SIZE], *param, *val, *args_it, *arg_dup_ptr;
+	int i;
+
+	/*
+	 * We must not modify the passed args string and need to store the
+	 * kstrdup pointer to be able to free memory later, TBD: find a way
+	 * to do this nicer
+	 */
+	arg_dup_ptr = args_it = kstrdup(args, GFP_KERNEL);
+
+	if (verbose)
+		printk(KERN_INFO "%s: Parsing ARGS: -%s- of %s\n",
+		       __func__, args_it, name);
+
+	for (i = 0; i < num; i++) {
+		if (!strcmp("ddebug", params[i].name))
+			pr_warning("Module %s uses reserved keyword "
+				   "*ddebug* as parameter\n", name);
+	}
+
+	/* Chew leading spaces */
+	args_it = skip_spaces(args_it);
+
+	while (*args_it) {
+		args_it = next_arg(args_it, &param, &val);
+		if (verbose)
+			printk(KERN_INFO "%s: Param: %s, val: %s\n",
+			       __func__, param, val);
+		if (!strcmp(param, "ddebug")) {
+			pr_info("Enabling debugging for module %s\n", name);
+			snprintf(ddebug, DDEBUG_STRING_SIZE, "module %s +p",
+				 name);
+			ddebug_exec_query(ddebug);
+		}
+	}
+	kfree(arg_dup_ptr);
+	if (verbose)
+		printk(KERN_INFO "%s: Finished %s parsing\n",  __func__, name);
+}
+/* We search for module.ddebug kernel boot params */
+static void ddebug_boot_parse_args(void)
+{
+	char tmp_cmd_arr[COMMAND_LINE_SIZE], *tmp_cmd_ptr, *param, *val, *tmp;
+	char module[MODULE_NAME_LEN], ddebug[DDEBUG_STRING_SIZE];
+
+	/* next_arg touches the passed buffer and chops each argument */
+	strlcpy(tmp_cmd_arr, saved_command_line, COMMAND_LINE_SIZE);
+	/* Chew leading spaces */
+	tmp_cmd_ptr = skip_spaces(tmp_cmd_arr);
+
+	while (*tmp_cmd_ptr) {
+		tmp_cmd_ptr = next_arg(tmp_cmd_ptr, &param, &val);
+		if (verbose)
+			printk(KERN_INFO "%s: Param: %s, val: %s\n",
+			       __func__, param, val);
+		tmp = strstr(param, ".ddebug");
+		if (tmp && strlen(tmp) == 7) {
+			strlcpy(module, param, tmp - param + 1);
+			pr_info("Enabling debugging for module %s\n", module);
+			snprintf(ddebug, DDEBUG_STRING_SIZE, "module %s +p",
+				 module);
+			ddebug_exec_query(ddebug);
+		}
+	}
+}
+
 static void ddebug_table_free(struct ddebug_table *dt)
 {
 	list_del_init(&dt->link);
@@ -805,6 +883,8 @@ static int __init dynamic_debug_init(void)
 				ddebug_setup_string);
 	}
 
+	ddebug_boot_parse_args();
+
 out_free:
 	if (ret)
 		ddebug_remove_all_tables();
Signature · 1 line
1.6.0.2

Hi,

So i'm wondering if need to support the module.ddebug on the command line? The ddebug_query="module foo +p" format that you introduced does the same thing.

Also, we can't put those large char[] arrays on the kernel stack. They probably should be global.

thanks,

-Jason

#3 lore raw

Re: [PATCH 1/4] Dynamic Debug: Introduce global fake module param module.ddebug - V3

Quoted 4 lines

Hi,

So i'm wondering if need to support the module.ddebug on the command line?

Yep, that would make things a bit easier...
People would e.g. have to use ddebug_query="module pnp +p" (which already is available with the patch that is queued in linux-next) instead of pnp.ddebug. Not that obvious or say user friendly, though.

Quoted 2 lines

The ddebug_query="module foo +p" format that you introduced does the same thing.

No that does not work for real (not built-in) modules. Give it a try... The stuff needs to be set up when the module is loaded.
If you have a real module declared as =m
You need to call "module foo +p" when the module gets/got loaded. But ddebug_query="..." only gets executed once, when
dynamic debug gets set up, far before any module got loaded.

Quoted 2 lines

Also, we can't put those large char[] arrays on the kernel stack. They probably should be global.

Where exactly, the command line(*args)?

Thomas

#4 lore raw

Re: [PATCH 1/4] Dynamic Debug: Introduce global fake module param module.ddebug - V3

Quoted 9 lines · Thomas Renninger
Quoted 4 lines

Hi,

So i'm wondering if need to support the module.ddebug on the command line?

Yep, that would make things a bit easier...
People would e.g. have to use ddebug_query="module pnp +p" (which already is available with the patch that is queued in linux-next) instead of pnp.ddebug. Not that obvious or say user friendly, though.

Quoted 9 lines
Quoted 2 lines

The ddebug_query="module foo +p" format that you introduced does the same thing.

No that does not work for real (not built-in) modules. Give it a try... The stuff needs to be set up when the module is loaded.
If you have a real module declared as =m
You need to call "module foo +p" when the module gets/got loaded. But ddebug_query="..." only gets executed once, when
dynamic debug gets set up, far before any module got loaded.

ok, to be consistent, if passing 'ddebug' as a module parameter when a module loads, we also need for module.ddebug to work, as that is how other module parameters work.

Quoted 4 lines
Quoted 2 lines

Also, we can't put those large char[] arrays on the kernel stack. They probably should be global.

Where exactly, the command line(*args)?

The character arrays, that put COMMAND_LINE_SIZE and DDEBUG_STRING_SIZE on the stack are too large. Also, ddebug_boot_parse_args() should be marked as '__init' since it only used on boot.

thanks,

-Jason

#5 lore raw

Re: [PATCH 1/4] Dynamic Debug: Introduce global fake module param module.ddebug - V3

Quoted 25 lines · Jason Baron
Quoted 13 lines · Thomas Renninger
Quoted 4 lines

Hi,

So i'm wondering if need to support the module.ddebug on the command line?

Yep, that would make things a bit easier...
People would e.g. have to use ddebug_query="module pnp +p" (which already is available with the patch that is queued in linux-next) instead of pnp.ddebug. Not that obvious or say user friendly, though.

Quoted 2 lines

The ddebug_query="module foo +p" format that you introduced does the same thing.

Quoted 6 lines

No that does not work for real (not built-in) modules. Give it a try... The stuff needs to be set up when the module is loaded.
If you have a real module declared as =m
You need to call "module foo +p" when the module gets/got loaded. But ddebug_query="..." only gets executed once, when
dynamic debug gets set up, far before any module got loaded.

ok, to be consistent, if passing 'ddebug' as a module parameter when a module loads, we also need for module.ddebug to work, as that is how other module parameters work.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Also, we can't put those large char[] arrays on the kernel stack. They probably should be global.

Where exactly, the command line(*args)?

The character arrays, that put COMMAND_LINE_SIZE

I dynamically malloc (kstrdup) the command line now.

Quoted 1 line

and DDEBUG_STRING_SIZE

I reuse an __initdata var I already have for that.

Quoted 2 lines

on the stack are too large. Also, ddebug_boot_parse_args() should be marked as '__init' since it only used on boot.

Yep.

I'll repost all 4 patches:
- The first is the ddebug fake parameter.
- 2x pnp compile in one namespace
- minor compile fixups if DEBUGP is defined in kernel/modules.c

Thanks,

Thomas

#6 lore raw

Dynamic Debug module.ddebug fake param enhancements V4

In reply to Jason Baron

The patches are intended for Greg's tree and depend on 3 other dynamic debug patches which already are in linux-next, but not in the vanilla kernel yet.

[PATCH 1/4] Dynamic Debug: Introduce global fake module param module.ddebug - V4

     V3 -> V4: Do not put that large arrays on the stack, make one func __init

[PATCH 2/4] PNP: Compile all pnp built-in stuff in one module namespace
[PATCH 3/4] PNP: Use dev_dbg instead of dev_printk(KERN_DEBUG.. if DYNAMIC_DEBUG is compiled in
-> Compile PNP subsystem in a separate pnp module namespace

[PATCH 4/4] kernel/module.c: Fix compiler warnings if debug is compiled in
-> minor compile fixup

Only the two PNP patches really belong together.
If someone e.g. complains about the PNP patches, please still submit the rest.

Thanks,

Thomas

#7 lore raw

Re: Dynamic Debug module.ddebug fake param enhancements V4

Quoted 11 lines · Thomas Renninger

The patches are intended for Greg's tree and depend on 3 other dynamic debug patches which already are in linux-next, but not in the vanilla kernel yet.

[PATCH 1/4] Dynamic Debug: Introduce global fake module param module.ddebug - V4

     V3 -> V4: Do not put that large arrays on the stack, make one func __init

[PATCH 2/4] PNP: Compile all pnp built-in stuff in one module namespace
[PATCH 3/4] PNP: Use dev_dbg instead of dev_printk(KERN_DEBUG.. if DYNAMIC_DEBUG is compiled in
-> Compile PNP subsystem in a separate pnp module namespace

Quoted 5 lines

[PATCH 4/4] kernel/module.c: Fix compiler warnings if debug is compiled in
-> minor compile fixup

Only the two PNP patches really belong together.
If someone e.g. complains about the PNP patches, please still submit the rest.

I confess that I don't understand the objective here (only because I haven't taken enough time to read and understand the patches).

Some examples of how you expect to use this would probably help me understand. And if you can compare that with the current, more difficult way, that would be even better.

I don't know if it's relevant, but I plan to change some of the pnp_dbg() uses to dev_printk(KERN_DEBUG). Specifically, mainline already logs all PCI device BARs with KERN_DEBUG, so that information is always in dmesg. PNP currently uses pnp_dbg() for the corresponding ACPI device resource usage, so to get that information, I often have to request another boot with CONFIG_PNP_DEBUG_MESSAGES=y and "pnp.debug". I want to convert those resource messages to dev_printk(KERN_DEBUG) so they're just always in dmesg.

Bjorn

#8 lore raw

Re: Dynamic Debug module.ddebug fake param enhancements V4

Quoted 18 lines · On Friday 24 September 2010 16:56:16 Bjorn Helgaas wrote:
Quoted 11 lines · Thomas Renninger

The patches are intended for Greg's tree and depend on 3 other dynamic debug patches which already are in linux-next, but not in the vanilla kernel yet.

[PATCH 1/4] Dynamic Debug: Introduce global fake module param module.ddebug - V4

     V3 -> V4: Do not put that large arrays on the stack, make one func __init

[PATCH 2/4] PNP: Compile all pnp built-in stuff in one module namespace
[PATCH 3/4] PNP: Use dev_dbg instead of dev_printk(KERN_DEBUG.. if DYNAMIC_DEBUG is compiled in
-> Compile PNP subsystem in a separate pnp module namespace

Quoted 5 lines

[PATCH 4/4] kernel/module.c: Fix compiler warnings if debug is compiled in
-> minor compile fixup

Only the two PNP patches really belong together.
If someone e.g. complains about the PNP patches, please still submit the rest.

Quoted 6 lines

I confess that I don't understand the objective here (only because I haven't taken enough time to read and understand the patches).

Some examples of how you expect to use this would probably help me understand. And if you can compare that with the current, more difficult way, that would be even better.

Yep:
Currently you do have to compile in PNP_DEBUG (or similar) to get some interesting resource debug messages.

Quoted 3 lines

I don't know if it's relevant, but I plan to change some of the pnp_dbg() uses to dev_printk(KERN_DEBUG).

That would mess up dynamic debug with these messages.
Both, dev_dbg and dev_printk(KERN_DEBUG..) has advantages and disadvantages. Below some background about dev_dbg combined with CONFIG_DYNAMIC_DEBUG.

Quoted 5 lines

Specifically, mainline
already logs all PCI device BARs with KERN_DEBUG, so that information is always in dmesg. PNP currently uses pnp_dbg() for the corresponding ACPI device resource usage, so to get that information, I often have to request another boot with CONFIG_PNP_DEBUG_MESSAGES=y and "pnp.debug".

Yep, the idea is that this is not necessary anymore.
But dynamic debug has an advantage compared to printk(KERN_DEBUG.. You can explicitly define which module or even which file you want to enable the debug messages (with this patch(es) the whole pnp
code would be compiled into one built-in module namespace).
E.g. pnp.ddebug boot param would enable all dev_dbg and pr_debug messages in:
driver/pnp/* -r

One disadvantage: this doesn't really work with (all) pci code, because some of the PCI initialization is a way too early for ddebug (e.g. early quirks).

Quoted 2 lines

I want to convert those resource messages to dev_printk(KERN_DEBUG) so they're just always in dmesg.

I hit the same, e.g. with pnp and driver/acpi/ec.c, there are some dev_dbg in there... with dynamic debug you can enable ec.c debug messages by:
acpi.ddebug
(because nearly all in drivers/acpi/* -r is compiled into a global acpi module namespace, I got the idea for pnp- Makefile prefix from there). Or you can even specify the file:
ddebug_query="file drivers/acpi/ec.c +p"
or
ddebug_query="file ec.c +p" (afaik works as well)
all other dev_dbg and pr_debug messages stay hidden.

SLE11-SP1 already has DYNAMIC_DEBUG enabled
More info:
Documentation/dynamic-debug-howto.txt

If you take a kernel from here:
ftp://ftp.suse.com/pub/projects/kernel/kotd/master
I added my patches there for some testing now.
There the additional boot params query_ddebug="" and module.ddebug are described in the source package, in:
Documentation/dynamic-debug-howto.txt
You can simply run a:
pnp.ddebug
to see quite some pnp output without CONFIG_PNP_DEBUG_MESSAGES defined.

What do you think (dev_dbg vs printk(KERN_DEBUG...)?

Thomas

#9 lore raw

Re: Dynamic Debug module.ddebug fake param enhancements V4

Quoted 1 line · Thomas Renninger

What do you think (dev_dbg vs printk(KERN_DEBUG...)?

Well, 99% of the time, what I want is simply the resource usage of all the devices in the system. Currently, a dmesg log gives me that for PCI devices. I plan to change PNP so the dmesg log will also contain that for PNP devices. That's simple and requires no user action at all and no extra boots.

The times when we need more extensive debugging are rare enough that I'm not sure it's worth keeping them compiled into the kernel, even if they are turned off by default (I understand the tradeoff from a distro point of view might be different).

With the exception of the ones in pnp/resource.c that I want to convert to dev_printk(KERN_DEBUG), I think all the pnp_dbg() uses are things I used during PNP development and haven't ever needed since.

Bjorn

#10 lore raw

Re: Dynamic Debug module.ddebug fake param enhancements V4

Greg: Do you mind pushing the first (1/4, V4) and the last (4/4) patch into your tree for linux-next and leave the two PNP patches out, please.

More PNP related discussion, below.

Quoted 3 lines · On Monday 27 September 2010 17:09:18 Bjorn Helgaas wrote:
Quoted 1 line · Thomas Renninger

What do you think (dev_dbg vs printk(KERN_DEBUG...)?

...

Quoted 3 lines

With the exception of the ones in pnp/resource.c that I want to convert to dev_printk(KERN_DEBUG), I think all the pnp_dbg() uses are things I used during PNP development and haven't ever needed since.

Ok. Sounds sane.
I used the PNP parts as it nicely showed what the module.ddebug boot param is doing, but I agree it hasn't much advantage for PNP.

Whatabout compiling pnp in one module namespace, the first of the two PNP patches?
I do not see an urgent need/advantage, it would just be a general cleanup.
PNP could then make use of moduleparam.h interface instead of using __setup(..).

E.g. attached patch would be an on top patch which provides no functional change, just that a pnp.debug would be a module param:
cat /sys/module/pnp/parameters/debug

Again there is not much use for this with pnp as all should be processed at boot time. But theoretically one could enable pnp.debug at runtime :) (or it should get hidden with 0000 perms if not needed). It's more a general cleanup, further pnp boot params can be pnp.xy module params then.

Bjoern: If you like them I can repost these two:
(PNP build in one module namespace and below)

Thomas

---------
PNP: Set up pnp_debug via module and not via boot param.

Cleanup only, no functional change (pnp.debug can be enabled and disabled at runtime, but that's not a real enhancement).

This one depends on another PNP cleanup patch:
PNP: Compile all pnp built-in stuff in one module namespace

drivers/pnp/core.c +1 -6
index 88b3cde..9801918 100644
@@ -218,10 +218,5 @@ subsys_initcall(pnp_init);
 int pnp_debug;
 
 #if defined(CONFIG_PNP_DEBUG_MESSAGES)
-static int __init pnp_debug_setup(char *__unused)
-{
-	pnp_debug = 1;
-	return 1;
-}
-__setup("pnp.debug", pnp_debug_setup);
+module_param_named(debug, pnp_debug, int, 0644);
 #endif
#11 lore raw

Re: Dynamic Debug module.ddebug fake param enhancements V4

Quoted 15 lines · Thomas Renninger

Greg: Do you mind pushing the first (1/4, V4) and the last (4/4) patch into your tree for linux-next and leave the two PNP patches out, please.

More PNP related discussion, below.

Quoted 3 lines · On Monday 27 September 2010 17:09:18 Bjorn Helgaas wrote:
Quoted 1 line · Thomas Renninger

What do you think (dev_dbg vs printk(KERN_DEBUG...)?

...

Quoted 3 lines

With the exception of the ones in pnp/resource.c that I want to convert to dev_printk(KERN_DEBUG), I think all the pnp_dbg() uses are things I used during PNP development and haven't ever needed since.

Quoted 7 lines

Ok. Sounds sane.
I used the PNP parts as it nicely showed what the module.ddebug boot param is doing, but I agree it hasn't much advantage for PNP.

Whatabout compiling pnp in one module namespace, the first of the two PNP patches?

[2/4] looks reasonable to me.

Quoted 3 lines

E.g. attached patch would be an on top patch which provides no functional change, just that a pnp.debug would be a module param:
cat /sys/module/pnp/parameters/debug

As does the one below.

Quoted 28 lines

---------
PNP: Set up pnp_debug via module and not via boot param.

Cleanup only, no functional change (pnp.debug can be enabled and disabled at runtime, but that's not a real enhancement).

This one depends on another PNP cleanup patch:
PNP: Compile all pnp built-in stuff in one module namespace

drivers/pnp/core.c +1 -6
index 88b3cde..9801918 100644
@@ -218,10 +218,5 @@ subsys_initcall(pnp_init);
 int pnp_debug;
 
 #if defined(CONFIG_PNP_DEBUG_MESSAGES)
-static int __init pnp_debug_setup(char *__unused)
-{
-	pnp_debug = 1;
-	return 1;
-}
-__setup("pnp.debug", pnp_debug_setup);
+module_param_named(debug, pnp_debug, int, 0644);
 #endif
#12 lore raw

Re: Dynamic Debug module.ddebug fake param enhancements V4

Quoted 4 lines · Bjorn Helgaas
Quoted 3 lines · Thomas Renninger

Greg: Do you mind pushing the first (1/4, V4) and the last (4/4) patch into your tree for linux-next and leave the two PNP patches out, please.

I've applied them now.

Quoted 16 lines
Quoted 16 lines

More PNP related discussion, below.

Quoted 3 lines · On Monday 27 September 2010 17:09:18 Bjorn Helgaas wrote:
Quoted 1 line · Thomas Renninger

What do you think (dev_dbg vs printk(KERN_DEBUG...)?

...

Quoted 3 lines

With the exception of the ones in pnp/resource.c that I want to convert to dev_printk(KERN_DEBUG), I think all the pnp_dbg() uses are things I used during PNP development and haven't ever needed since.

Ok. Sounds sane.
I used the PNP parts as it nicely showed what the module.ddebug boot param is doing, but I agree it hasn't much advantage for PNP.

Quoted 4 lines
Quoted 2 lines

Whatabout compiling pnp in one module namespace, the first of the two PNP patches?

[2/4] looks reasonable to me.

And this one.

Quoted 6 lines
Quoted 4 lines

E.g. attached patch would be an on top patch which provides no functional change, just that a pnp.debug would be a module param:
cat /sys/module/pnp/parameters/debug

As does the one below.

And this one.

So that left 3/4 out of the series applied to my tree.

If this is incorrect, please let me know.

thanks,

greg k-h

#13 lore raw

PATCH 1/4 Dynamic Debug: Introduce global fake module param module.ddebug - V4

In reply to Jason Baron

Dynamic Debug allows enabling of pr_debug and dev_dbg messages at runtime. This is controlled via /sys/kernel/debug/dynamic_debug/control. One major drawback is that the whole initialization of a module cannot be tracked, because ddebug is only aware of debug strings of loaded modules. But this is the most interesting part...

This patch introduces a fake module parameter module.ddebug(not shown in /sys/module/*/parameters, thus it does not use any resources/memory).

If a module passes ddebug as a module parameter (e.g. via module.ddebug kernel boot param or via "modprobe module ddebug"), all debug strings of this module get activated by issuing "module module_name +p" internally (not via sysfs) when the module gets loaded.

Possible enhancements for the future if ddebug might get extended with further flags:
module.ddebug=flags
Then module.ddebug="p" would be the same as module.ddebug, but if there is a "x" ddebug flag added, one could pass:
module.ddebug="xp"
which would result in such a dynamic debug query:
module module_name +xp

Modules must not use "ddebug" as module parameter or it will get ignored. If it's tried, a warning will show up at module load time that it will get ignored (only works for not built-in modules).

Tested with (additional added pr_debug messages):
options hp-wmi ddebug
in modprobe.conf
-> works and pr_debug messages issued at module initialization time show up. Also "p" flag gets set for the whole hp-wmi module:
grep hp-wmi /sys/../dynamic_debug/control
also tested with compiled-in modules, e.g. pnp.ddebug and an additional patch later in the patch series which instruments pnp code to work with ddebug.

CC Bjorn Helgaas <[email protected]>
CC Jason Baron <[email protected]>
CC Greg KH <[email protected]>
---
 Documentation/dynamic-debug-howto.txt |   28 ++++++++++-
 include/linux/dynamic_debug.h         |   15 ++++++
 include/linux/moduleparam.h           |    3 +
 kernel/module.c                       |    1 +
 kernel/params.c                       |   13 +++++-
 lib/dynamic_debug.c                   |   89 +++++++++++++++++++++++++++++++-
 6 files changed, 144 insertions(+), 5 deletions(-)
Documentation/dynamic-debug-howto.txt +27 -1
index 58ea64a..ebbbbdd 100644
@@ -213,7 +213,7 @@ Note also that there is no convenient syntax to remove all
 the flags at once, you need to use "-psc".
 
 
-Debug messages during boot process
+Debug Messages during Boot Process
 ==================================
 
 To be able to activate debug messages during the boot process,
@@ -232,6 +232,32 @@ PCI (or other devices) initialization also is a hot candidate for using
 this boot parameter for debugging purposes.
 
 
+Debug Messages at Module Initialization Time
+============================================
+
+Enabling debug messages inside a module is only possible if the module itself
+is loaded already. If you unload a module, the dynamic debug flags associated
+to its debug messages are lost.
+Therefore, enabling debug messages that get processed at module initialization
+time through the <debugfs>/dynamic_debug/control interface is not possible.
+Instead, a "ddebug" module paramter can be passed:
+
+	- via kernel boot parameter:
+	  module.ddebug
+
+	- as an ordinary module parameter via modprobe
+	  modprobe module ddebug
+
+	- or the parameter can be used permanently via modprobe.conf(.local)
+	  options module ddebug
+
+The ddebug option is not implemented as an ordinary module parameter and thus
+will not show up in /sys/module/module_name/parameters/ddebug
+The settings can get reverted through the sysfs interface again when the
+module got loaded as soon as debug messages are not needed anymore:
+echo "module module_name -p" > <debugfs>/dynamic_debug/control
+as described in the "Command Language Reference" chapter above.
+
 Examples
 ========
 
include/linux/dynamic_debug.h +15 -0
index 52c0da4..56c0c3a 100644
@@ -39,8 +39,13 @@ struct _ddebug {
 int ddebug_add_module(struct _ddebug *tab, unsigned int n,
 				const char *modname);
 
+struct kernel_param;
+
 #if defined(CONFIG_DYNAMIC_DEBUG)
 extern int ddebug_remove_module(const char *mod_name);
+extern int ddebug_exec_query(char *query_string);
+extern void ddebug_module_parse_args(const char *name, char* args,
+				     struct kernel_param *params, unsigned num);
 
 #define __dynamic_dbg_enabled(dd)  ({	     \
 	int __ret = 0;							     \
@@ -77,6 +82,16 @@ static inline int ddebug_remove_module(const char *mod)
 {
 	return 0;
 }
+static inline int ddebug_exec_query(char *query_string)
+{
+	return 0;
+}
+static incline void ddebug_module_parse_args(const char *name, char* args,
+					     struct kernel_param *params,
+					     unsigned num)
+{
+	return 0;
+}
 
 #define dynamic_pr_debug(fmt, ...)					\
 	do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
include/linux/moduleparam.h +3 -0
index 9d2f183..5cec3cc 100644
@@ -405,4 +405,7 @@ static inline void module_param_sysfs_remove(struct module *mod)
 { }
 #endif
 
+/* For being able to parse parameters the same way params.c does */
+extern char *next_arg(char *args, char **param, char **val);
+
 #endif /* _LINUX_MODULE_PARAMS_H */
kernel/module.c +1 -0
index d0b5f8d..3912e12 100644
@@ -2628,6 +2628,7 @@ static struct module *load_module(void __user *umod,
 	list_add_rcu(&mod->list, &modules);
 	mutex_unlock(&module_mutex);
 
+	ddebug_module_parse_args(mod->name, mod->args, mod->kp, mod->num_kp);
 	/* Module is ready to execute: parsing args may do that. */
 	err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL);
 	if (err < 0)
kernel/params.c +12 -1
index 08107d1..44950c3 100644
@@ -107,6 +107,16 @@ static int parse_one(char *param,
 		}
 	}
 
+	/*
+	 * Ignore ddebug module params and module.ddebug boot params:
+	 * Documentation/dynamic-debug-howto.txt
+	 */
+	tmp = strstr(param, ".ddebug");
+	if (parameq(param, "ddebug") || (tmp && strlen(tmp) == 7)) {
+		DEBUGP("Ignoring ddebug parameter %s\n", param);
+		return 0;
+	}
+
 	if (handle_unknown) {
 		DEBUGP("Unknown argument: calling %p\n", handle_unknown);
 		return handle_unknown(param, val);
@@ -118,7 +128,7 @@ static int parse_one(char *param,
 
 /* You can use " around spaces, but can't escape ". */
 /* Hyphens and underscores equivalent in parameter names. */
-static char *next_arg(char *args, char **param, char **val)
+char *next_arg(char *args, char **param, char **val)
 {
 	unsigned int i, equals = 0;
 	int in_quote = 0, quoted = 0;
@@ -713,6 +723,7 @@ void module_param_sysfs_remove(struct module *mod)
 void destroy_params(const struct kernel_param *params, unsigned num)
 {
 	unsigned int i;
+	char *tmp;
 
 	for (i = 0; i < num; i++)
 		if (params[i].ops->free)
lib/dynamic_debug.c +86 -3

136 lines not on this page · raw message

Signature · 1 line
1.6.4.2
#14 lore raw

Re: [PATCH 1/4] Dynamic Debug: Introduce global fake module param module.ddebug - V4

Quoted 27 lines · Thomas Renninger

Dynamic Debug allows enabling of pr_debug and dev_dbg messages at runtime. This is controlled via /sys/kernel/debug/dynamic_debug/control. One major drawback is that the whole initialization of a module cannot be tracked, because ddebug is only aware of debug strings of loaded modules. But this is the most interesting part...

This patch introduces a fake module parameter module.ddebug(not shown in /sys/module/*/parameters, thus it does not use any resources/memory).

If a module passes ddebug as a module parameter (e.g. via module.ddebug kernel boot param or via "modprobe module ddebug"), all debug strings of this module get activated by issuing "module module_name +p" internally (not via sysfs) when the module gets loaded.

Possible enhancements for the future if ddebug might get extended with further flags:
module.ddebug=flags
Then module.ddebug="p" would be the same as module.ddebug, but if there is a "x" ddebug flag added, one could pass:
module.ddebug="xp"
which would result in such a dynamic debug query:
module module_name +xp

Modules must not use "ddebug" as module parameter or it will get ignored. If it's tried, a warning will show up at module load time that it will get ignored (only works for not built-in modules).

Quoted 8 lines

Tested with (additional added pr_debug messages):
options hp-wmi ddebug
in modprobe.conf
-> works and pr_debug messages issued at module initialization time show up. Also "p" flag gets set for the whole hp-wmi module:
grep hp-wmi /sys/../dynamic_debug/control
also tested with compiled-in modules, e.g. pnp.ddebug and an additional patch later in the patch series which instruments pnp code to work with ddebug.

I don't think you actually built this patch, as it dies:
kernel/params.c: In function ‘parse_one’:
kernel/params.c:114:2: error: ‘tmp’ undeclared (first use in this function) kernel/params.c:114:2: note: each undeclared identifier is reported only once for each function it appears in kernel/params.c: In function ‘destroy_params’:
kernel/params.c:726:8: warning: unused variable ‘tmp’

I've dropped all 4 from my queue now, care to resend when they work properly?

thanks,

greg k-h

#15 lore raw

Re: [PATCH 1/4] Dynamic Debug: Introduce global fake module param module.ddebug - V4

Quoted 38 lines · Greg KH
Quoted 27 lines · Thomas Renninger

Dynamic Debug allows enabling of pr_debug and dev_dbg messages at runtime. This is controlled via /sys/kernel/debug/dynamic_debug/control. One major drawback is that the whole initialization of a module cannot be tracked, because ddebug is only aware of debug strings of loaded modules. But this is the most interesting part...

This patch introduces a fake module parameter module.ddebug(not shown in /sys/module/*/parameters, thus it does not use any resources/memory).

If a module passes ddebug as a module parameter (e.g. via module.ddebug kernel boot param or via "modprobe module ddebug"), all debug strings of this module get activated by issuing "module module_name +p" internally (not via sysfs) when the module gets loaded.

Possible enhancements for the future if ddebug might get extended with further flags:
module.ddebug=flags
Then module.ddebug="p" would be the same as module.ddebug, but if there is a "x" ddebug flag added, one could pass:
module.ddebug="xp"
which would result in such a dynamic debug query:
module module_name +xp

Modules must not use "ddebug" as module parameter or it will get ignored. If it's tried, a warning will show up at module load time that it will get ignored (only works for not built-in modules).

Quoted 9 lines

Tested with (additional added pr_debug messages):
options hp-wmi ddebug
in modprobe.conf
-> works and pr_debug messages issued at module initialization time show up. Also "p" flag gets set for the whole hp-wmi module:
grep hp-wmi /sys/../dynamic_debug/control
also tested with compiled-in modules, e.g. pnp.ddebug and an additional patch later in the patch series which instruments pnp code to work with ddebug.

Quoted 7 lines

I don't think you actually built this patch, as it dies:
kernel/params.c: In function ‘parse_one’:
kernel/params.c:114:2: error: ‘tmp’ undeclared (first use in this function) kernel/params.c:114:2: note: each undeclared identifier is reported only once for each function it appears in kernel/params.c: In function ‘destroy_params’:
kernel/params.c:726:8: warning: unused variable ‘tmp’

Strange, I added them to the latest SUSE factory kernel already and I didn't do much more than copying (and slightly adjusting?).

Can you give me a pointer to your git tree and branch you want the patches based on, iirc I based them on latest Linus master branch.

Sorry and thanks,

Thomas

#16 lore raw

Re: [PATCH 1/4] Dynamic Debug: Introduce global fake module param module.ddebug - V4

Quoted 46 lines · Thomas Renninger
Quoted 38 lines · Greg KH
Quoted 27 lines · Thomas Renninger

Dynamic Debug allows enabling of pr_debug and dev_dbg messages at runtime. This is controlled via /sys/kernel/debug/dynamic_debug/control. One major drawback is that the whole initialization of a module cannot be tracked, because ddebug is only aware of debug strings of loaded modules. But this is the most interesting part...

This patch introduces a fake module parameter module.ddebug(not shown in /sys/module/*/parameters, thus it does not use any resources/memory).

If a module passes ddebug as a module parameter (e.g. via module.ddebug kernel boot param or via "modprobe module ddebug"), all debug strings of this module get activated by issuing "module module_name +p" internally (not via sysfs) when the module gets loaded.

Possible enhancements for the future if ddebug might get extended with further flags:
module.ddebug=flags
Then module.ddebug="p" would be the same as module.ddebug, but if there is a "x" ddebug flag added, one could pass:
module.ddebug="xp"
which would result in such a dynamic debug query:
module module_name +xp

Modules must not use "ddebug" as module parameter or it will get ignored. If it's tried, a warning will show up at module load time that it will get ignored (only works for not built-in modules).

Quoted 9 lines

Tested with (additional added pr_debug messages):
options hp-wmi ddebug
in modprobe.conf
-> works and pr_debug messages issued at module initialization time show up. Also "p" flag gets set for the whole hp-wmi module:
grep hp-wmi /sys/../dynamic_debug/control
also tested with compiled-in modules, e.g. pnp.ddebug and an additional patch later in the patch series which instruments pnp code to work with ddebug.

Quoted 7 lines

I don't think you actually built this patch, as it dies:
kernel/params.c: In function ‘parse_one’:
kernel/params.c:114:2: error: ‘tmp’ undeclared (first use in this function) kernel/params.c:114:2: note: each undeclared identifier is reported only once for each function it appears in kernel/params.c: In function ‘destroy_params’:
kernel/params.c:726:8: warning: unused variable ‘tmp’

Quoted 5 lines

Strange, I added them to the latest SUSE factory kernel already and I didn't do much more than copying (and slightly adjusting?).

Can you give me a pointer to your git tree and branch you want the patches based on, iirc I based them on latest Linus master branch.

Try them on top of linux-next, which has my patches in it.

Or use my quilt tree, which is on kernel.org (and in the MAINTAINERS file.)

thanks,

greg k-h

#17 lore raw

PATCH 2/4 PNP: Compile all pnp built-in stuff in one module namespace

In reply to Jason Baron

before, dynamic debug info (/sys/kernel/debug/dynamic_debug/control) showed the file name as module name of each dynamic debug message (in square brackets):
drivers/pnp/core.c:198 [core]pnp_add_device p "%s device, IDs%s (%s)\012" drivers/pnp/resource.c:619 [resource]pnp_add_bus_resource p " add %pr\012" ..
drivers/pnp/pnpacpi/core.c:89 [core]pnpacpi_set_resources p "set resources\012" ..

With this patch the module name will be pnp for all "drivers/pnp/* -r" code:
drivers/pnp/core.c:198 [pnp]pnp_add_device p "%s device, IDs%s (%s)\012" drivers/pnp/resource.c:619 [pnp]pnp_add_bus_resource p " add %pr\012"
..
drivers/pnp/pnpacpi/core.c:112 [pnp]pnpacpi_disable_resources p "disable resources\012"

This has advantages:
- Any pnp code can make use of the moduleparam.h interface, the modules will show up as pnp.param.
- Passing pnp.ddebug as kernel boot param will enable all pnp debug messages with my previous patch and CONFIG_DYNAMIC_DEBUG enabled.

CC Bjorn Helgaas <[email protected]>
CC Jason Baron <[email protected]>
CC Greg KH <[email protected]>
---
 drivers/pnp/Makefile         |    6 ++++--
 drivers/pnp/isapnp/Makefile  |    6 +++---
 drivers/pnp/pnpacpi/Makefile |    3 ++-
 drivers/pnp/pnpbios/Makefile |    5 +++--
 4 files changed, 12 insertions(+), 8 deletions(-)
drivers/pnp/Makefile +4 -2
index 8de3775..bfba893 100644
@@ -2,11 +2,13 @@
 # Makefile for the Linux Plug-and-Play Support.
 #
 
-obj-y		:= core.o card.o driver.o resource.o manager.o support.o interface.o quirks.o
+obj-y		:= pnp.o
+
+pnp-y		:= core.o card.o driver.o resource.o manager.o support.o interface.o quirks.o
 
 obj-$(CONFIG_PNPACPI)		+= pnpacpi/
 obj-$(CONFIG_PNPBIOS)		+= pnpbios/
 obj-$(CONFIG_ISAPNP)		+= isapnp/
 
 # pnp_system_init goes after pnpacpi/pnpbios init
-obj-y				+= system.o
+pnp-y				+= system.o
drivers/pnp/isapnp/Makefile +3 -3
index cac18bb..6e607aa 100644
@@ -1,7 +1,7 @@
 #
 # Makefile for the kernel ISAPNP driver.
 #
+obj-y			+= pnp.o
+pnp-y			:= core.o compat.o
 
-isapnp-proc-$(CONFIG_PROC_FS) = proc.o
-
-obj-y := core.o compat.o $(isapnp-proc-y)
+pnp-$(CONFIG_PROC_FS)	+= proc.o
drivers/pnp/pnpacpi/Makefile +2 -1
index 905326f..40c93da 100644
@@ -1,5 +1,6 @@
 #
 # Makefile for the kernel PNPACPI driver.
 #
+obj-y += pnp.o
 
-obj-y := core.o rsparser.o
+pnp-y := core.o rsparser.o
drivers/pnp/pnpbios/Makefile +3 -2
index 3cd3ed7..240b0ff 100644
@@ -1,7 +1,8 @@
 #
 # Makefile for the kernel PNPBIOS driver.
 #
+obj-y := pnp.o
 
-pnpbios-proc-$(CONFIG_PNPBIOS_PROC_FS) = proc.o
+pnp-y := core.o bioscalls.o rsparser.o
 
-obj-y := core.o bioscalls.o rsparser.o $(pnpbios-proc-y)
+pnp-$(CONFIG_PNPBIOS_PROC_FS) += proc.o
Signature · 1 line
1.6.4.2
#18 lore raw

PATCH 3/4 PNP: Use dev_dbg instead of dev_printk(KERN_DEBUG.. if DYNAMIC_DEBUG is compiled in

In reply to Jason Baron

This allows usage of generic pnp.ddebug debug parameter instead of pnp.debug PNP specific parameter.

I wonder whether CONFIG_PNP_DEBUG_MESSAGES can vanish totally with this or at some time. Only advantage having it is:
If you are restricted and your kernel must not exceed X bytes, you cannot compile in PNP debug messages only, but you have to compile in all debug messages.

CC Bjorn Helgaas <[email protected]>
CC Jason Baron <[email protected]>
CC Greg KH <[email protected]>
---
 drivers/pnp/base.h |    8 ++++++--
 drivers/pnp/core.c |   16 +++++++++++++++-
 2 files changed, 21 insertions(+), 3 deletions(-)
drivers/pnp/base.h +6 -2
index 0bab84e..1f7f9bd 100644
@@ -170,12 +170,16 @@ struct pnp_resource *pnp_add_bus_resource(struct pnp_dev *dev,
 					  resource_size_t start,
 					  resource_size_t end);
 
-extern int pnp_debug;
-
+#if defined(CONFIG_DYNAMIC_DEBUG)
+#define pnp_dbg(dev, format, arg...)					\
+	({ dev_dbg(dev, format, ## arg); 0; })
+#else
 #if defined(CONFIG_PNP_DEBUG_MESSAGES)
+extern int pnp_debug;
 #define pnp_dbg(dev, format, arg...)					\
 	({ if (pnp_debug) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })
 #else
 #define pnp_dbg(dev, format, arg...)					\
 	({ if (0) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })
 #endif
+#endif
drivers/pnp/core.c +15 -1
index 88b3cde..fe834ac 100644
@@ -215,9 +215,21 @@ static int __init pnp_init(void)
 
 subsys_initcall(pnp_init);
 
-int pnp_debug;
+#if defined(CONFIG_DYNAMIC_DEBUG)
+static int __init pnp_debug_setup(char *__unused)
+{
+	printk(KERN_INFO "DYNAMIC_DEBUG enabled use pnp.ddebug instead of "
+	       "pnp.debug boot param\n");
+	return 1;
+}
+__setup("pnp.debug", pnp_debug_setup);
+
+#else
 
 #if defined(CONFIG_PNP_DEBUG_MESSAGES)
+
+int pnp_debug;
+
 static int __init pnp_debug_setup(char *__unused)
 {
 	pnp_debug = 1;
@@ -225,3 +237,5 @@ static int __init pnp_debug_setup(char *__unused)
 }
 __setup("pnp.debug", pnp_debug_setup);
 #endif
+
+#endif
Signature · 1 line
1.6.4.2
#19 lore raw

PATCH 4/4 kernel/module.c: Fix compiler warnings if debug is compiled in

In reply to Jason Baron

Fixes these warnings:
kernel/module.c: In function ‘layout_sections’:
kernel/module.c:1776: error: ‘name’ undeclared (first use in this function) kernel/module.c:1776: error: (Each undeclared identifier is reported only once kernel/module.c:1776: error: for each function it appears in.) kernel/module.c: In function ‘move_module’:
kernel/module.c:2394: warning: format ‘%lx’ expects type ‘long unsigned int’, but argument 2 has type ‘Elf64_Addr’

if DEBUGP is defined in kernel/module.c

---
 kernel/module.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
kernel/module.c +2 -3
index 3912e12..66e4361 100644
@@ -1773,7 +1773,6 @@ static void layout_sections(struct module *mod, struct load_info *info)
 			    || strstarts(sname, ".init"))
 				continue;
 			s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
-			DEBUGP("\t%s\n", name);
 		}
 		if (m == 0)
 			mod->core_text_size = mod->core_size;
@@ -2390,8 +2389,8 @@ static int move_module(struct module *mod, struct load_info *info)
 			memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
 		/* Update sh_addr to point to copy in image. */
 		shdr->sh_addr = (unsigned long)dest;
-		DEBUGP("\t0x%lx %s\n",
-		       shdr->sh_addr, info->secstrings + shdr->sh_name);
+		DEBUGP("\t0x%p %s\n",
+		       (void *)shdr->sh_addr, info->secstrings + shdr->sh_name);
 	}
 
 	return 0;
Signature · 1 line
1.6.4.2
#20 lore raw

PATCH 2/4 PNP: Compile all pnp built-in stuff in one module namespace

In reply to Thomas Renninger

before, dynamic debug info (/sys/kernel/debug/dynamic_debug/control) showed the file name as module name of each dynamic debug message (in square brackets):
drivers/pnp/core.c:198 [core]pnp_add_device p "%s device, IDs%s (%s)\012" drivers/pnp/resource.c:619 [resource]pnp_add_bus_resource p " add %pr\012" ..
drivers/pnp/pnpacpi/core.c:89 [core]pnpacpi_set_resources p "set resources\012" ..

With this patch the module name will be pnp for all "drivers/pnp/* -r" code:
drivers/pnp/core.c:198 [pnp]pnp_add_device p "%s device, IDs%s (%s)\012" drivers/pnp/resource.c:619 [pnp]pnp_add_bus_resource p " add %pr\012"
..
drivers/pnp/pnpacpi/core.c:112 [pnp]pnpacpi_disable_resources p "disable resources\012"

This has advantages:
- Any pnp code can make use of the moduleparam.h interface, the modules will show up as pnp.param.
- Passing pnp.ddebug as kernel boot param will enable all pnp debug messages with my previous patch and CONFIG_DYNAMIC_DEBUG enabled.

CC Bjorn Helgaas <[email protected]>
CC Jason Baron <[email protected]>
CC Greg KH <[email protected]>
---
 drivers/pnp/Makefile         |    6 ++++--
 drivers/pnp/isapnp/Makefile  |    6 +++---
 drivers/pnp/pnpacpi/Makefile |    3 ++-
 drivers/pnp/pnpbios/Makefile |    5 +++--
 4 files changed, 12 insertions(+), 8 deletions(-)
drivers/pnp/Makefile +4 -2
index 8de3775..bfba893 100644
@@ -2,11 +2,13 @@
 # Makefile for the Linux Plug-and-Play Support.
 #
 
-obj-y		:= core.o card.o driver.o resource.o manager.o support.o interface.o quirks.o
+obj-y		:= pnp.o
+
+pnp-y		:= core.o card.o driver.o resource.o manager.o support.o interface.o quirks.o
 
 obj-$(CONFIG_PNPACPI)		+= pnpacpi/
 obj-$(CONFIG_PNPBIOS)		+= pnpbios/
 obj-$(CONFIG_ISAPNP)		+= isapnp/
 
 # pnp_system_init goes after pnpacpi/pnpbios init
-obj-y				+= system.o
+pnp-y				+= system.o
drivers/pnp/isapnp/Makefile +3 -3
index cac18bb..6e607aa 100644
@@ -1,7 +1,7 @@
 #
 # Makefile for the kernel ISAPNP driver.
 #
+obj-y			+= pnp.o
+pnp-y			:= core.o compat.o
 
-isapnp-proc-$(CONFIG_PROC_FS) = proc.o
-
-obj-y := core.o compat.o $(isapnp-proc-y)
+pnp-$(CONFIG_PROC_FS)	+= proc.o
drivers/pnp/pnpacpi/Makefile +2 -1
index 905326f..40c93da 100644
@@ -1,5 +1,6 @@
 #
 # Makefile for the kernel PNPACPI driver.
 #
+obj-y += pnp.o
 
-obj-y := core.o rsparser.o
+pnp-y := core.o rsparser.o
drivers/pnp/pnpbios/Makefile +3 -2
index 3cd3ed7..240b0ff 100644
@@ -1,7 +1,8 @@
 #
 # Makefile for the kernel PNPBIOS driver.
 #
+obj-y := pnp.o
 
-pnpbios-proc-$(CONFIG_PNPBIOS_PROC_FS) = proc.o
+pnp-y := core.o bioscalls.o rsparser.o
 
-obj-y := core.o bioscalls.o rsparser.o $(pnpbios-proc-y)
+pnp-$(CONFIG_PNPBIOS_PROC_FS) += proc.o
Signature · 1 line
1.6.0.2
#21 lore raw

PATCH 3/4 PNP: Use dev_dbg instead of dev_printk(KERN_DEBUG.. if DYNAMIC_DEBUG is compiled in

In reply to Thomas Renninger

This allows usage of generic pnp.ddebug debug parameter instead of pnp.debug PNP specific parameter.

I wonder whether CONFIG_PNP_DEBUG_MESSAGES can vanish totally with this or at some time. Only advantage having it is:
If you are restricted and your kernel must not exceed X bytes, you cannot compile in PNP debug messages only, but you have to compile in all debug messages.

CC Bjorn Helgaas <[email protected]>
CC Jason Baron <[email protected]>
CC Greg KH <[email protected]>
---
 drivers/pnp/base.h |    8 ++++++--
 drivers/pnp/core.c |   16 +++++++++++++++-
 2 files changed, 21 insertions(+), 3 deletions(-)
drivers/pnp/base.h +6 -2
index 0bab84e..1f7f9bd 100644
@@ -170,12 +170,16 @@ struct pnp_resource *pnp_add_bus_resource(struct pnp_dev *dev,
 					  resource_size_t start,
 					  resource_size_t end);
 
-extern int pnp_debug;
-
+#if defined(CONFIG_DYNAMIC_DEBUG)
+#define pnp_dbg(dev, format, arg...)					\
+	({ dev_dbg(dev, format, ## arg); 0; })
+#else
 #if defined(CONFIG_PNP_DEBUG_MESSAGES)
+extern int pnp_debug;
 #define pnp_dbg(dev, format, arg...)					\
 	({ if (pnp_debug) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })
 #else
 #define pnp_dbg(dev, format, arg...)					\
 	({ if (0) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })
 #endif
+#endif
drivers/pnp/core.c +15 -1
index 88b3cde..fe834ac 100644
@@ -215,9 +215,21 @@ static int __init pnp_init(void)
 
 subsys_initcall(pnp_init);
 
-int pnp_debug;
+#if defined(CONFIG_DYNAMIC_DEBUG)
+static int __init pnp_debug_setup(char *__unused)
+{
+	printk(KERN_INFO "DYNAMIC_DEBUG enabled use pnp.ddebug instead of "
+	       "pnp.debug boot param\n");
+	return 1;
+}
+__setup("pnp.debug", pnp_debug_setup);
+
+#else
 
 #if defined(CONFIG_PNP_DEBUG_MESSAGES)
+
+int pnp_debug;
+
 static int __init pnp_debug_setup(char *__unused)
 {
 	pnp_debug = 1;
@@ -225,3 +237,5 @@ static int __init pnp_debug_setup(char *__unused)
 }
 __setup("pnp.debug", pnp_debug_setup);
 #endif
+
+#endif
Signature · 1 line
1.6.0.2
#22 lore raw

PATCH 4/4 kernel/module.c: Fix compiler warnings if debug is compiled in

In reply to Thomas Renninger

Fixes these warnings:
kernel/module.c: In function ‘layout_sections’:
kernel/module.c:1776: error: ‘name’ undeclared (first use in this function) kernel/module.c:1776: error: (Each undeclared identifier is reported only once kernel/module.c:1776: error: for each function it appears in.) kernel/module.c: In function ‘move_module’:
kernel/module.c:2394: warning: format ‘%lx’ expects type ‘long unsigned int’, but argument 2 has type ‘Elf64_Addr’

if DEBUGP is defined in kernel/module.c

---
 kernel/module.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
kernel/module.c +2 -3
index 3912e12..66e4361 100644
@@ -1773,7 +1773,6 @@ static void layout_sections(struct module *mod, struct load_info *info)
 			    || strstarts(sname, ".init"))
 				continue;
 			s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
-			DEBUGP("\t%s\n", name);
 		}
 		if (m == 0)
 			mod->core_text_size = mod->core_size;
@@ -2390,8 +2389,8 @@ static int move_module(struct module *mod, struct load_info *info)
 			memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
 		/* Update sh_addr to point to copy in image. */
 		shdr->sh_addr = (unsigned long)dest;
-		DEBUGP("\t0x%lx %s\n",
-		       shdr->sh_addr, info->secstrings + shdr->sh_name);
+		DEBUGP("\t0x%p %s\n",
+		       (void *)shdr->sh_addr, info->secstrings + shdr->sh_name);
 	}
 
 	return 0;
Signature · 1 line
1.6.0.2