.. | .. |
---|
11 | 11 | * Copyright (C) 2013 Du, Changbin <changbin.du@gmail.com> |
---|
12 | 12 | */ |
---|
13 | 13 | |
---|
14 | | -#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ |
---|
| 14 | +#define pr_fmt(fmt) "dyndbg: " fmt |
---|
15 | 15 | |
---|
16 | 16 | #include <linux/kernel.h> |
---|
17 | 17 | #include <linux/module.h> |
---|
.. | .. |
---|
37 | 37 | #include <linux/device.h> |
---|
38 | 38 | #include <linux/netdevice.h> |
---|
39 | 39 | |
---|
40 | | -extern struct _ddebug __start___verbose[]; |
---|
41 | | -extern struct _ddebug __stop___verbose[]; |
---|
| 40 | +#include <rdma/ib_verbs.h> |
---|
| 41 | + |
---|
| 42 | +extern struct _ddebug __start___dyndbg[]; |
---|
| 43 | +extern struct _ddebug __stop___dyndbg[]; |
---|
42 | 44 | |
---|
43 | 45 | struct ddebug_table { |
---|
44 | 46 | struct list_head link; |
---|
.. | .. |
---|
58 | 60 | struct ddebug_iter { |
---|
59 | 61 | struct ddebug_table *table; |
---|
60 | 62 | unsigned int idx; |
---|
| 63 | +}; |
---|
| 64 | + |
---|
| 65 | +struct flag_settings { |
---|
| 66 | + unsigned int flags; |
---|
| 67 | + unsigned int mask; |
---|
61 | 68 | }; |
---|
62 | 69 | |
---|
63 | 70 | static DEFINE_MUTEX(ddebug_lock); |
---|
.. | .. |
---|
103 | 110 | return fb->buf; |
---|
104 | 111 | } |
---|
105 | 112 | |
---|
106 | | -#define vpr_info(fmt, ...) \ |
---|
| 113 | +#define vnpr_info(lvl, fmt, ...) \ |
---|
107 | 114 | do { \ |
---|
108 | | - if (verbose) \ |
---|
| 115 | + if (verbose >= lvl) \ |
---|
109 | 116 | pr_info(fmt, ##__VA_ARGS__); \ |
---|
110 | 117 | } while (0) |
---|
| 118 | + |
---|
| 119 | +#define vpr_info(fmt, ...) vnpr_info(1, fmt, ##__VA_ARGS__) |
---|
| 120 | +#define v2pr_info(fmt, ...) vnpr_info(2, fmt, ##__VA_ARGS__) |
---|
111 | 121 | |
---|
112 | 122 | static void vpr_info_dq(const struct ddebug_query *query, const char *msg) |
---|
113 | 123 | { |
---|
.. | .. |
---|
122 | 132 | |
---|
123 | 133 | vpr_info("%s: func=\"%s\" file=\"%s\" module=\"%s\" format=\"%.*s\" lineno=%u-%u\n", |
---|
124 | 134 | msg, |
---|
125 | | - query->function ? query->function : "", |
---|
126 | | - query->filename ? query->filename : "", |
---|
127 | | - query->module ? query->module : "", |
---|
128 | | - fmtlen, query->format ? query->format : "", |
---|
| 135 | + query->function ?: "", |
---|
| 136 | + query->filename ?: "", |
---|
| 137 | + query->module ?: "", |
---|
| 138 | + fmtlen, query->format ?: "", |
---|
129 | 139 | query->first_lineno, query->last_lineno); |
---|
130 | 140 | } |
---|
131 | 141 | |
---|
.. | .. |
---|
136 | 146 | * logs the changes. Takes ddebug_lock. |
---|
137 | 147 | */ |
---|
138 | 148 | static int ddebug_change(const struct ddebug_query *query, |
---|
139 | | - unsigned int flags, unsigned int mask) |
---|
| 149 | + struct flag_settings *modifiers) |
---|
140 | 150 | { |
---|
141 | 151 | int i; |
---|
142 | 152 | struct ddebug_table *dt; |
---|
.. | .. |
---|
171 | 181 | continue; |
---|
172 | 182 | |
---|
173 | 183 | /* match against the format */ |
---|
174 | | - if (query->format && |
---|
175 | | - !strstr(dp->format, query->format)) |
---|
176 | | - continue; |
---|
| 184 | + if (query->format) { |
---|
| 185 | + if (*query->format == '^') { |
---|
| 186 | + char *p; |
---|
| 187 | + /* anchored search. match must be at beginning */ |
---|
| 188 | + p = strstr(dp->format, query->format+1); |
---|
| 189 | + if (p != dp->format) |
---|
| 190 | + continue; |
---|
| 191 | + } else if (!strstr(dp->format, query->format)) |
---|
| 192 | + continue; |
---|
| 193 | + } |
---|
177 | 194 | |
---|
178 | 195 | /* match against the line number range */ |
---|
179 | 196 | if (query->first_lineno && |
---|
.. | .. |
---|
185 | 202 | |
---|
186 | 203 | nfound++; |
---|
187 | 204 | |
---|
188 | | - newflags = (dp->flags & mask) | flags; |
---|
| 205 | + newflags = (dp->flags & modifiers->mask) | modifiers->flags; |
---|
189 | 206 | if (newflags == dp->flags) |
---|
190 | 207 | continue; |
---|
191 | 208 | #ifdef CONFIG_JUMP_LABEL |
---|
192 | 209 | if (dp->flags & _DPRINTK_FLAGS_PRINT) { |
---|
193 | | - if (!(flags & _DPRINTK_FLAGS_PRINT)) |
---|
| 210 | + if (!(newflags & _DPRINTK_FLAGS_PRINT)) |
---|
194 | 211 | static_branch_disable(&dp->key.dd_key_true); |
---|
195 | | - } else if (flags & _DPRINTK_FLAGS_PRINT) |
---|
| 212 | + } else if (newflags & _DPRINTK_FLAGS_PRINT) { |
---|
196 | 213 | static_branch_enable(&dp->key.dd_key_true); |
---|
| 214 | + } |
---|
197 | 215 | #endif |
---|
198 | 216 | dp->flags = newflags; |
---|
199 | | - vpr_info("changed %s:%d [%s]%s =%s\n", |
---|
| 217 | + v2pr_info("changed %s:%d [%s]%s =%s\n", |
---|
200 | 218 | trim_prefix(dp->filename), dp->lineno, |
---|
201 | 219 | dt->mod_name, dp->function, |
---|
202 | 220 | ddebug_describe_flags(dp->flags, &fbuf)); |
---|
.. | .. |
---|
286 | 304 | return 0; |
---|
287 | 305 | } |
---|
288 | 306 | |
---|
| 307 | +static int parse_linerange(struct ddebug_query *query, const char *first) |
---|
| 308 | +{ |
---|
| 309 | + char *last = strchr(first, '-'); |
---|
| 310 | + |
---|
| 311 | + if (query->first_lineno || query->last_lineno) { |
---|
| 312 | + pr_err("match-spec: line used 2x\n"); |
---|
| 313 | + return -EINVAL; |
---|
| 314 | + } |
---|
| 315 | + if (last) |
---|
| 316 | + *last++ = '\0'; |
---|
| 317 | + if (parse_lineno(first, &query->first_lineno) < 0) |
---|
| 318 | + return -EINVAL; |
---|
| 319 | + if (last) { |
---|
| 320 | + /* range <first>-<last> */ |
---|
| 321 | + if (parse_lineno(last, &query->last_lineno) < 0) |
---|
| 322 | + return -EINVAL; |
---|
| 323 | + |
---|
| 324 | + /* special case for last lineno not specified */ |
---|
| 325 | + if (query->last_lineno == 0) |
---|
| 326 | + query->last_lineno = UINT_MAX; |
---|
| 327 | + |
---|
| 328 | + if (query->last_lineno < query->first_lineno) { |
---|
| 329 | + pr_err("last-line:%d < 1st-line:%d\n", |
---|
| 330 | + query->last_lineno, |
---|
| 331 | + query->first_lineno); |
---|
| 332 | + return -EINVAL; |
---|
| 333 | + } |
---|
| 334 | + } else { |
---|
| 335 | + query->last_lineno = query->first_lineno; |
---|
| 336 | + } |
---|
| 337 | + vpr_info("parsed line %d-%d\n", query->first_lineno, |
---|
| 338 | + query->last_lineno); |
---|
| 339 | + return 0; |
---|
| 340 | +} |
---|
| 341 | + |
---|
289 | 342 | static int check_set(const char **dest, char *src, char *name) |
---|
290 | 343 | { |
---|
291 | 344 | int rc = 0; |
---|
.. | .. |
---|
319 | 372 | { |
---|
320 | 373 | unsigned int i; |
---|
321 | 374 | int rc = 0; |
---|
| 375 | + char *fline; |
---|
322 | 376 | |
---|
323 | 377 | /* check we have an even number of words */ |
---|
324 | 378 | if (nwords % 2 != 0) { |
---|
325 | 379 | pr_err("expecting pairs of match-spec <value>\n"); |
---|
326 | 380 | return -EINVAL; |
---|
327 | 381 | } |
---|
328 | | - memset(query, 0, sizeof(*query)); |
---|
329 | | - |
---|
330 | | - if (modname) |
---|
331 | | - /* support $modname.dyndbg=<multiple queries> */ |
---|
332 | | - query->module = modname; |
---|
333 | 382 | |
---|
334 | 383 | for (i = 0; i < nwords; i += 2) { |
---|
335 | | - if (!strcmp(words[i], "func")) { |
---|
336 | | - rc = check_set(&query->function, words[i+1], "func"); |
---|
337 | | - } else if (!strcmp(words[i], "file")) { |
---|
338 | | - rc = check_set(&query->filename, words[i+1], "file"); |
---|
339 | | - } else if (!strcmp(words[i], "module")) { |
---|
340 | | - rc = check_set(&query->module, words[i+1], "module"); |
---|
341 | | - } else if (!strcmp(words[i], "format")) { |
---|
342 | | - string_unescape_inplace(words[i+1], UNESCAPE_SPACE | |
---|
| 384 | + char *keyword = words[i]; |
---|
| 385 | + char *arg = words[i+1]; |
---|
| 386 | + |
---|
| 387 | + if (!strcmp(keyword, "func")) { |
---|
| 388 | + rc = check_set(&query->function, arg, "func"); |
---|
| 389 | + } else if (!strcmp(keyword, "file")) { |
---|
| 390 | + if (check_set(&query->filename, arg, "file")) |
---|
| 391 | + return -EINVAL; |
---|
| 392 | + |
---|
| 393 | + /* tail :$info is function or line-range */ |
---|
| 394 | + fline = strchr(query->filename, ':'); |
---|
| 395 | + if (!fline) |
---|
| 396 | + continue; |
---|
| 397 | + *fline++ = '\0'; |
---|
| 398 | + if (isalpha(*fline) || *fline == '*' || *fline == '?') { |
---|
| 399 | + /* take as function name */ |
---|
| 400 | + if (check_set(&query->function, fline, "func")) |
---|
| 401 | + return -EINVAL; |
---|
| 402 | + } else { |
---|
| 403 | + if (parse_linerange(query, fline)) |
---|
| 404 | + return -EINVAL; |
---|
| 405 | + } |
---|
| 406 | + } else if (!strcmp(keyword, "module")) { |
---|
| 407 | + rc = check_set(&query->module, arg, "module"); |
---|
| 408 | + } else if (!strcmp(keyword, "format")) { |
---|
| 409 | + string_unescape_inplace(arg, UNESCAPE_SPACE | |
---|
343 | 410 | UNESCAPE_OCTAL | |
---|
344 | 411 | UNESCAPE_SPECIAL); |
---|
345 | | - rc = check_set(&query->format, words[i+1], "format"); |
---|
346 | | - } else if (!strcmp(words[i], "line")) { |
---|
347 | | - char *first = words[i+1]; |
---|
348 | | - char *last = strchr(first, '-'); |
---|
349 | | - if (query->first_lineno || query->last_lineno) { |
---|
350 | | - pr_err("match-spec: line used 2x\n"); |
---|
| 412 | + rc = check_set(&query->format, arg, "format"); |
---|
| 413 | + } else if (!strcmp(keyword, "line")) { |
---|
| 414 | + if (parse_linerange(query, arg)) |
---|
351 | 415 | return -EINVAL; |
---|
352 | | - } |
---|
353 | | - if (last) |
---|
354 | | - *last++ = '\0'; |
---|
355 | | - if (parse_lineno(first, &query->first_lineno) < 0) |
---|
356 | | - return -EINVAL; |
---|
357 | | - if (last) { |
---|
358 | | - /* range <first>-<last> */ |
---|
359 | | - if (parse_lineno(last, &query->last_lineno) < 0) |
---|
360 | | - return -EINVAL; |
---|
361 | | - |
---|
362 | | - /* special case for last lineno not specified */ |
---|
363 | | - if (query->last_lineno == 0) |
---|
364 | | - query->last_lineno = UINT_MAX; |
---|
365 | | - |
---|
366 | | - if (query->last_lineno < query->first_lineno) { |
---|
367 | | - pr_err("last-line:%d < 1st-line:%d\n", |
---|
368 | | - query->last_lineno, |
---|
369 | | - query->first_lineno); |
---|
370 | | - return -EINVAL; |
---|
371 | | - } |
---|
372 | | - } else { |
---|
373 | | - query->last_lineno = query->first_lineno; |
---|
374 | | - } |
---|
375 | 416 | } else { |
---|
376 | | - pr_err("unknown keyword \"%s\"\n", words[i]); |
---|
| 417 | + pr_err("unknown keyword \"%s\"\n", keyword); |
---|
377 | 418 | return -EINVAL; |
---|
378 | 419 | } |
---|
379 | 420 | if (rc) |
---|
380 | 421 | return rc; |
---|
381 | 422 | } |
---|
| 423 | + if (!query->module && modname) |
---|
| 424 | + /* |
---|
| 425 | + * support $modname.dyndbg=<multiple queries>, when |
---|
| 426 | + * not given in the query itself |
---|
| 427 | + */ |
---|
| 428 | + query->module = modname; |
---|
| 429 | + |
---|
382 | 430 | vpr_info_dq(query, "parsed"); |
---|
383 | 431 | return 0; |
---|
384 | 432 | } |
---|
.. | .. |
---|
389 | 437 | * flags fields of matched _ddebug's. Returns 0 on success |
---|
390 | 438 | * or <0 on error. |
---|
391 | 439 | */ |
---|
392 | | -static int ddebug_parse_flags(const char *str, unsigned int *flagsp, |
---|
393 | | - unsigned int *maskp) |
---|
| 440 | +static int ddebug_parse_flags(const char *str, struct flag_settings *modifiers) |
---|
394 | 441 | { |
---|
395 | | - unsigned flags = 0; |
---|
396 | | - int op = '=', i; |
---|
| 442 | + int op, i; |
---|
397 | 443 | |
---|
398 | 444 | switch (*str) { |
---|
399 | 445 | case '+': |
---|
.. | .. |
---|
410 | 456 | for (; *str ; ++str) { |
---|
411 | 457 | for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) { |
---|
412 | 458 | if (*str == opt_array[i].opt_char) { |
---|
413 | | - flags |= opt_array[i].flag; |
---|
| 459 | + modifiers->flags |= opt_array[i].flag; |
---|
414 | 460 | break; |
---|
415 | 461 | } |
---|
416 | 462 | } |
---|
417 | 463 | if (i < 0) { |
---|
418 | | - pr_err("unknown flag '%c' in \"%s\"\n", *str, str); |
---|
| 464 | + pr_err("unknown flag '%c'\n", *str); |
---|
419 | 465 | return -EINVAL; |
---|
420 | 466 | } |
---|
421 | 467 | } |
---|
422 | | - vpr_info("flags=0x%x\n", flags); |
---|
| 468 | + vpr_info("flags=0x%x\n", modifiers->flags); |
---|
423 | 469 | |
---|
424 | | - /* calculate final *flagsp, *maskp according to mask and op */ |
---|
| 470 | + /* calculate final flags, mask based upon op */ |
---|
425 | 471 | switch (op) { |
---|
426 | 472 | case '=': |
---|
427 | | - *maskp = 0; |
---|
428 | | - *flagsp = flags; |
---|
| 473 | + /* modifiers->flags already set */ |
---|
| 474 | + modifiers->mask = 0; |
---|
429 | 475 | break; |
---|
430 | 476 | case '+': |
---|
431 | | - *maskp = ~0U; |
---|
432 | | - *flagsp = flags; |
---|
| 477 | + modifiers->mask = ~0U; |
---|
433 | 478 | break; |
---|
434 | 479 | case '-': |
---|
435 | | - *maskp = ~flags; |
---|
436 | | - *flagsp = 0; |
---|
| 480 | + modifiers->mask = ~modifiers->flags; |
---|
| 481 | + modifiers->flags = 0; |
---|
437 | 482 | break; |
---|
438 | 483 | } |
---|
439 | | - vpr_info("*flagsp=0x%x *maskp=0x%x\n", *flagsp, *maskp); |
---|
| 484 | + vpr_info("*flagsp=0x%x *maskp=0x%x\n", modifiers->flags, modifiers->mask); |
---|
| 485 | + |
---|
440 | 486 | return 0; |
---|
441 | 487 | } |
---|
442 | 488 | |
---|
443 | 489 | static int ddebug_exec_query(char *query_string, const char *modname) |
---|
444 | 490 | { |
---|
445 | | - unsigned int flags = 0, mask = 0; |
---|
446 | | - struct ddebug_query query; |
---|
| 491 | + struct flag_settings modifiers = {}; |
---|
| 492 | + struct ddebug_query query = {}; |
---|
447 | 493 | #define MAXWORDS 9 |
---|
448 | 494 | int nwords, nfound; |
---|
449 | 495 | char *words[MAXWORDS]; |
---|
.. | .. |
---|
454 | 500 | return -EINVAL; |
---|
455 | 501 | } |
---|
456 | 502 | /* check flags 1st (last arg) so query is pairs of spec,val */ |
---|
457 | | - if (ddebug_parse_flags(words[nwords-1], &flags, &mask)) { |
---|
| 503 | + if (ddebug_parse_flags(words[nwords-1], &modifiers)) { |
---|
458 | 504 | pr_err("flags parse failed\n"); |
---|
459 | 505 | return -EINVAL; |
---|
460 | 506 | } |
---|
.. | .. |
---|
463 | 509 | return -EINVAL; |
---|
464 | 510 | } |
---|
465 | 511 | /* actually go and implement the change */ |
---|
466 | | - nfound = ddebug_change(&query, flags, mask); |
---|
| 512 | + nfound = ddebug_change(&query, &modifiers); |
---|
467 | 513 | vpr_info_dq(&query, nfound ? "applied" : "no-match"); |
---|
468 | 514 | |
---|
469 | 515 | return nfound; |
---|
.. | .. |
---|
635 | 681 | |
---|
636 | 682 | #endif |
---|
637 | 683 | |
---|
| 684 | +#if IS_ENABLED(CONFIG_INFINIBAND) |
---|
| 685 | + |
---|
| 686 | +void __dynamic_ibdev_dbg(struct _ddebug *descriptor, |
---|
| 687 | + const struct ib_device *ibdev, const char *fmt, ...) |
---|
| 688 | +{ |
---|
| 689 | + struct va_format vaf; |
---|
| 690 | + va_list args; |
---|
| 691 | + |
---|
| 692 | + va_start(args, fmt); |
---|
| 693 | + |
---|
| 694 | + vaf.fmt = fmt; |
---|
| 695 | + vaf.va = &args; |
---|
| 696 | + |
---|
| 697 | + if (ibdev && ibdev->dev.parent) { |
---|
| 698 | + char buf[PREFIX_SIZE]; |
---|
| 699 | + |
---|
| 700 | + dev_printk_emit(LOGLEVEL_DEBUG, ibdev->dev.parent, |
---|
| 701 | + "%s%s %s %s: %pV", |
---|
| 702 | + dynamic_emit_prefix(descriptor, buf), |
---|
| 703 | + dev_driver_string(ibdev->dev.parent), |
---|
| 704 | + dev_name(ibdev->dev.parent), |
---|
| 705 | + dev_name(&ibdev->dev), |
---|
| 706 | + &vaf); |
---|
| 707 | + } else if (ibdev) { |
---|
| 708 | + printk(KERN_DEBUG "%s: %pV", dev_name(&ibdev->dev), &vaf); |
---|
| 709 | + } else { |
---|
| 710 | + printk(KERN_DEBUG "(NULL ib_device): %pV", &vaf); |
---|
| 711 | + } |
---|
| 712 | + |
---|
| 713 | + va_end(args); |
---|
| 714 | +} |
---|
| 715 | +EXPORT_SYMBOL(__dynamic_ibdev_dbg); |
---|
| 716 | + |
---|
| 717 | +#endif |
---|
| 718 | + |
---|
638 | 719 | #define DDEBUG_STRING_SIZE 1024 |
---|
639 | 720 | static __initdata char ddebug_setup_string[DDEBUG_STRING_SIZE]; |
---|
640 | 721 | |
---|
.. | .. |
---|
733 | 814 | struct _ddebug *dp; |
---|
734 | 815 | int n = *pos; |
---|
735 | 816 | |
---|
736 | | - vpr_info("called m=%p *pos=%lld\n", m, (unsigned long long)*pos); |
---|
737 | | - |
---|
738 | 817 | mutex_lock(&ddebug_lock); |
---|
739 | 818 | |
---|
740 | 819 | if (!n) |
---|
.. | .. |
---|
757 | 836 | struct ddebug_iter *iter = m->private; |
---|
758 | 837 | struct _ddebug *dp; |
---|
759 | 838 | |
---|
760 | | - vpr_info("called m=%p p=%p *pos=%lld\n", |
---|
761 | | - m, p, (unsigned long long)*pos); |
---|
762 | | - |
---|
763 | 839 | if (p == SEQ_START_TOKEN) |
---|
764 | 840 | dp = ddebug_iter_first(iter); |
---|
765 | 841 | else |
---|
.. | .. |
---|
779 | 855 | struct ddebug_iter *iter = m->private; |
---|
780 | 856 | struct _ddebug *dp = p; |
---|
781 | 857 | struct flagsbuf flags; |
---|
782 | | - |
---|
783 | | - vpr_info("called m=%p p=%p\n", m, p); |
---|
784 | 858 | |
---|
785 | 859 | if (p == SEQ_START_TOKEN) { |
---|
786 | 860 | seq_puts(m, |
---|
.. | .. |
---|
804 | 878 | */ |
---|
805 | 879 | static void ddebug_proc_stop(struct seq_file *m, void *p) |
---|
806 | 880 | { |
---|
807 | | - vpr_info("called m=%p p=%p\n", m, p); |
---|
808 | 881 | mutex_unlock(&ddebug_lock); |
---|
809 | 882 | } |
---|
810 | 883 | |
---|
.. | .. |
---|
815 | 888 | .stop = ddebug_proc_stop |
---|
816 | 889 | }; |
---|
817 | 890 | |
---|
818 | | -/* |
---|
819 | | - * File_ops->open method for <debugfs>/dynamic_debug/control. Does |
---|
820 | | - * the seq_file setup dance, and also creates an iterator to walk the |
---|
821 | | - * _ddebugs. Note that we create a seq_file always, even for O_WRONLY |
---|
822 | | - * files where it's not needed, as doing so simplifies the ->release |
---|
823 | | - * method. |
---|
824 | | - */ |
---|
825 | 891 | static int ddebug_proc_open(struct inode *inode, struct file *file) |
---|
826 | 892 | { |
---|
827 | 893 | vpr_info("called\n"); |
---|
.. | .. |
---|
838 | 904 | .write = ddebug_proc_write |
---|
839 | 905 | }; |
---|
840 | 906 | |
---|
| 907 | +static const struct proc_ops proc_fops = { |
---|
| 908 | + .proc_open = ddebug_proc_open, |
---|
| 909 | + .proc_read = seq_read, |
---|
| 910 | + .proc_lseek = seq_lseek, |
---|
| 911 | + .proc_release = seq_release_private, |
---|
| 912 | + .proc_write = ddebug_proc_write |
---|
| 913 | +}; |
---|
| 914 | + |
---|
841 | 915 | /* |
---|
842 | 916 | * Allocate a new ddebug_table for the given module |
---|
843 | 917 | * and add it to the global list. |
---|
.. | .. |
---|
846 | 920 | const char *name) |
---|
847 | 921 | { |
---|
848 | 922 | struct ddebug_table *dt; |
---|
849 | | - const char *new_name; |
---|
850 | 923 | |
---|
851 | 924 | dt = kzalloc(sizeof(*dt), GFP_KERNEL); |
---|
852 | | - if (dt == NULL) |
---|
853 | | - return -ENOMEM; |
---|
854 | | - new_name = kstrdup_const(name, GFP_KERNEL); |
---|
855 | | - if (new_name == NULL) { |
---|
856 | | - kfree(dt); |
---|
| 925 | + if (dt == NULL) { |
---|
| 926 | + pr_err("error adding module: %s\n", name); |
---|
857 | 927 | return -ENOMEM; |
---|
858 | 928 | } |
---|
859 | | - dt->mod_name = new_name; |
---|
| 929 | + /* |
---|
| 930 | + * For built-in modules, name lives in .rodata and is |
---|
| 931 | + * immortal. For loaded modules, name points at the name[] |
---|
| 932 | + * member of struct module, which lives at least as long as |
---|
| 933 | + * this struct ddebug_table. |
---|
| 934 | + */ |
---|
| 935 | + dt->mod_name = name; |
---|
860 | 936 | dt->num_ddebugs = n; |
---|
861 | 937 | dt->ddebugs = tab; |
---|
862 | 938 | |
---|
863 | 939 | mutex_lock(&ddebug_lock); |
---|
864 | | - list_add_tail(&dt->link, &ddebug_tables); |
---|
| 940 | + list_add(&dt->link, &ddebug_tables); |
---|
865 | 941 | mutex_unlock(&ddebug_lock); |
---|
866 | 942 | |
---|
867 | | - vpr_info("%u debug prints in module %s\n", n, dt->mod_name); |
---|
| 943 | + v2pr_info("%3u debug prints in module %s\n", n, dt->mod_name); |
---|
868 | 944 | return 0; |
---|
869 | 945 | } |
---|
870 | | -EXPORT_SYMBOL_GPL(ddebug_add_module); |
---|
871 | 946 | |
---|
872 | 947 | /* helper for ddebug_dyndbg_(boot|module)_param_cb */ |
---|
873 | 948 | static int ddebug_dyndbg_param_cb(char *param, char *val, |
---|
.. | .. |
---|
912 | 987 | static void ddebug_table_free(struct ddebug_table *dt) |
---|
913 | 988 | { |
---|
914 | 989 | list_del_init(&dt->link); |
---|
915 | | - kfree_const(dt->mod_name); |
---|
916 | 990 | kfree(dt); |
---|
917 | 991 | } |
---|
918 | 992 | |
---|
.. | .. |
---|
925 | 999 | struct ddebug_table *dt, *nextdt; |
---|
926 | 1000 | int ret = -ENOENT; |
---|
927 | 1001 | |
---|
928 | | - vpr_info("removing module \"%s\"\n", mod_name); |
---|
| 1002 | + v2pr_info("removing module \"%s\"\n", mod_name); |
---|
929 | 1003 | |
---|
930 | 1004 | mutex_lock(&ddebug_lock); |
---|
931 | 1005 | list_for_each_entry_safe(dt, nextdt, &ddebug_tables, link) { |
---|
932 | | - if (!strcmp(dt->mod_name, mod_name)) { |
---|
| 1006 | + if (dt->mod_name == mod_name) { |
---|
933 | 1007 | ddebug_table_free(dt); |
---|
934 | 1008 | ret = 0; |
---|
| 1009 | + break; |
---|
935 | 1010 | } |
---|
936 | 1011 | } |
---|
937 | 1012 | mutex_unlock(&ddebug_lock); |
---|
938 | 1013 | return ret; |
---|
939 | 1014 | } |
---|
940 | | -EXPORT_SYMBOL_GPL(ddebug_remove_module); |
---|
941 | 1015 | |
---|
942 | 1016 | static void ddebug_remove_all_tables(void) |
---|
943 | 1017 | { |
---|
.. | .. |
---|
971 | 1045 | /* Also create the control file in procfs */ |
---|
972 | 1046 | procfs_dir = proc_mkdir("dynamic_debug", NULL); |
---|
973 | 1047 | if (procfs_dir) |
---|
974 | | - proc_create("control", 0644, procfs_dir, &ddebug_proc_fops); |
---|
| 1048 | + proc_create("control", 0644, procfs_dir, &proc_fops); |
---|
975 | 1049 | |
---|
976 | 1050 | return 0; |
---|
977 | 1051 | } |
---|
.. | .. |
---|
983 | 1057 | char *cmdline; |
---|
984 | 1058 | int ret = 0; |
---|
985 | 1059 | int n = 0, entries = 0, modct = 0; |
---|
986 | | - int verbose_bytes = 0; |
---|
987 | 1060 | |
---|
988 | | - if (__start___verbose == __stop___verbose) { |
---|
989 | | - pr_warn("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n"); |
---|
990 | | - return 1; |
---|
| 1061 | + if (&__start___dyndbg == &__stop___dyndbg) { |
---|
| 1062 | + if (IS_ENABLED(CONFIG_DYNAMIC_DEBUG)) { |
---|
| 1063 | + pr_warn("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n"); |
---|
| 1064 | + return 1; |
---|
| 1065 | + } |
---|
| 1066 | + pr_info("Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build\n"); |
---|
| 1067 | + ddebug_init_success = 1; |
---|
| 1068 | + return 0; |
---|
991 | 1069 | } |
---|
992 | | - iter = __start___verbose; |
---|
| 1070 | + iter = __start___dyndbg; |
---|
993 | 1071 | modname = iter->modname; |
---|
994 | 1072 | iter_start = iter; |
---|
995 | | - for (; iter < __stop___verbose; iter++) { |
---|
| 1073 | + for (; iter < __stop___dyndbg; iter++) { |
---|
996 | 1074 | entries++; |
---|
997 | | - verbose_bytes += strlen(iter->modname) + strlen(iter->function) |
---|
998 | | - + strlen(iter->filename) + strlen(iter->format); |
---|
999 | | - |
---|
1000 | 1075 | if (strcmp(modname, iter->modname)) { |
---|
1001 | 1076 | modct++; |
---|
1002 | 1077 | ret = ddebug_add_module(iter_start, n, modname); |
---|
.. | .. |
---|
1013 | 1088 | goto out_err; |
---|
1014 | 1089 | |
---|
1015 | 1090 | ddebug_init_success = 1; |
---|
1016 | | - vpr_info("%d modules, %d entries and %d bytes in ddebug tables, %d bytes in (readonly) verbose section\n", |
---|
| 1091 | + vpr_info("%d modules, %d entries and %d bytes in ddebug tables, %d bytes in __dyndbg section\n", |
---|
1017 | 1092 | modct, entries, (int)(modct * sizeof(struct ddebug_table)), |
---|
1018 | | - verbose_bytes + (int)(__stop___verbose - __start___verbose)); |
---|
| 1093 | + (int)(entries * sizeof(struct _ddebug))); |
---|
1019 | 1094 | |
---|
1020 | 1095 | /* apply ddebug_query boot param, dont unload tables on err */ |
---|
1021 | 1096 | if (ddebug_setup_string[0] != '\0') { |
---|