1 From jbaron@redhat.com Tue Aug 12 17:09:39 2008
2 From: Jason Baron <jbaron@redhat.com>
3 Date: Tue, 12 Aug 2008 16:46:19 -0400
4 Subject: driver core: basic infrastructure for per-module dynamic debug messages
5 To: Greg KH <greg@kroah.com>
6 Cc: Randy Dunlap <randy.dunlap@oracle.com>, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, joe@perches.com, nick@nick-andrew.net
7 Message-ID: <20080812204619.GE6056@redhat.com>
10 Base infrastructure to enable per-module debug messages.
12 I've introduced CONFIG_DYNAMIC_PRINTK_DEBUG, which when enabled centralizes
13 control of debugging statements on a per-module basis in one /proc file,
14 currently, <debugfs>/dynamic_printk/modules. When, CONFIG_DYNAMIC_PRINTK_DEBUG,
15 is not set, debugging statements can still be enabled as before, often by
16 defining 'DEBUG' for the proper compilation unit. Thus, this patch set has no
17 affect when CONFIG_DYNAMIC_PRINTK_DEBUG is not set.
19 The infrastructure currently ties into all pr_debug() and dev_dbg() calls. That
20 is, if CONFIG_DYNAMIC_PRINTK_DEBUG is set, all pr_debug() and dev_dbg() calls
21 can be dynamically enabled/disabled on a per-module basis.
23 Future plans include extending this functionality to subsystems, that define
24 their own debug levels and flags.
28 Dynamic debugging is controlled by the debugfs file,
29 <debugfs>/dynamic_printk/modules. This file contains a list of the modules that
30 can be enabled. The format of the file is as follows:
32 <module_name> <enabled=0/1>
37 <module_name> : Name of the module in which the debug call resides
38 <enabled=0/1> : whether the messages are enabled or not
42 snd_hda_intel enabled=0
48 $echo "set enabled=1 <module_name>" > dynamic_printk/modules
52 $echo "set enabled=0 <module_name>" > dynamic_printk/modules
56 $echo "set enabled=1 all" > dynamic_printk/modules
60 $echo "set enabled=0 all" > dynamic_printk/modules
62 Finally, passing "dynamic_printk" at the command line enables
63 debugging for all modules. This mode can be turned off via the above
66 [gkh: minor cleanups and tweaks to make the build work quietly]
68 Signed-off-by: Jason Baron <jbaron@redhat.com>
69 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
73 Documentation/kernel-parameters.txt | 5
74 include/asm-generic/vmlinux.lds.h | 10
75 include/linux/device.h | 6
76 include/linux/dynamic_printk.h | 93 ++++++++
77 include/linux/kernel.h | 7
78 include/linux/module.h | 1
79 kernel/module.c | 31 ++
80 lib/Kconfig.debug | 55 ++++
82 lib/dynamic_printk.c | 418 ++++++++++++++++++++++++++++++++++++
83 net/netfilter/nf_conntrack_pptp.c | 2
84 scripts/Makefile.lib | 11
85 scripts/basic/Makefile | 2
86 scripts/basic/hash.c | 64 +++++
87 14 files changed, 700 insertions(+), 7 deletions(-)
89 --- a/Documentation/kernel-parameters.txt
90 +++ b/Documentation/kernel-parameters.txt
91 @@ -1742,6 +1742,11 @@ and is between 256 and 4096 characters.
93 Ranges are in pairs (memory base and size).
96 + Enables pr_debug()/dev_dbg() calls if
97 + CONFIG_DYNAMIC_PRINTK_DEBUG has been enabled. These can also
98 + be switched on/off via <debugfs>/dynamic_printk/modules
101 [KNL] debug: print fatal signals
102 print-fatal-signals=1: print segfault info to
103 --- a/include/asm-generic/vmlinux.lds.h
104 +++ b/include/asm-generic/vmlinux.lds.h
106 CPU_DISCARD(init.data) \
107 CPU_DISCARD(init.rodata) \
108 MEM_DISCARD(init.data) \
109 - MEM_DISCARD(init.rodata)
110 + MEM_DISCARD(init.rodata) \
111 + /* implement dynamic printk debug */ \
112 + VMLINUX_SYMBOL(__start___verbose_strings) = .; \
113 + *(__verbose_strings) \
114 + VMLINUX_SYMBOL(__stop___verbose_strings) = .; \
116 + VMLINUX_SYMBOL(__start___verbose) = .; \
118 + VMLINUX_SYMBOL(__stop___verbose) = .;
122 --- a/include/linux/device.h
123 +++ b/include/linux/device.h
124 @@ -553,7 +553,11 @@ int printk_dev_hash(const char *, const
125 #define dev_info(dev, format, arg...) \
126 dev_printk_hash(KERN_INFO , dev , format , ## arg)
129 +#if defined(CONFIG_DYNAMIC_PRINTK_DEBUG)
130 +#define dev_dbg(dev, format, ...) do { \
131 + dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
133 +#elif defined(DEBUG)
134 #define dev_dbg(dev, format, arg...) \
135 dev_printk(KERN_DEBUG , dev , format , ## arg)
138 +++ b/include/linux/dynamic_printk.h
140 +#ifndef _DYNAMIC_PRINTK_H
141 +#define _DYNAMIC_PRINTK_H
143 +#define DYNAMIC_DEBUG_HASH_BITS 6
144 +#define DEBUG_HASH_TABLE_SIZE (1 << DYNAMIC_DEBUG_HASH_BITS)
146 +#define TYPE_BOOLEAN 1
148 +#define DYNAMIC_ENABLED_ALL 0
149 +#define DYNAMIC_ENABLED_NONE 1
150 +#define DYNAMIC_ENABLED_SOME 2
152 +extern int dynamic_enabled;
154 +/* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which
155 + * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
156 + * use independent hash functions, to reduce the chance of false positives.
158 +extern long long dynamic_printk_enabled;
159 +extern long long dynamic_printk_enabled2;
163 + char *logical_modname;
168 +} __attribute__((aligned(8)));
170 +int register_dynamic_debug_module(char *mod_name, int type, char *share_name,
171 + char *flags, int hash, int hash2);
173 +#if defined(CONFIG_DYNAMIC_PRINTK_DEBUG)
174 +extern int unregister_dynamic_debug_module(char *mod_name);
175 +extern int __dynamic_dbg_enabled_helper(char *modname, int type,
176 + int value, int hash);
178 +#define __dynamic_dbg_enabled(module, type, value, level, hash) ({ \
180 + if (unlikely((dynamic_printk_enabled & (1LL << DEBUG_HASH)) && \
181 + (dynamic_printk_enabled2 & (1LL << DEBUG_HASH2)))) \
182 + __ret = __dynamic_dbg_enabled_helper(module, type, \
186 +#define dynamic_pr_debug(fmt, ...) do { \
187 + static char mod_name[] \
188 + __attribute__((section("__verbose_strings"))) \
189 + = KBUILD_MODNAME; \
190 + static struct mod_debug descriptor \
192 + __attribute__((section("__verbose"), aligned(8))) = \
193 + { mod_name, mod_name, NULL, TYPE_BOOLEAN, DEBUG_HASH, DEBUG_HASH2 };\
194 + if (__dynamic_dbg_enabled(KBUILD_MODNAME, TYPE_BOOLEAN, \
195 + 0, 0, DEBUG_HASH)) \
196 + printk(KERN_DEBUG KBUILD_MODNAME ":" fmt, \
200 +#define dynamic_dev_dbg(dev, format, ...) do { \
201 + static char mod_name[] \
202 + __attribute__((section("__verbose_strings"))) \
203 + = KBUILD_MODNAME; \
204 + static struct mod_debug descriptor \
206 + __attribute__((section("__verbose"), aligned(8))) = \
207 + { mod_name, mod_name, NULL, TYPE_BOOLEAN, DEBUG_HASH, DEBUG_HASH2 };\
208 + if (__dynamic_dbg_enabled(KBUILD_MODNAME, TYPE_BOOLEAN, \
209 + 0, 0, DEBUG_HASH)) \
210 + dev_printk(KERN_DEBUG, dev, \
211 + KBUILD_MODNAME ": " format, \
217 +static inline int unregister_dynamic_debug_module(const char *mod_name)
221 +static inline int __dynamic_dbg_enabled_helper(char *modname, int type,
222 + int value, int hash)
227 +#define __dynamic_dbg_enabled(module, type, value, level, hash) ({ 0; })
228 +#define dynamic_pr_debug(fmt, ...) do { } while (0)
229 +#define dynamic_dev_dbg(dev, format, ...) do { } while (0)
233 --- a/include/linux/kernel.h
234 +++ b/include/linux/kernel.h
236 #include <linux/log2.h>
237 #include <linux/typecheck.h>
238 #include <linux/ratelimit.h>
239 +#include <linux/dynamic_printk.h>
240 #include <asm/byteorder.h>
243 @@ -331,8 +332,12 @@ int printk_hash(const char *, const char
244 #define pr_info(fmt, arg...) \
245 pr_printk_hash(KERN_INFO, fmt, ##arg)
248 /* If you are writing a driver, please use dev_dbg instead */
249 +#if defined(CONFIG_DYNAMIC_PRINTK_DEBUG)
250 +#define pr_debug(fmt, ...) do { \
251 + dynamic_pr_debug(fmt, ##__VA_ARGS__); \
253 +#elif defined(DEBUG)
254 #define pr_debug(fmt, arg...) \
255 pr_printk(KERN_DEBUG, fmt, ##arg)
257 --- a/include/linux/module.h
258 +++ b/include/linux/module.h
259 @@ -345,7 +345,6 @@ struct module
260 /* Reference counts */
261 struct module_ref ref[NR_CPUS];
265 #ifndef MODULE_ARCH_INIT
266 #define MODULE_ARCH_INIT {}
267 --- a/kernel/module.c
268 +++ b/kernel/module.c
269 @@ -798,6 +798,7 @@ SYSCALL_DEFINE2(delete_module, const cha
270 mutex_lock(&module_mutex);
271 /* Store the name of the last unloaded module for diagnostic purposes */
272 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module));
273 + unregister_dynamic_debug_module(mod->name);
277 @@ -1823,6 +1824,33 @@ static inline void add_kallsyms(struct m
279 #endif /* CONFIG_KALLSYMS */
281 +#ifdef CONFIG_DYNAMIC_PRINTK_DEBUG
282 +static void dynamic_printk_setup(Elf_Shdr *sechdrs, unsigned int verboseindex)
284 + struct mod_debug *debug_info;
285 + unsigned long pos, end;
286 + unsigned int num_verbose;
288 + pos = sechdrs[verboseindex].sh_addr;
289 + num_verbose = sechdrs[verboseindex].sh_size /
290 + sizeof(struct mod_debug);
291 + end = pos + (num_verbose * sizeof(struct mod_debug));
293 + for (; pos < end; pos += sizeof(struct mod_debug)) {
294 + debug_info = (struct mod_debug *)pos;
295 + register_dynamic_debug_module(debug_info->modname,
296 + debug_info->type, debug_info->logical_modname,
297 + debug_info->flag_names, debug_info->hash,
298 + debug_info->hash2);
302 +static inline void dynamic_printk_setup(Elf_Shdr *sechdrs,
303 + unsigned int verboseindex)
306 +#endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */
308 static void *module_alloc_update_bounds(unsigned long size)
310 void *ret = module_alloc(size);
311 @@ -1871,6 +1899,7 @@ static noinline struct module *load_modu
313 unsigned int markersindex;
314 unsigned int markersstringsindex;
315 + unsigned int verboseindex;
318 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */
319 @@ -2157,6 +2186,7 @@ static noinline struct module *load_modu
320 markersindex = find_sec(hdr, sechdrs, secstrings, "__markers");
321 markersstringsindex = find_sec(hdr, sechdrs, secstrings,
322 "__markers_strings");
323 + verboseindex = find_sec(hdr, sechdrs, secstrings, "__verbose");
325 /* Now do relocations. */
326 for (i = 1; i < hdr->e_shnum; i++) {
327 @@ -2207,6 +2237,7 @@ static noinline struct module *load_modu
328 marker_update_probe_range(mod->markers,
329 mod->markers + mod->num_markers);
331 + dynamic_printk_setup(sechdrs, verboseindex);
332 err = module_finalize(hdr, sechdrs, mod);
335 --- a/lib/Kconfig.debug
336 +++ b/lib/Kconfig.debug
337 @@ -752,6 +752,61 @@ menuconfig BUILD_DOCSRC
339 Say N if you are unsure.
341 +config DYNAMIC_PRINTK_DEBUG
342 + bool "Enable dynamic printk() call support"
345 + select PRINTK_DEBUG
348 + Compiles debug level messages into the kernel, which would not
349 + otherwise be available at runtime. These messages can then be
350 + enabled/disabled on a per module basis. This mechanism implicitly
351 + enables all pr_debug() and dev_dbg() calls. The impact of this
352 + compile option is a larger kernel text size of about 2%.
356 + Dynamic debugging is controlled by the debugfs file,
357 + dynamic_printk/modules. This file contains a list of the modules that
358 + can be enabled. The format of the file is the module name, followed
359 + by a set of flags that can be enabled. The first flag is always the
360 + 'enabled' flag. For example:
362 + <module_name> <enabled=0/1>
367 + <module_name> : Name of the module in which the debug call resides
368 + <enabled=0/1> : whether the messages are enabled or not
370 + From a live system:
372 + snd_hda_intel enabled=0
378 + $echo "set enabled=1 <module_name>" > dynamic_printk/modules
382 + $echo "set enabled=0 <module_name>" > dynamic_printk/modules
384 + Enable all modules:
386 + $echo "set enabled=1 all" > dynamic_printk/modules
388 + Disable all modules:
390 + $echo "set enabled=0 all" > dynamic_printk/modules
392 + Finally, passing "dynamic_printk" at the command line enables
393 + debugging for all modules. This mode can be turned off via the above
396 source "samples/Kconfig"
398 source "lib/Kconfig.kgdb"
401 @@ -81,6 +81,8 @@ obj-$(CONFIG_HAVE_LMB) += lmb.o
403 obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o
405 +obj-$(CONFIG_DYNAMIC_PRINTK_DEBUG) += dynamic_printk.o
407 hostprogs-y := gen_crc32table
408 clean-files := crc32table.h
411 +++ b/lib/dynamic_printk.c
414 + * lib/dynamic_printk.c
416 + * make pr_debug()/dev_dbg() calls runtime configurable based upon their
417 + * their source module.
419 + * Copyright (C) 2008 Red Hat, Inc., Jason Baron <jbaron@redhat.com>
422 +#include <linux/kernel.h>
423 +#include <linux/module.h>
424 +#include <linux/uaccess.h>
425 +#include <linux/seq_file.h>
426 +#include <linux/debugfs.h>
427 +#include <linux/fs.h>
429 +extern struct mod_debug __start___verbose[];
430 +extern struct mod_debug __stop___verbose[];
433 + struct hlist_node hlist;
434 + struct hlist_node hlist2;
442 +static int nr_entries;
443 +static int num_enabled;
444 +int dynamic_enabled = DYNAMIC_ENABLED_NONE;
445 +static struct hlist_head module_table[DEBUG_HASH_TABLE_SIZE] =
446 + { [0 ... DEBUG_HASH_TABLE_SIZE-1] = HLIST_HEAD_INIT };
447 +static struct hlist_head module_table2[DEBUG_HASH_TABLE_SIZE] =
448 + { [0 ... DEBUG_HASH_TABLE_SIZE-1] = HLIST_HEAD_INIT };
449 +static DECLARE_MUTEX(debug_list_mutex);
451 +/* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which
452 + * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
453 + * use independent hash functions, to reduce the chance of false positives.
455 +long long dynamic_printk_enabled;
456 +EXPORT_SYMBOL_GPL(dynamic_printk_enabled);
457 +long long dynamic_printk_enabled2;
458 +EXPORT_SYMBOL_GPL(dynamic_printk_enabled2);
460 +/* returns the debug module pointer. */
461 +static struct debug_name *find_debug_module(char *module_name)
464 + struct hlist_head *head;
465 + struct hlist_node *node;
466 + struct debug_name *element;
469 + for (i = 0; i < DEBUG_HASH_TABLE_SIZE; i++) {
470 + head = &module_table[i];
471 + hlist_for_each_entry_rcu(element, node, head, hlist)
472 + if (!strcmp(element->name, module_name))
478 +/* returns the debug module pointer. */
479 +static struct debug_name *find_debug_module_hash(char *module_name, int hash)
481 + struct hlist_head *head;
482 + struct hlist_node *node;
483 + struct debug_name *element;
486 + head = &module_table[hash];
487 + hlist_for_each_entry_rcu(element, node, head, hlist)
488 + if (!strcmp(element->name, module_name))
493 +/* caller must hold mutex*/
494 +static int __add_debug_module(char *mod_name, int hash, int hash2)
496 + struct debug_name *new;
500 + if (find_debug_module(mod_name)) {
504 + module_name = kmalloc(strlen(mod_name) + 1, GFP_KERNEL);
505 + if (!module_name) {
509 + module_name = strcpy(module_name, mod_name);
510 + module_name[strlen(mod_name)] = '\0';
511 + new = kzalloc(sizeof(struct debug_name), GFP_KERNEL);
513 + kfree(module_name);
517 + INIT_HLIST_NODE(&new->hlist);
518 + INIT_HLIST_NODE(&new->hlist2);
519 + new->name = module_name;
521 + new->hash2 = hash2;
522 + hlist_add_head_rcu(&new->hlist, &module_table[hash]);
523 + hlist_add_head_rcu(&new->hlist2, &module_table2[hash2]);
529 +int unregister_dynamic_debug_module(char *mod_name)
531 + struct debug_name *element;
534 + down(&debug_list_mutex);
535 + element = find_debug_module(mod_name);
540 + hlist_del_rcu(&element->hlist);
541 + hlist_del_rcu(&element->hlist2);
543 + kfree(element->name);
544 + if (element->enable)
549 + up(&debug_list_mutex);
552 +EXPORT_SYMBOL_GPL(unregister_dynamic_debug_module);
554 +int register_dynamic_debug_module(char *mod_name, int type, char *share_name,
555 + char *flags, int hash, int hash2)
557 + struct debug_name *elem;
560 + down(&debug_list_mutex);
561 + elem = find_debug_module(mod_name);
563 + if (__add_debug_module(mod_name, hash, hash2))
565 + elem = find_debug_module(mod_name);
566 + if (dynamic_enabled == DYNAMIC_ENABLED_ALL &&
567 + !strcmp(mod_name, share_name)) {
568 + elem->enable = true;
572 + elem->type |= type;
574 + up(&debug_list_mutex);
577 +EXPORT_SYMBOL_GPL(register_dynamic_debug_module);
579 +int __dynamic_dbg_enabled_helper(char *mod_name, int type, int value, int hash)
581 + struct debug_name *elem;
584 + if (dynamic_enabled == DYNAMIC_ENABLED_ALL)
587 + elem = find_debug_module_hash(mod_name, hash);
588 + if (elem && elem->enable)
593 +EXPORT_SYMBOL_GPL(__dynamic_dbg_enabled_helper);
595 +static void set_all(bool enable)
597 + struct debug_name *e;
598 + struct hlist_node *node;
600 + long long enable_mask;
602 + for (i = 0; i < DEBUG_HASH_TABLE_SIZE; i++) {
603 + if (module_table[i].first != NULL) {
604 + hlist_for_each_entry(e, node, &module_table[i], hlist) {
605 + e->enable = enable;
610 + enable_mask = ULLONG_MAX;
613 + dynamic_printk_enabled = enable_mask;
614 + dynamic_printk_enabled2 = enable_mask;
617 +static int disabled_hash(int i, bool first_table)
619 + struct debug_name *e;
620 + struct hlist_node *node;
623 + hlist_for_each_entry(e, node, &module_table[i], hlist) {
628 + hlist_for_each_entry(e, node, &module_table2[i], hlist2) {
636 +static ssize_t pr_debug_write(struct file *file, const char __user *buf,
637 + size_t length, loff_t *ppos)
639 + char *buffer, *s, *value_str, *setting_str;
641 + struct debug_name *elem = NULL;
644 + if (length > PAGE_SIZE || length < 0)
647 + buffer = (char *)__get_free_page(GFP_KERNEL);
652 + if (copy_from_user(buffer, buf, length))
656 + if (length < PAGE_SIZE)
657 + buffer[length] = '\0';
658 + else if (buffer[PAGE_SIZE-1])
662 + down(&debug_list_mutex);
664 + if (strncmp("set", buffer, 3))
667 + setting_str = strsep(&s, "=");
670 + setting_str = strstrip(setting_str);
671 + value_str = strsep(&s, " ");
675 + if (!strncmp(s, "all", 3))
678 + elem = find_debug_module(s);
679 + if (!strncmp(setting_str, "enable", 6)) {
680 + value = !!simple_strtol(value_str, NULL, 10);
684 + num_enabled = nr_entries;
685 + dynamic_enabled = DYNAMIC_ENABLED_ALL;
689 + dynamic_enabled = DYNAMIC_ENABLED_NONE;
694 + if (value && (elem->enable == 0)) {
695 + dynamic_printk_enabled |=
696 + (1LL << elem->hash1);
697 + dynamic_printk_enabled2 |=
698 + (1LL << elem->hash2);
701 + dynamic_enabled = DYNAMIC_ENABLED_SOME;
704 + "debugging enabled for module %s",
706 + } else if (!value && (elem->enable == 1)) {
709 + if (disabled_hash(elem->hash1, true))
710 + dynamic_printk_enabled &=
711 + ~(1LL << elem->hash1);
712 + if (disabled_hash(elem->hash2, false))
713 + dynamic_printk_enabled2 &=
714 + ~(1LL << elem->hash2);
717 + DYNAMIC_ENABLED_SOME;
720 + DYNAMIC_ENABLED_NONE;
723 + "debugging disabled for module "
732 + up(&debug_list_mutex);
734 + free_page((unsigned long)buffer);
738 +static void *pr_debug_seq_start(struct seq_file *f, loff_t *pos)
740 + return (*pos < DEBUG_HASH_TABLE_SIZE) ? pos : NULL;
743 +static void *pr_debug_seq_next(struct seq_file *s, void *v, loff_t *pos)
746 + if (*pos >= DEBUG_HASH_TABLE_SIZE)
751 +static void pr_debug_seq_stop(struct seq_file *s, void *v)
753 + /* Nothing to do */
756 +static int pr_debug_seq_show(struct seq_file *s, void *v)
758 + struct hlist_head *head;
759 + struct hlist_node *node;
760 + struct debug_name *elem;
761 + unsigned int i = *(loff_t *) v;
764 + head = &module_table[i];
765 + hlist_for_each_entry_rcu(elem, node, head, hlist) {
766 + seq_printf(s, "%s enabled=%d", elem->name, elem->enable);
767 + seq_printf(s, "\n");
773 +static struct seq_operations pr_debug_seq_ops = {
774 + .start = pr_debug_seq_start,
775 + .next = pr_debug_seq_next,
776 + .stop = pr_debug_seq_stop,
777 + .show = pr_debug_seq_show
780 +static int pr_debug_open(struct inode *inode, struct file *filp)
782 + return seq_open(filp, &pr_debug_seq_ops);
785 +static const struct file_operations pr_debug_operations = {
786 + .open = pr_debug_open,
788 + .write = pr_debug_write,
789 + .llseek = seq_lseek,
790 + .release = seq_release,
793 +static int __init dynamic_printk_init(void)
795 + struct dentry *dir, *file;
796 + struct mod_debug *iter;
797 + unsigned long value;
799 + dir = debugfs_create_dir("dynamic_printk", NULL);
802 + file = debugfs_create_file("modules", 0644, dir, NULL,
803 + &pr_debug_operations);
805 + debugfs_remove(dir);
808 + for (value = (unsigned long)__start___verbose;
809 + value < (unsigned long)__stop___verbose;
810 + value += sizeof(struct mod_debug)) {
811 + iter = (struct mod_debug *)value;
812 + register_dynamic_debug_module(iter->modname,
814 + iter->logical_modname,
815 + iter->flag_names, iter->hash, iter->hash2);
819 +module_init(dynamic_printk_init);
820 +/* may want to move this earlier so we can get traces as early as possible */
822 +static int __init dynamic_printk_setup(char *str)
829 +/* Use early_param(), so we can get debug output as early as possible */
830 +early_param("dynamic_printk", dynamic_printk_setup);
831 --- a/net/netfilter/nf_conntrack_pptp.c
832 +++ b/net/netfilter/nf_conntrack_pptp.c
833 @@ -65,7 +65,7 @@ void
834 struct nf_conntrack_expect *exp) __read_mostly;
835 EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_expectfn);
838 +#if defined(DEBUG) || defined(CONFIG_DYNAMIC_PRINTK_DEBUG)
839 /* PptpControlMessageType names */
840 const char *const pptp_msg_name[] = {
842 --- a/scripts/Makefile.lib
843 +++ b/scripts/Makefile.lib
844 @@ -96,6 +96,14 @@ basename_flags = -D"KBUILD_BASENAME=KBUI
845 modname_flags = $(if $(filter 1,$(words $(modname))),\
846 -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
849 +ifdef CONFIG_DYNAMIC_PRINTK_DEBUG
850 +debug_flags = -D"DEBUG_HASH=$(shell ./scripts/basic/hash djb2 $(@D)$(modname))"\
851 + -D"DEBUG_HASH2=$(shell ./scripts/basic/hash r5 $(@D)$(modname))"
856 orig_c_flags = $(KBUILD_CFLAGS) $(ccflags-y) $(CFLAGS_$(basetarget).o)
857 _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
858 _a_flags = $(KBUILD_AFLAGS) $(asflags-y) $(AFLAGS_$(basetarget).o)
859 @@ -121,7 +129,8 @@ endif
861 c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) \
862 $(__c_flags) $(modkern_cflags) \
863 - -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags)
864 + -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) \
867 a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) \
868 $(__a_flags) $(modkern_aflags)
869 --- a/scripts/basic/Makefile
870 +++ b/scripts/basic/Makefile
872 # fixdep: Used to generate dependency information during build process
873 # docproc: Used in Documentation/DocBook
875 -hostprogs-y := fixdep docproc
876 +hostprogs-y := fixdep docproc hash
877 always := $(hostprogs-y)
879 # fixdep is needed to compile other host programs
881 +++ b/scripts/basic/hash.c
884 + * Copyright (C) 2008 Red Hat, Inc., Jason Baron <jbaron@redhat.com>
892 +#define DYNAMIC_DEBUG_HASH_BITS 6
894 +static const char *program;
896 +static void usage(void)
898 + printf("Usage: %s <djb2|r5> <modname>\n", program);
902 +/* djb2 hashing algorithm by Dan Bernstein. From:
903 + * http://www.cse.yorku.ca/~oz/hash.html
906 +unsigned int djb2_hash(char *str)
908 + unsigned long hash = 5381;
913 + hash = ((hash << 5) + hash) + c;
916 + return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1));
919 +unsigned int r5_hash(char *str)
921 + unsigned long hash = 0;
926 + hash = (hash + (c << 4) + (c >> 4)) * 11;
929 + return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1));
932 +int main(int argc, char *argv[])
938 + if (!strcmp(argv[1], "djb2"))
939 + printf("%d\n", djb2_hash(argv[2]));
940 + else if (!strcmp(argv[1], "r5"))
941 + printf("%d\n", r5_hash(argv[2]));