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 @@ -1735,6 +1735,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);
336 +++ b/lib/dynamic_printk.c
339 + * lib/dynamic_printk.c
341 + * make pr_debug()/dev_dbg() calls runtime configurable based upon their
342 + * their source module.
344 + * Copyright (C) 2008 Red Hat, Inc., Jason Baron <jbaron@redhat.com>
347 +#include <linux/kernel.h>
348 +#include <linux/module.h>
349 +#include <linux/uaccess.h>
350 +#include <linux/seq_file.h>
351 +#include <linux/debugfs.h>
352 +#include <linux/fs.h>
354 +extern struct mod_debug __start___verbose[];
355 +extern struct mod_debug __stop___verbose[];
358 + struct hlist_node hlist;
359 + struct hlist_node hlist2;
367 +static int nr_entries;
368 +static int num_enabled;
369 +int dynamic_enabled = DYNAMIC_ENABLED_NONE;
370 +static struct hlist_head module_table[DEBUG_HASH_TABLE_SIZE] =
371 + { [0 ... DEBUG_HASH_TABLE_SIZE-1] = HLIST_HEAD_INIT };
372 +static struct hlist_head module_table2[DEBUG_HASH_TABLE_SIZE] =
373 + { [0 ... DEBUG_HASH_TABLE_SIZE-1] = HLIST_HEAD_INIT };
374 +static DECLARE_MUTEX(debug_list_mutex);
376 +/* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which
377 + * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
378 + * use independent hash functions, to reduce the chance of false positives.
380 +long long dynamic_printk_enabled;
381 +EXPORT_SYMBOL_GPL(dynamic_printk_enabled);
382 +long long dynamic_printk_enabled2;
383 +EXPORT_SYMBOL_GPL(dynamic_printk_enabled2);
385 +/* returns the debug module pointer. */
386 +static struct debug_name *find_debug_module(char *module_name)
389 + struct hlist_head *head;
390 + struct hlist_node *node;
391 + struct debug_name *element;
394 + for (i = 0; i < DEBUG_HASH_TABLE_SIZE; i++) {
395 + head = &module_table[i];
396 + hlist_for_each_entry_rcu(element, node, head, hlist)
397 + if (!strcmp(element->name, module_name))
403 +/* returns the debug module pointer. */
404 +static struct debug_name *find_debug_module_hash(char *module_name, int hash)
406 + struct hlist_head *head;
407 + struct hlist_node *node;
408 + struct debug_name *element;
411 + head = &module_table[hash];
412 + hlist_for_each_entry_rcu(element, node, head, hlist)
413 + if (!strcmp(element->name, module_name))
418 +/* caller must hold mutex*/
419 +static int __add_debug_module(char *mod_name, int hash, int hash2)
421 + struct debug_name *new;
425 + if (find_debug_module(mod_name)) {
429 + module_name = kmalloc(strlen(mod_name) + 1, GFP_KERNEL);
430 + if (!module_name) {
434 + module_name = strcpy(module_name, mod_name);
435 + module_name[strlen(mod_name)] = '\0';
436 + new = kzalloc(sizeof(struct debug_name), GFP_KERNEL);
438 + kfree(module_name);
442 + INIT_HLIST_NODE(&new->hlist);
443 + INIT_HLIST_NODE(&new->hlist2);
444 + new->name = module_name;
446 + new->hash2 = hash2;
447 + hlist_add_head_rcu(&new->hlist, &module_table[hash]);
448 + hlist_add_head_rcu(&new->hlist2, &module_table2[hash2]);
454 +int unregister_dynamic_debug_module(char *mod_name)
456 + struct debug_name *element;
459 + down(&debug_list_mutex);
460 + element = find_debug_module(mod_name);
465 + hlist_del_rcu(&element->hlist);
466 + hlist_del_rcu(&element->hlist2);
468 + kfree(element->name);
469 + if (element->enable)
474 + up(&debug_list_mutex);
477 +EXPORT_SYMBOL_GPL(unregister_dynamic_debug_module);
479 +int register_dynamic_debug_module(char *mod_name, int type, char *share_name,
480 + char *flags, int hash, int hash2)
482 + struct debug_name *elem;
485 + down(&debug_list_mutex);
486 + elem = find_debug_module(mod_name);
488 + if (__add_debug_module(mod_name, hash, hash2))
490 + elem = find_debug_module(mod_name);
491 + if (dynamic_enabled == DYNAMIC_ENABLED_ALL &&
492 + !strcmp(mod_name, share_name)) {
493 + elem->enable = true;
497 + elem->type |= type;
499 + up(&debug_list_mutex);
502 +EXPORT_SYMBOL_GPL(register_dynamic_debug_module);
504 +int __dynamic_dbg_enabled_helper(char *mod_name, int type, int value, int hash)
506 + struct debug_name *elem;
509 + if (dynamic_enabled == DYNAMIC_ENABLED_ALL)
512 + elem = find_debug_module_hash(mod_name, hash);
513 + if (elem && elem->enable)
518 +EXPORT_SYMBOL_GPL(__dynamic_dbg_enabled_helper);
520 +static void set_all(bool enable)
522 + struct debug_name *e;
523 + struct hlist_node *node;
525 + long long enable_mask;
527 + for (i = 0; i < DEBUG_HASH_TABLE_SIZE; i++) {
528 + if (module_table[i].first != NULL) {
529 + hlist_for_each_entry(e, node, &module_table[i], hlist) {
530 + e->enable = enable;
535 + enable_mask = ULLONG_MAX;
538 + dynamic_printk_enabled = enable_mask;
539 + dynamic_printk_enabled2 = enable_mask;
542 +static int disabled_hash(int i, bool first_table)
544 + struct debug_name *e;
545 + struct hlist_node *node;
548 + hlist_for_each_entry(e, node, &module_table[i], hlist) {
553 + hlist_for_each_entry(e, node, &module_table2[i], hlist2) {
561 +static ssize_t pr_debug_write(struct file *file, const char __user *buf,
562 + size_t length, loff_t *ppos)
564 + char *buffer, *s, *value_str, *setting_str;
566 + struct debug_name *elem = NULL;
569 + if (length > PAGE_SIZE || length < 0)
572 + buffer = (char *)__get_free_page(GFP_KERNEL);
577 + if (copy_from_user(buffer, buf, length))
581 + if (length < PAGE_SIZE)
582 + buffer[length] = '\0';
583 + else if (buffer[PAGE_SIZE-1])
587 + down(&debug_list_mutex);
589 + if (strncmp("set", buffer, 3))
592 + setting_str = strsep(&s, "=");
595 + setting_str = strstrip(setting_str);
596 + value_str = strsep(&s, " ");
600 + if (!strncmp(s, "all", 3))
603 + elem = find_debug_module(s);
604 + if (!strncmp(setting_str, "enable", 6)) {
605 + value = !!simple_strtol(value_str, NULL, 10);
609 + num_enabled = nr_entries;
610 + dynamic_enabled = DYNAMIC_ENABLED_ALL;
614 + dynamic_enabled = DYNAMIC_ENABLED_NONE;
619 + if (value && (elem->enable == 0)) {
620 + dynamic_printk_enabled |=
621 + (1LL << elem->hash1);
622 + dynamic_printk_enabled2 |=
623 + (1LL << elem->hash2);
626 + dynamic_enabled = DYNAMIC_ENABLED_SOME;
629 + "debugging enabled for module %s",
631 + } else if (!value && (elem->enable == 1)) {
634 + if (disabled_hash(elem->hash1, true))
635 + dynamic_printk_enabled &=
636 + ~(1LL << elem->hash1);
637 + if (disabled_hash(elem->hash2, false))
638 + dynamic_printk_enabled2 &=
639 + ~(1LL << elem->hash2);
642 + DYNAMIC_ENABLED_SOME;
645 + DYNAMIC_ENABLED_NONE;
648 + "debugging disabled for module "
657 + up(&debug_list_mutex);
659 + free_page((unsigned long)buffer);
663 +static void *pr_debug_seq_start(struct seq_file *f, loff_t *pos)
665 + return (*pos < DEBUG_HASH_TABLE_SIZE) ? pos : NULL;
668 +static void *pr_debug_seq_next(struct seq_file *s, void *v, loff_t *pos)
671 + if (*pos >= DEBUG_HASH_TABLE_SIZE)
676 +static void pr_debug_seq_stop(struct seq_file *s, void *v)
678 + /* Nothing to do */
681 +static int pr_debug_seq_show(struct seq_file *s, void *v)
683 + struct hlist_head *head;
684 + struct hlist_node *node;
685 + struct debug_name *elem;
686 + unsigned int i = *(loff_t *) v;
689 + head = &module_table[i];
690 + hlist_for_each_entry_rcu(elem, node, head, hlist) {
691 + seq_printf(s, "%s enabled=%d", elem->name, elem->enable);
692 + seq_printf(s, "\n");
698 +static struct seq_operations pr_debug_seq_ops = {
699 + .start = pr_debug_seq_start,
700 + .next = pr_debug_seq_next,
701 + .stop = pr_debug_seq_stop,
702 + .show = pr_debug_seq_show
705 +static int pr_debug_open(struct inode *inode, struct file *filp)
707 + return seq_open(filp, &pr_debug_seq_ops);
710 +static const struct file_operations pr_debug_operations = {
711 + .open = pr_debug_open,
713 + .write = pr_debug_write,
714 + .llseek = seq_lseek,
715 + .release = seq_release,
718 +static int __init dynamic_printk_init(void)
720 + struct dentry *dir, *file;
721 + struct mod_debug *iter;
722 + unsigned long value;
724 + dir = debugfs_create_dir("dynamic_printk", NULL);
727 + file = debugfs_create_file("modules", 0644, dir, NULL,
728 + &pr_debug_operations);
730 + debugfs_remove(dir);
733 + for (value = (unsigned long)__start___verbose;
734 + value < (unsigned long)__stop___verbose;
735 + value += sizeof(struct mod_debug)) {
736 + iter = (struct mod_debug *)value;
737 + register_dynamic_debug_module(iter->modname,
739 + iter->logical_modname,
740 + iter->flag_names, iter->hash, iter->hash2);
744 +module_init(dynamic_printk_init);
745 +/* may want to move this earlier so we can get traces as early as possible */
747 +static int __init dynamic_printk_setup(char *str)
754 +/* Use early_param(), so we can get debug output as early as possible */
755 +early_param("dynamic_printk", dynamic_printk_setup);
756 --- a/lib/Kconfig.debug
757 +++ b/lib/Kconfig.debug
758 @@ -752,6 +752,61 @@ menuconfig BUILD_DOCSRC
760 Say N if you are unsure.
762 +config DYNAMIC_PRINTK_DEBUG
763 + bool "Enable dynamic printk() call support"
766 + select PRINTK_DEBUG
769 + Compiles debug level messages into the kernel, which would not
770 + otherwise be available at runtime. These messages can then be
771 + enabled/disabled on a per module basis. This mechanism implicitly
772 + enables all pr_debug() and dev_dbg() calls. The impact of this
773 + compile option is a larger kernel text size of about 2%.
777 + Dynamic debugging is controlled by the debugfs file,
778 + dynamic_printk/modules. This file contains a list of the modules that
779 + can be enabled. The format of the file is the module name, followed
780 + by a set of flags that can be enabled. The first flag is always the
781 + 'enabled' flag. For example:
783 + <module_name> <enabled=0/1>
788 + <module_name> : Name of the module in which the debug call resides
789 + <enabled=0/1> : whether the messages are enabled or not
791 + From a live system:
793 + snd_hda_intel enabled=0
799 + $echo "set enabled=1 <module_name>" > dynamic_printk/modules
803 + $echo "set enabled=0 <module_name>" > dynamic_printk/modules
805 + Enable all modules:
807 + $echo "set enabled=1 all" > dynamic_printk/modules
809 + Disable all modules:
811 + $echo "set enabled=0 all" > dynamic_printk/modules
813 + Finally, passing "dynamic_printk" at the command line enables
814 + debugging for all modules. This mode can be turned off via the above
817 source "samples/Kconfig"
819 source "lib/Kconfig.kgdb"
822 @@ -81,6 +81,8 @@ obj-$(CONFIG_HAVE_LMB) += lmb.o
824 obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o
826 +obj-$(CONFIG_DYNAMIC_PRINTK_DEBUG) += dynamic_printk.o
828 hostprogs-y := gen_crc32table
829 clean-files := crc32table.h
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[] = {
843 +++ b/scripts/basic/hash.c
846 + * Copyright (C) 2008 Red Hat, Inc., Jason Baron <jbaron@redhat.com>
854 +#define DYNAMIC_DEBUG_HASH_BITS 6
856 +static const char *program;
858 +static void usage(void)
860 + printf("Usage: %s <djb2|r5> <modname>\n", program);
864 +/* djb2 hashing algorithm by Dan Bernstein. From:
865 + * http://www.cse.yorku.ca/~oz/hash.html
868 +unsigned int djb2_hash(char *str)
870 + unsigned long hash = 5381;
875 + hash = ((hash << 5) + hash) + c;
878 + return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1));
881 +unsigned int r5_hash(char *str)
883 + unsigned long hash = 0;
888 + hash = (hash + (c << 4) + (c >> 4)) * 11;
891 + return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1));
894 +int main(int argc, char *argv[])
900 + if (!strcmp(argv[1], "djb2"))
901 + printf("%d\n", djb2_hash(argv[2]));
902 + else if (!strcmp(argv[1], "r5"))
903 + printf("%d\n", r5_hash(argv[2]));
909 --- a/scripts/basic/Makefile
910 +++ b/scripts/basic/Makefile
912 # fixdep: Used to generate dependency information during build process
913 # docproc: Used in Documentation/DocBook
915 -hostprogs-y := fixdep docproc
916 +hostprogs-y := fixdep docproc hash
917 always := $(hostprogs-y)
919 # fixdep is needed to compile other host programs
920 --- a/scripts/Makefile.lib
921 +++ b/scripts/Makefile.lib
922 @@ -96,6 +96,14 @@ basename_flags = -D"KBUILD_BASENAME=KBUI
923 modname_flags = $(if $(filter 1,$(words $(modname))),\
924 -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
927 +ifdef CONFIG_DYNAMIC_PRINTK_DEBUG
928 +debug_flags = -D"DEBUG_HASH=$(shell ./scripts/basic/hash djb2 $(@D)$(modname))"\
929 + -D"DEBUG_HASH2=$(shell ./scripts/basic/hash r5 $(@D)$(modname))"
934 orig_c_flags = $(KBUILD_CFLAGS) $(ccflags-y) $(CFLAGS_$(basetarget).o)
935 _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
936 _a_flags = $(KBUILD_AFLAGS) $(asflags-y) $(AFLAGS_$(basetarget).o)
937 @@ -121,7 +129,8 @@ endif
939 c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) \
940 $(__c_flags) $(modkern_cflags) \
941 - -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags)
942 + -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) \
945 a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) \
946 $(__a_flags) $(modkern_aflags)