diff options
Diffstat (limited to 'lib/dynamic_debug.c')
-rw-r--r-- | lib/dynamic_debug.c | 140 |
1 files changed, 76 insertions, 64 deletions
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 02afc2533728..3094318bfea7 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c | |||
@@ -26,19 +26,11 @@ | |||
26 | #include <linux/dynamic_debug.h> | 26 | #include <linux/dynamic_debug.h> |
27 | #include <linux/debugfs.h> | 27 | #include <linux/debugfs.h> |
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | #include <linux/jump_label.h> | ||
29 | 30 | ||
30 | extern struct _ddebug __start___verbose[]; | 31 | extern struct _ddebug __start___verbose[]; |
31 | extern struct _ddebug __stop___verbose[]; | 32 | extern struct _ddebug __stop___verbose[]; |
32 | 33 | ||
33 | /* dynamic_debug_enabled, and dynamic_debug_enabled2 are bitmasks in which | ||
34 | * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They | ||
35 | * use independent hash functions, to reduce the chance of false positives. | ||
36 | */ | ||
37 | long long dynamic_debug_enabled; | ||
38 | EXPORT_SYMBOL_GPL(dynamic_debug_enabled); | ||
39 | long long dynamic_debug_enabled2; | ||
40 | EXPORT_SYMBOL_GPL(dynamic_debug_enabled2); | ||
41 | |||
42 | struct ddebug_table { | 34 | struct ddebug_table { |
43 | struct list_head link; | 35 | struct list_head link; |
44 | char *mod_name; | 36 | char *mod_name; |
@@ -88,26 +80,6 @@ static char *ddebug_describe_flags(struct _ddebug *dp, char *buf, | |||
88 | } | 80 | } |
89 | 81 | ||
90 | /* | 82 | /* |
91 | * must be called with ddebug_lock held | ||
92 | */ | ||
93 | |||
94 | static int disabled_hash(char hash, bool first_table) | ||
95 | { | ||
96 | struct ddebug_table *dt; | ||
97 | char table_hash_value; | ||
98 | |||
99 | list_for_each_entry(dt, &ddebug_tables, link) { | ||
100 | if (first_table) | ||
101 | table_hash_value = dt->ddebugs->primary_hash; | ||
102 | else | ||
103 | table_hash_value = dt->ddebugs->secondary_hash; | ||
104 | if (dt->num_enabled && (hash == table_hash_value)) | ||
105 | return 0; | ||
106 | } | ||
107 | return 1; | ||
108 | } | ||
109 | |||
110 | /* | ||
111 | * Search the tables for _ddebug's which match the given | 83 | * Search the tables for _ddebug's which match the given |
112 | * `query' and apply the `flags' and `mask' to them. Tells | 84 | * `query' and apply the `flags' and `mask' to them. Tells |
113 | * the user which ddebug's were changed, or whether none | 85 | * the user which ddebug's were changed, or whether none |
@@ -170,17 +142,9 @@ static void ddebug_change(const struct ddebug_query *query, | |||
170 | dt->num_enabled++; | 142 | dt->num_enabled++; |
171 | dp->flags = newflags; | 143 | dp->flags = newflags; |
172 | if (newflags) { | 144 | if (newflags) { |
173 | dynamic_debug_enabled |= | 145 | jump_label_enable(&dp->enabled); |
174 | (1LL << dp->primary_hash); | ||
175 | dynamic_debug_enabled2 |= | ||
176 | (1LL << dp->secondary_hash); | ||
177 | } else { | 146 | } else { |
178 | if (disabled_hash(dp->primary_hash, true)) | 147 | jump_label_disable(&dp->enabled); |
179 | dynamic_debug_enabled &= | ||
180 | ~(1LL << dp->primary_hash); | ||
181 | if (disabled_hash(dp->secondary_hash, false)) | ||
182 | dynamic_debug_enabled2 &= | ||
183 | ~(1LL << dp->secondary_hash); | ||
184 | } | 148 | } |
185 | if (verbose) | 149 | if (verbose) |
186 | printk(KERN_INFO | 150 | printk(KERN_INFO |
@@ -429,6 +393,40 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp, | |||
429 | return 0; | 393 | return 0; |
430 | } | 394 | } |
431 | 395 | ||
396 | static int ddebug_exec_query(char *query_string) | ||
397 | { | ||
398 | unsigned int flags = 0, mask = 0; | ||
399 | struct ddebug_query query; | ||
400 | #define MAXWORDS 9 | ||
401 | int nwords; | ||
402 | char *words[MAXWORDS]; | ||
403 | |||
404 | nwords = ddebug_tokenize(query_string, words, MAXWORDS); | ||
405 | if (nwords <= 0) | ||
406 | return -EINVAL; | ||
407 | if (ddebug_parse_query(words, nwords-1, &query)) | ||
408 | return -EINVAL; | ||
409 | if (ddebug_parse_flags(words[nwords-1], &flags, &mask)) | ||
410 | return -EINVAL; | ||
411 | |||
412 | /* actually go and implement the change */ | ||
413 | ddebug_change(&query, flags, mask); | ||
414 | return 0; | ||
415 | } | ||
416 | |||
417 | static __initdata char ddebug_setup_string[1024]; | ||
418 | static __init int ddebug_setup_query(char *str) | ||
419 | { | ||
420 | if (strlen(str) >= 1024) { | ||
421 | pr_warning("ddebug boot param string too large\n"); | ||
422 | return 0; | ||
423 | } | ||
424 | strcpy(ddebug_setup_string, str); | ||
425 | return 1; | ||
426 | } | ||
427 | |||
428 | __setup("ddebug_query=", ddebug_setup_query); | ||
429 | |||
432 | /* | 430 | /* |
433 | * File_ops->write method for <debugfs>/dynamic_debug/conrol. Gathers the | 431 | * File_ops->write method for <debugfs>/dynamic_debug/conrol. Gathers the |
434 | * command text from userspace, parses and executes it. | 432 | * command text from userspace, parses and executes it. |
@@ -436,12 +434,8 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp, | |||
436 | static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, | 434 | static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, |
437 | size_t len, loff_t *offp) | 435 | size_t len, loff_t *offp) |
438 | { | 436 | { |
439 | unsigned int flags = 0, mask = 0; | ||
440 | struct ddebug_query query; | ||
441 | #define MAXWORDS 9 | ||
442 | int nwords; | ||
443 | char *words[MAXWORDS]; | ||
444 | char tmpbuf[256]; | 437 | char tmpbuf[256]; |
438 | int ret; | ||
445 | 439 | ||
446 | if (len == 0) | 440 | if (len == 0) |
447 | return 0; | 441 | return 0; |
@@ -455,16 +449,9 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, | |||
455 | printk(KERN_INFO "%s: read %d bytes from userspace\n", | 449 | printk(KERN_INFO "%s: read %d bytes from userspace\n", |
456 | __func__, (int)len); | 450 | __func__, (int)len); |
457 | 451 | ||
458 | nwords = ddebug_tokenize(tmpbuf, words, MAXWORDS); | 452 | ret = ddebug_exec_query(tmpbuf); |
459 | if (nwords <= 0) | 453 | if (ret) |
460 | return -EINVAL; | 454 | return ret; |
461 | if (ddebug_parse_query(words, nwords-1, &query)) | ||
462 | return -EINVAL; | ||
463 | if (ddebug_parse_flags(words[nwords-1], &flags, &mask)) | ||
464 | return -EINVAL; | ||
465 | |||
466 | /* actually go and implement the change */ | ||
467 | ddebug_change(&query, flags, mask); | ||
468 | 455 | ||
469 | *offp += len; | 456 | *offp += len; |
470 | return len; | 457 | return len; |
@@ -725,13 +712,14 @@ static void ddebug_remove_all_tables(void) | |||
725 | mutex_unlock(&ddebug_lock); | 712 | mutex_unlock(&ddebug_lock); |
726 | } | 713 | } |
727 | 714 | ||
728 | static int __init dynamic_debug_init(void) | 715 | static __initdata int ddebug_init_success; |
716 | |||
717 | static int __init dynamic_debug_init_debugfs(void) | ||
729 | { | 718 | { |
730 | struct dentry *dir, *file; | 719 | struct dentry *dir, *file; |
731 | struct _ddebug *iter, *iter_start; | 720 | |
732 | const char *modname = NULL; | 721 | if (!ddebug_init_success) |
733 | int ret = 0; | 722 | return -ENODEV; |
734 | int n = 0; | ||
735 | 723 | ||
736 | dir = debugfs_create_dir("dynamic_debug", NULL); | 724 | dir = debugfs_create_dir("dynamic_debug", NULL); |
737 | if (!dir) | 725 | if (!dir) |
@@ -742,6 +730,16 @@ static int __init dynamic_debug_init(void) | |||
742 | debugfs_remove(dir); | 730 | debugfs_remove(dir); |
743 | return -ENOMEM; | 731 | return -ENOMEM; |
744 | } | 732 | } |
733 | return 0; | ||
734 | } | ||
735 | |||
736 | static int __init dynamic_debug_init(void) | ||
737 | { | ||
738 | struct _ddebug *iter, *iter_start; | ||
739 | const char *modname = NULL; | ||
740 | int ret = 0; | ||
741 | int n = 0; | ||
742 | |||
745 | if (__start___verbose != __stop___verbose) { | 743 | if (__start___verbose != __stop___verbose) { |
746 | iter = __start___verbose; | 744 | iter = __start___verbose; |
747 | modname = iter->modname; | 745 | modname = iter->modname; |
@@ -759,12 +757,26 @@ static int __init dynamic_debug_init(void) | |||
759 | } | 757 | } |
760 | ret = ddebug_add_module(iter_start, n, modname); | 758 | ret = ddebug_add_module(iter_start, n, modname); |
761 | } | 759 | } |
760 | |||
761 | /* ddebug_query boot param got passed -> set it up */ | ||
762 | if (ddebug_setup_string[0] != '\0') { | ||
763 | ret = ddebug_exec_query(ddebug_setup_string); | ||
764 | if (ret) | ||
765 | pr_warning("Invalid ddebug boot param %s", | ||
766 | ddebug_setup_string); | ||
767 | else | ||
768 | pr_info("ddebug initialized with string %s", | ||
769 | ddebug_setup_string); | ||
770 | } | ||
771 | |||
762 | out_free: | 772 | out_free: |
763 | if (ret) { | 773 | if (ret) |
764 | ddebug_remove_all_tables(); | 774 | ddebug_remove_all_tables(); |
765 | debugfs_remove(dir); | 775 | else |
766 | debugfs_remove(file); | 776 | ddebug_init_success = 1; |
767 | } | ||
768 | return 0; | 777 | return 0; |
769 | } | 778 | } |
770 | module_init(dynamic_debug_init); | 779 | /* Allow early initialization for boot messages via boot param */ |
780 | arch_initcall(dynamic_debug_init); | ||
781 | /* Debugfs setup must be done later */ | ||
782 | module_init(dynamic_debug_init_debugfs); | ||