]> git.ipfire.org Git - ipfire-2.x.git/blame - src/patches/suse-2.6.27.31/patches.drivers/driver-core-basic-infrastructure-for-per-module-dynamic-debug-messages.patch
Add a patch to fix Intel E100 wake-on-lan problems.
[ipfire-2.x.git] / src / patches / suse-2.6.27.31 / patches.drivers / driver-core-basic-infrastructure-for-per-module-dynamic-debug-messages.patch
CommitLineData
2cb7cef9
BS
1From jbaron@redhat.com Tue Aug 12 17:09:39 2008
2From: Jason Baron <jbaron@redhat.com>
3Date: Tue, 12 Aug 2008 16:46:19 -0400
4Subject: driver core: basic infrastructure for per-module dynamic debug messages
5To: Greg KH <greg@kroah.com>
6Cc: Randy Dunlap <randy.dunlap@oracle.com>, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, joe@perches.com, nick@nick-andrew.net
7Message-ID: <20080812204619.GE6056@redhat.com>
8Patch-mainline: 2.6.28
9
10Base infrastructure to enable per-module debug messages.
11
12I've introduced CONFIG_DYNAMIC_PRINTK_DEBUG, which when enabled centralizes
13control of debugging statements on a per-module basis in one /proc file,
14currently, <debugfs>/dynamic_printk/modules. When, CONFIG_DYNAMIC_PRINTK_DEBUG,
15is not set, debugging statements can still be enabled as before, often by
16defining 'DEBUG' for the proper compilation unit. Thus, this patch set has no
17affect when CONFIG_DYNAMIC_PRINTK_DEBUG is not set.
18
19The infrastructure currently ties into all pr_debug() and dev_dbg() calls. That
20is, if CONFIG_DYNAMIC_PRINTK_DEBUG is set, all pr_debug() and dev_dbg() calls
21can be dynamically enabled/disabled on a per-module basis.
22
23Future plans include extending this functionality to subsystems, that define
24their own debug levels and flags.
25
26Usage:
27
28Dynamic debugging is controlled by the debugfs file,
29<debugfs>/dynamic_printk/modules. This file contains a list of the modules that
30can be enabled. The format of the file is as follows:
31
32 <module_name> <enabled=0/1>
33 .
34 .
35 .
36
37 <module_name> : Name of the module in which the debug call resides
38 <enabled=0/1> : whether the messages are enabled or not
39
40For example:
41
42 snd_hda_intel enabled=0
43 fixup enabled=1
44 driver enabled=0
45
46Enable a module:
47
48 $echo "set enabled=1 <module_name>" > dynamic_printk/modules
49
50Disable a module:
51
52 $echo "set enabled=0 <module_name>" > dynamic_printk/modules
53
54Enable all modules:
55
56 $echo "set enabled=1 all" > dynamic_printk/modules
57
58Disable all modules:
59
60 $echo "set enabled=0 all" > dynamic_printk/modules
61
62Finally, passing "dynamic_printk" at the command line enables
63debugging for all modules. This mode can be turned off via the above
64disable command.
65
66[gkh: minor cleanups and tweaks to make the build work quietly]
67
68Signed-off-by: Jason Baron <jbaron@redhat.com>
69Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
70
71
72---
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 ++++
81 lib/Makefile | 2
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(-)
88
89--- a/Documentation/kernel-parameters.txt
90+++ b/Documentation/kernel-parameters.txt
91@@ -1742,6 +1742,11 @@ and is between 256 and 4096 characters.
92 autoconfiguration.
93 Ranges are in pairs (memory base and size).
94
95+ dynamic_printk
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
99+
100 print-fatal-signals=
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
105@@ -268,7 +268,15 @@
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) = .; \
115+ . = ALIGN(8); \
116+ VMLINUX_SYMBOL(__start___verbose) = .; \
117+ *(__verbose) \
118+ VMLINUX_SYMBOL(__stop___verbose) = .;
119
120 #define INIT_TEXT \
121 *(.init.text) \
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)
127
128-#ifdef DEBUG
129+#if defined(CONFIG_DYNAMIC_PRINTK_DEBUG)
130+#define dev_dbg(dev, format, ...) do { \
131+ dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
132+ } while (0)
133+#elif defined(DEBUG)
134 #define dev_dbg(dev, format, arg...) \
135 dev_printk(KERN_DEBUG , dev , format , ## arg)
136 #else
137--- /dev/null
138+++ b/include/linux/dynamic_printk.h
139@@ -0,0 +1,93 @@
140+#ifndef _DYNAMIC_PRINTK_H
141+#define _DYNAMIC_PRINTK_H
142+
143+#define DYNAMIC_DEBUG_HASH_BITS 6
144+#define DEBUG_HASH_TABLE_SIZE (1 << DYNAMIC_DEBUG_HASH_BITS)
145+
146+#define TYPE_BOOLEAN 1
147+
148+#define DYNAMIC_ENABLED_ALL 0
149+#define DYNAMIC_ENABLED_NONE 1
150+#define DYNAMIC_ENABLED_SOME 2
151+
152+extern int dynamic_enabled;
153+
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.
157+ */
158+extern long long dynamic_printk_enabled;
159+extern long long dynamic_printk_enabled2;
160+
161+struct mod_debug {
162+ char *modname;
163+ char *logical_modname;
164+ char *flag_names;
165+ int type;
166+ int hash;
167+ int hash2;
168+} __attribute__((aligned(8)));
169+
170+int register_dynamic_debug_module(char *mod_name, int type, char *share_name,
171+ char *flags, int hash, int hash2);
172+
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);
177+
178+#define __dynamic_dbg_enabled(module, type, value, level, hash) ({ \
179+ int __ret = 0; \
180+ if (unlikely((dynamic_printk_enabled & (1LL << DEBUG_HASH)) && \
181+ (dynamic_printk_enabled2 & (1LL << DEBUG_HASH2)))) \
182+ __ret = __dynamic_dbg_enabled_helper(module, type, \
183+ value, hash);\
184+ __ret; })
185+
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 \
191+ __used \
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, \
197+ ##__VA_ARGS__); \
198+ } while (0)
199+
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 \
205+ __used \
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, \
212+ ##__VA_ARGS__); \
213+ } while (0)
214+
215+#else
216+
217+static inline int unregister_dynamic_debug_module(const char *mod_name)
218+{
219+ return 0;
220+}
221+static inline int __dynamic_dbg_enabled_helper(char *modname, int type,
222+ int value, int hash)
223+{
224+ return 0;
225+}
226+
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)
230+#endif
231+
232+#endif
233--- a/include/linux/kernel.h
234+++ b/include/linux/kernel.h
235@@ -16,6 +16,7 @@
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>
241 #include <asm/bug.h>
242
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)
246
247-#ifdef DEBUG
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__); \
252+ } while (0)
253+#elif defined(DEBUG)
254 #define pr_debug(fmt, arg...) \
255 pr_printk(KERN_DEBUG, fmt, ##arg)
256 #else
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];
262 #endif
263-
264 };
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);
274 free_module(mod);
275
276 out:
277@@ -1823,6 +1824,33 @@ static inline void add_kallsyms(struct m
278 }
279 #endif /* CONFIG_KALLSYMS */
280
281+#ifdef CONFIG_DYNAMIC_PRINTK_DEBUG
282+static void dynamic_printk_setup(Elf_Shdr *sechdrs, unsigned int verboseindex)
283+{
284+ struct mod_debug *debug_info;
285+ unsigned long pos, end;
286+ unsigned int num_verbose;
287+
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));
292+
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);
299+ }
300+}
301+#else
302+static inline void dynamic_printk_setup(Elf_Shdr *sechdrs,
303+ unsigned int verboseindex)
304+{
305+}
306+#endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */
307+
308 static void *module_alloc_update_bounds(unsigned long size)
309 {
310 void *ret = module_alloc(size);
311@@ -1871,6 +1899,7 @@ static noinline struct module *load_modu
312 #endif
313 unsigned int markersindex;
314 unsigned int markersstringsindex;
315+ unsigned int verboseindex;
316 struct module *mod;
317 long err = 0;
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");
324
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);
330 #endif
331+ dynamic_printk_setup(sechdrs, verboseindex);
332 err = module_finalize(hdr, sechdrs, mod);
333 if (err < 0)
334 goto cleanup;
335--- a/lib/Kconfig.debug
336+++ b/lib/Kconfig.debug
337@@ -752,6 +752,61 @@ menuconfig BUILD_DOCSRC
338
339 Say N if you are unsure.
340
341+config DYNAMIC_PRINTK_DEBUG
342+ bool "Enable dynamic printk() call support"
343+ default n
344+ depends on PRINTK
345+ select PRINTK_DEBUG
346+ help
347+
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%.
353+
354+ Usage:
355+
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:
361+
362+ <module_name> <enabled=0/1>
363+ .
364+ .
365+ .
366+
367+ <module_name> : Name of the module in which the debug call resides
368+ <enabled=0/1> : whether the messages are enabled or not
369+
370+ From a live system:
371+
372+ snd_hda_intel enabled=0
373+ fixup enabled=0
374+ driver enabled=0
375+
376+ Enable a module:
377+
378+ $echo "set enabled=1 <module_name>" > dynamic_printk/modules
379+
380+ Disable a module:
381+
382+ $echo "set enabled=0 <module_name>" > dynamic_printk/modules
383+
384+ Enable all modules:
385+
386+ $echo "set enabled=1 all" > dynamic_printk/modules
387+
388+ Disable all modules:
389+
390+ $echo "set enabled=0 all" > dynamic_printk/modules
391+
392+ Finally, passing "dynamic_printk" at the command line enables
393+ debugging for all modules. This mode can be turned off via the above
394+ disable command.
395+
396 source "samples/Kconfig"
397
398 source "lib/Kconfig.kgdb"
399--- a/lib/Makefile
400+++ b/lib/Makefile
401@@ -81,6 +81,8 @@ obj-$(CONFIG_HAVE_LMB) += lmb.o
402
403 obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o
404
405+obj-$(CONFIG_DYNAMIC_PRINTK_DEBUG) += dynamic_printk.o
406+
407 hostprogs-y := gen_crc32table
408 clean-files := crc32table.h
409
410--- /dev/null
411+++ b/lib/dynamic_printk.c
412@@ -0,0 +1,418 @@
413+/*
414+ * lib/dynamic_printk.c
415+ *
416+ * make pr_debug()/dev_dbg() calls runtime configurable based upon their
417+ * their source module.
418+ *
419+ * Copyright (C) 2008 Red Hat, Inc., Jason Baron <jbaron@redhat.com>
420+ */
421+
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>
428+
429+extern struct mod_debug __start___verbose[];
430+extern struct mod_debug __stop___verbose[];
431+
432+struct debug_name {
433+ struct hlist_node hlist;
434+ struct hlist_node hlist2;
435+ int hash1;
436+ int hash2;
437+ char *name;
438+ int enable;
439+ int type;
440+};
441+
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);
450+
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.
454+ */
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);
459+
460+/* returns the debug module pointer. */
461+static struct debug_name *find_debug_module(char *module_name)
462+{
463+ int i;
464+ struct hlist_head *head;
465+ struct hlist_node *node;
466+ struct debug_name *element;
467+
468+ element = NULL;
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))
473+ return element;
474+ }
475+ return NULL;
476+}
477+
478+/* returns the debug module pointer. */
479+static struct debug_name *find_debug_module_hash(char *module_name, int hash)
480+{
481+ struct hlist_head *head;
482+ struct hlist_node *node;
483+ struct debug_name *element;
484+
485+ element = NULL;
486+ head = &module_table[hash];
487+ hlist_for_each_entry_rcu(element, node, head, hlist)
488+ if (!strcmp(element->name, module_name))
489+ return element;
490+ return NULL;
491+}
492+
493+/* caller must hold mutex*/
494+static int __add_debug_module(char *mod_name, int hash, int hash2)
495+{
496+ struct debug_name *new;
497+ char *module_name;
498+ int ret = 0;
499+
500+ if (find_debug_module(mod_name)) {
501+ ret = -EINVAL;
502+ goto out;
503+ }
504+ module_name = kmalloc(strlen(mod_name) + 1, GFP_KERNEL);
505+ if (!module_name) {
506+ ret = -ENOMEM;
507+ goto out;
508+ }
509+ module_name = strcpy(module_name, mod_name);
510+ module_name[strlen(mod_name)] = '\0';
511+ new = kzalloc(sizeof(struct debug_name), GFP_KERNEL);
512+ if (!new) {
513+ kfree(module_name);
514+ ret = -ENOMEM;
515+ goto out;
516+ }
517+ INIT_HLIST_NODE(&new->hlist);
518+ INIT_HLIST_NODE(&new->hlist2);
519+ new->name = module_name;
520+ new->hash1 = hash;
521+ new->hash2 = hash2;
522+ hlist_add_head_rcu(&new->hlist, &module_table[hash]);
523+ hlist_add_head_rcu(&new->hlist2, &module_table2[hash2]);
524+ nr_entries++;
525+out:
526+ return ret;
527+}
528+
529+int unregister_dynamic_debug_module(char *mod_name)
530+{
531+ struct debug_name *element;
532+ int ret = 0;
533+
534+ down(&debug_list_mutex);
535+ element = find_debug_module(mod_name);
536+ if (!element) {
537+ ret = -EINVAL;
538+ goto out;
539+ }
540+ hlist_del_rcu(&element->hlist);
541+ hlist_del_rcu(&element->hlist2);
542+ synchronize_rcu();
543+ kfree(element->name);
544+ if (element->enable)
545+ num_enabled--;
546+ kfree(element);
547+ nr_entries--;
548+out:
549+ up(&debug_list_mutex);
550+ return 0;
551+}
552+EXPORT_SYMBOL_GPL(unregister_dynamic_debug_module);
553+
554+int register_dynamic_debug_module(char *mod_name, int type, char *share_name,
555+ char *flags, int hash, int hash2)
556+{
557+ struct debug_name *elem;
558+ int ret = 0;
559+
560+ down(&debug_list_mutex);
561+ elem = find_debug_module(mod_name);
562+ if (!elem) {
563+ if (__add_debug_module(mod_name, hash, hash2))
564+ goto out;
565+ elem = find_debug_module(mod_name);
566+ if (dynamic_enabled == DYNAMIC_ENABLED_ALL &&
567+ !strcmp(mod_name, share_name)) {
568+ elem->enable = true;
569+ num_enabled++;
570+ }
571+ }
572+ elem->type |= type;
573+out:
574+ up(&debug_list_mutex);
575+ return ret;
576+}
577+EXPORT_SYMBOL_GPL(register_dynamic_debug_module);
578+
579+int __dynamic_dbg_enabled_helper(char *mod_name, int type, int value, int hash)
580+{
581+ struct debug_name *elem;
582+ int ret = 0;
583+
584+ if (dynamic_enabled == DYNAMIC_ENABLED_ALL)
585+ return 1;
586+ rcu_read_lock();
587+ elem = find_debug_module_hash(mod_name, hash);
588+ if (elem && elem->enable)
589+ ret = 1;
590+ rcu_read_unlock();
591+ return ret;
592+}
593+EXPORT_SYMBOL_GPL(__dynamic_dbg_enabled_helper);
594+
595+static void set_all(bool enable)
596+{
597+ struct debug_name *e;
598+ struct hlist_node *node;
599+ int i;
600+ long long enable_mask;
601+
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;
606+ }
607+ }
608+ }
609+ if (enable)
610+ enable_mask = ULLONG_MAX;
611+ else
612+ enable_mask = 0;
613+ dynamic_printk_enabled = enable_mask;
614+ dynamic_printk_enabled2 = enable_mask;
615+}
616+
617+static int disabled_hash(int i, bool first_table)
618+{
619+ struct debug_name *e;
620+ struct hlist_node *node;
621+
622+ if (first_table) {
623+ hlist_for_each_entry(e, node, &module_table[i], hlist) {
624+ if (e->enable)
625+ return 0;
626+ }
627+ } else {
628+ hlist_for_each_entry(e, node, &module_table2[i], hlist2) {
629+ if (e->enable)
630+ return 0;
631+ }
632+ }
633+ return 1;
634+}
635+
636+static ssize_t pr_debug_write(struct file *file, const char __user *buf,
637+ size_t length, loff_t *ppos)
638+{
639+ char *buffer, *s, *value_str, *setting_str;
640+ int err, value;
641+ struct debug_name *elem = NULL;
642+ int all = 0;
643+
644+ if (length > PAGE_SIZE || length < 0)
645+ return -EINVAL;
646+
647+ buffer = (char *)__get_free_page(GFP_KERNEL);
648+ if (!buffer)
649+ return -ENOMEM;
650+
651+ err = -EFAULT;
652+ if (copy_from_user(buffer, buf, length))
653+ goto out;
654+
655+ err = -EINVAL;
656+ if (length < PAGE_SIZE)
657+ buffer[length] = '\0';
658+ else if (buffer[PAGE_SIZE-1])
659+ goto out;
660+
661+ err = -EINVAL;
662+ down(&debug_list_mutex);
663+
664+ if (strncmp("set", buffer, 3))
665+ goto out_up;
666+ s = buffer + 3;
667+ setting_str = strsep(&s, "=");
668+ if (s == NULL)
669+ goto out_up;
670+ setting_str = strstrip(setting_str);
671+ value_str = strsep(&s, " ");
672+ if (s == NULL)
673+ goto out_up;
674+ s = strstrip(s);
675+ if (!strncmp(s, "all", 3))
676+ all = 1;
677+ else
678+ elem = find_debug_module(s);
679+ if (!strncmp(setting_str, "enable", 6)) {
680+ value = !!simple_strtol(value_str, NULL, 10);
681+ if (all) {
682+ if (value) {
683+ set_all(true);
684+ num_enabled = nr_entries;
685+ dynamic_enabled = DYNAMIC_ENABLED_ALL;
686+ } else {
687+ set_all(false);
688+ num_enabled = 0;
689+ dynamic_enabled = DYNAMIC_ENABLED_NONE;
690+ }
691+ err = 0;
692+ } else {
693+ if (elem) {
694+ if (value && (elem->enable == 0)) {
695+ dynamic_printk_enabled |=
696+ (1LL << elem->hash1);
697+ dynamic_printk_enabled2 |=
698+ (1LL << elem->hash2);
699+ elem->enable = 1;
700+ num_enabled++;
701+ dynamic_enabled = DYNAMIC_ENABLED_SOME;
702+ err = 0;
703+ printk(KERN_DEBUG
704+ "debugging enabled for module %s",
705+ elem->name);
706+ } else if (!value && (elem->enable == 1)) {
707+ elem->enable = 0;
708+ num_enabled--;
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);
715+ if (num_enabled)
716+ dynamic_enabled =
717+ DYNAMIC_ENABLED_SOME;
718+ else
719+ dynamic_enabled =
720+ DYNAMIC_ENABLED_NONE;
721+ err = 0;
722+ printk(KERN_DEBUG
723+ "debugging disabled for module "
724+ "%s", elem->name);
725+ }
726+ }
727+ }
728+ }
729+ if (!err)
730+ err = length;
731+out_up:
732+ up(&debug_list_mutex);
733+out:
734+ free_page((unsigned long)buffer);
735+ return err;
736+}
737+
738+static void *pr_debug_seq_start(struct seq_file *f, loff_t *pos)
739+{
740+ return (*pos < DEBUG_HASH_TABLE_SIZE) ? pos : NULL;
741+}
742+
743+static void *pr_debug_seq_next(struct seq_file *s, void *v, loff_t *pos)
744+{
745+ (*pos)++;
746+ if (*pos >= DEBUG_HASH_TABLE_SIZE)
747+ return NULL;
748+ return pos;
749+}
750+
751+static void pr_debug_seq_stop(struct seq_file *s, void *v)
752+{
753+ /* Nothing to do */
754+}
755+
756+static int pr_debug_seq_show(struct seq_file *s, void *v)
757+{
758+ struct hlist_head *head;
759+ struct hlist_node *node;
760+ struct debug_name *elem;
761+ unsigned int i = *(loff_t *) v;
762+
763+ rcu_read_lock();
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");
768+ }
769+ rcu_read_unlock();
770+ return 0;
771+}
772+
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
778+};
779+
780+static int pr_debug_open(struct inode *inode, struct file *filp)
781+{
782+ return seq_open(filp, &pr_debug_seq_ops);
783+}
784+
785+static const struct file_operations pr_debug_operations = {
786+ .open = pr_debug_open,
787+ .read = seq_read,
788+ .write = pr_debug_write,
789+ .llseek = seq_lseek,
790+ .release = seq_release,
791+};
792+
793+static int __init dynamic_printk_init(void)
794+{
795+ struct dentry *dir, *file;
796+ struct mod_debug *iter;
797+ unsigned long value;
798+
799+ dir = debugfs_create_dir("dynamic_printk", NULL);
800+ if (!dir)
801+ return -ENOMEM;
802+ file = debugfs_create_file("modules", 0644, dir, NULL,
803+ &pr_debug_operations);
804+ if (!file) {
805+ debugfs_remove(dir);
806+ return -ENOMEM;
807+ }
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,
813+ iter->type,
814+ iter->logical_modname,
815+ iter->flag_names, iter->hash, iter->hash2);
816+ }
817+ return 0;
818+}
819+module_init(dynamic_printk_init);
820+/* may want to move this earlier so we can get traces as early as possible */
821+
822+static int __init dynamic_printk_setup(char *str)
823+{
824+ if (str)
825+ return -ENOENT;
826+ set_all(true);
827+ return 0;
828+}
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);
836
837-#ifdef DEBUG
838+#if defined(DEBUG) || defined(CONFIG_DYNAMIC_PRINTK_DEBUG)
839 /* PptpControlMessageType names */
840 const char *const pptp_msg_name[] = {
841 "UNKNOWN_MESSAGE",
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)))")
847
848+#hash values
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))"
852+else
853+debug_flags =
854+endif
855+
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
860
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) \
865+ $(debug_flags)
866
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
871@@ -9,7 +9,7 @@
872 # fixdep: Used to generate dependency information during build process
873 # docproc: Used in Documentation/DocBook
874
875-hostprogs-y := fixdep docproc
876+hostprogs-y := fixdep docproc hash
877 always := $(hostprogs-y)
878
879 # fixdep is needed to compile other host programs
880--- /dev/null
881+++ b/scripts/basic/hash.c
882@@ -0,0 +1,64 @@
883+/*
884+ * Copyright (C) 2008 Red Hat, Inc., Jason Baron <jbaron@redhat.com>
885+ *
886+ */
887+
888+#include <stdio.h>
889+#include <stdlib.h>
890+#include <string.h>
891+
892+#define DYNAMIC_DEBUG_HASH_BITS 6
893+
894+static const char *program;
895+
896+static void usage(void)
897+{
898+ printf("Usage: %s <djb2|r5> <modname>\n", program);
899+ exit(1);
900+}
901+
902+/* djb2 hashing algorithm by Dan Bernstein. From:
903+ * http://www.cse.yorku.ca/~oz/hash.html
904+ */
905+
906+unsigned int djb2_hash(char *str)
907+{
908+ unsigned long hash = 5381;
909+ int c;
910+
911+ c = *str;
912+ while (c) {
913+ hash = ((hash << 5) + hash) + c;
914+ c = *++str;
915+ }
916+ return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1));
917+}
918+
919+unsigned int r5_hash(char *str)
920+{
921+ unsigned long hash = 0;
922+ int c;
923+
924+ c = *str;
925+ while (c) {
926+ hash = (hash + (c << 4) + (c >> 4)) * 11;
927+ c = *++str;
928+ }
929+ return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1));
930+}
931+
932+int main(int argc, char *argv[])
933+{
934+ program = argv[0];
935+
936+ if (argc != 3)
937+ usage();
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]));
942+ else
943+ usage();
944+ exit(0);
945+}
946+