FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
linux/lib/dynamic_debug.c at master · multikernel/linux · GitHub
multikernel
/
linux
Public
forked from
torvalds/linux
Notifications
You must be signed in to change notification settings
Fork
15
Star
180
Code
Issues
27
Pull requests
5
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
linux
/
lib
/
dynamic_debug.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
1495 lines (1287 loc) · 37.7 KB
Breadcrumbs
linux
/
lib
/
dynamic_debug.c
Copy path
File metadata and controls
1495 lines (1287 loc) · 37.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* lib/dynamic_debug.c
*
* make pr_debug()/dev_dbg() calls runtime configurable based upon their
* source module.
*
* Copyright (C) 2008 Jason Baron <jbaron@redhat.com>
* By Greg Banks <gnb@melbourne.sgi.com>
* Copyright (c) 2008 Silicon Graphics Inc. All Rights Reserved.
* Copyright (C) 2011 Bart Van Assche. All Rights Reserved.
* Copyright (C) 2013 Du, Changbin <changbin.du@gmail.com>
*/
#define
pr_fmt
(
fmt
) "dyndbg: " fmt
#include
<linux/kernel.h>
#include
<linux/module.h>
#include
<linux/moduleparam.h>
#include
<linux/kallsyms.h>
#include
<linux/types.h>
#include
<linux/mutex.h>
#include
<linux/proc_fs.h>
#include
<linux/seq_file.h>
#include
<linux/list.h>
#include
<linux/sysctl.h>
#include
<linux/ctype.h>
#include
<linux/string.h>
#include
<linux/parser.h>
#include
<linux/string_helpers.h>
#include
<linux/uaccess.h>
#include
<linux/dynamic_debug.h>
#include
<linux/debugfs.h>
#include
<linux/slab.h>
#include
<linux/jump_label.h>
#include
<linux/hardirq.h>
#include
<linux/sched.h>
#include
<linux/device.h>
#include
<linux/netdevice.h>
#include
<rdma/ib_verbs.h>
extern
struct
_ddebug
__start___dyndbg
[];
extern
struct
_ddebug
__stop___dyndbg
[];
extern
struct
ddebug_class_map
__start___dyndbg_classes
[];
extern
struct
ddebug_class_map
__stop___dyndbg_classes
[];
struct
ddebug_table
{
struct
list_head
link
,
maps
;
const
char
*
mod_name
;
unsigned
int
num_ddebugs
;
struct
_ddebug
*
ddebugs
;
};
struct
ddebug_query
{
const
char
*
filename
;
const
char
*
module
;
const
char
*
function
;
const
char
*
format
;
const
char
*
class_string
;
unsigned
int
first_lineno
,
last_lineno
;
};
struct
ddebug_iter
{
struct
ddebug_table
*
table
;
int
idx
;
};
struct
flag_settings
{
unsigned
int
flags
;
unsigned
int
mask
;
};
static
DEFINE_MUTEX
(
ddebug_lock
);
static
LIST_HEAD
(
ddebug_tables
);
static
int
verbose
;
module_param
(
verbose
,
int
,
0644
);
MODULE_PARM_DESC
(
verbose
,
" dynamic_debug/control processing "
"( 0 = off (default), 1 = module add/rm, 2 = >control summary, 3 = parsing, 4 = per-site changes)"
);
/* Return the path relative to source root */
static
inline
const
char
*
trim_prefix
(
const
char
*
path
)
{
int
skip
=
strlen
(
__FILE__
)
-
strlen
(
"lib/dynamic_debug.c"
);
if
(
strncmp
(
path
,
__FILE__
,
skip
))
skip
=
0
;
/* prefix mismatch, don't skip */
return
path
+
skip
;
}
static
const
struct
{
unsigned
flag
:
8
;
char
opt_char
; }
opt_array
[]
=
{
{
_DPRINTK_FLAGS_PRINT
,
'p'
},
{
_DPRINTK_FLAGS_INCL_MODNAME
,
'm'
},
{
_DPRINTK_FLAGS_INCL_FUNCNAME
,
'f'
},
{
_DPRINTK_FLAGS_INCL_SOURCENAME
,
's'
},
{
_DPRINTK_FLAGS_INCL_LINENO
,
'l'
},
{
_DPRINTK_FLAGS_INCL_TID
,
't'
},
{
_DPRINTK_FLAGS_INCL_STACK
,
'd'
},
{
_DPRINTK_FLAGS_NONE
,
'_'
},
};
struct
flagsbuf
{
char
buf
[
ARRAY_SIZE
(
opt_array
)
+
1
]; };
/* format a string into buf[] which describes the _ddebug's flags */
static
char
*
ddebug_describe_flags
(
unsigned
int
flags
,
struct
flagsbuf
*
fb
)
{
char
*
p
=
fb
->
buf
;
int
i
;
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
opt_array
);
++
i
)
if
(
flags
&
opt_array
[
i
].
flag
)
*
p
++
=
opt_array
[
i
].
opt_char
;
if
(
p
==
fb
->
buf
)
*
p
++
=
'_'
;
*
p
=
'\0'
;
return
fb
->
buf
;
}
#define
vnpr_info
(
lvl
,
fmt
, ...) \
do { \
if (verbose >= lvl) \
pr_info(fmt, ##__VA_ARGS__); \
} while (0)
#define
vpr_info
(
fmt
, ...) vnpr_info(1, fmt, ##__VA_ARGS__)
#define
v2pr_info
(
fmt
, ...) vnpr_info(2, fmt, ##__VA_ARGS__)
#define
v3pr_info
(
fmt
, ...) vnpr_info(3, fmt, ##__VA_ARGS__)
#define
v4pr_info
(
fmt
, ...) vnpr_info(4, fmt, ##__VA_ARGS__)
static
void
vpr_info_dq
(
const
struct
ddebug_query
*
query
,
const
char
*
msg
)
{
/* trim any trailing newlines */
int
fmtlen
=
0
;
if
(
query
->
format
) {
fmtlen
=
strlen
(
query
->
format
);
while
(
fmtlen
&&
query
->
format
[
fmtlen
-
1
]
==
'\n'
)
fmtlen
--
;
}
v3pr_info
(
"%s: func=\"%s\" file=\"%s\" module=\"%s\" format=\"%.*s\" lineno=%u-%u class=%s\n"
,
msg
,
query
->
function
?:
""
,
query
->
filename
?:
""
,
query
->
module
?:
""
,
fmtlen
,
query
->
format
?:
""
,
query
->
first_lineno
,
query
->
last_lineno
,
query
->
class_string
);
}
static
struct
ddebug_class_map
*
ddebug_find_valid_class
(
struct
ddebug_table
const
*
dt
,
const
char
*
class_string
,
int
*
class_id
)
{
struct
ddebug_class_map
*
map
;
int
idx
;
list_for_each_entry
(
map
,
&
dt
->
maps
,
link
) {
idx
=
match_string
(
map
->
class_names
,
map
->
length
,
class_string
);
if
(
idx
>=
0
) {
*
class_id
=
idx
+
map
->
base
;
return
map
;
}
}
*
class_id
=
-
ENOENT
;
return
NULL
;
}
#define
__outvar
/* filled by callee */
/*
* Search the tables for _ddebug's which match the given `query' and
* apply the `flags' and `mask' to them. Returns number of matching
* callsites, normally the same as number of changes. If verbose,
* logs the changes. Takes ddebug_lock.
*/
static
int
ddebug_change
(
const
struct
ddebug_query
*
query
,
struct
flag_settings
*
modifiers
)
{
int
i
;
struct
ddebug_table
*
dt
;
unsigned
int
newflags
;
unsigned
int
nfound
=
0
;
struct
flagsbuf
fbuf
,
nbuf
;
struct
ddebug_class_map
*
map
=
NULL
;
int
__outvar
valid_class
;
/* search for matching ddebugs */
mutex_lock
(
&
ddebug_lock
);
list_for_each_entry
(
dt
,
&
ddebug_tables
,
link
) {
/* match against the module name */
if
(
query
->
module
&&
!
match_wildcard
(
query
->
module
,
dt
->
mod_name
))
continue
;
if
(
query
->
class_string
) {
map
=
ddebug_find_valid_class
(
dt
,
query
->
class_string
,
&
valid_class
);
if
(!
map
)
continue
;
}
else
{
/* constrain query, do not touch class'd callsites */
valid_class
=
_DPRINTK_CLASS_DFLT
;
}
for
(
i
=
0
;
i
<
dt
->
num_ddebugs
;
i
++
) {
struct
_ddebug
*
dp
=
&
dt
->
ddebugs
[
i
];
/* match site against query-class */
if
(
dp
->
class_id
!=
valid_class
)
continue
;
/* match against the source filename */
if
(
query
->
filename
&&
!
match_wildcard
(
query
->
filename
,
dp
->
filename
)
&&
!
match_wildcard
(
query
->
filename
,
kbasename
(
dp
->
filename
))
&&
!
match_wildcard
(
query
->
filename
,
trim_prefix
(
dp
->
filename
)))
continue
;
/* match against the function */
if
(
query
->
function
&&
!
match_wildcard
(
query
->
function
,
dp
->
function
))
continue
;
/* match against the format */
if
(
query
->
format
) {
if
(
*
query
->
format
==
'^'
) {
char
*
p
;
/* anchored search. match must be at beginning */
p
=
strstr
(
dp
->
format
,
query
->
format
+
1
);
if
(
p
!=
dp
->
format
)
continue
;
}
else
if
(!
strstr
(
dp
->
format
,
query
->
format
))
continue
;
}
/* match against the line number range */
if
(
query
->
first_lineno
&&
dp
->
lineno
<
query
->
first_lineno
)
continue
;
if
(
query
->
last_lineno
&&
dp
->
lineno
>
query
->
last_lineno
)
continue
;
nfound
++
;
newflags
=
(
dp
->
flags
&
modifiers
->
mask
) |
modifiers
->
flags
;
if
(
newflags
==
dp
->
flags
)
continue
;
#ifdef
CONFIG_JUMP_LABEL
if
(
dp
->
flags
&
_DPRINTK_FLAGS_PRINT
) {
if
(!(
newflags
&
_DPRINTK_FLAGS_PRINT
))
static_branch_disable
(
&
dp
->
key
.
dd_key_true
);
}
else
if
(
newflags
&
_DPRINTK_FLAGS_PRINT
) {
static_branch_enable
(
&
dp
->
key
.
dd_key_true
);
}
#endif
v4pr_info
(
"changed %s:%d [%s]%s %s => %s\n"
,
trim_prefix
(
dp
->
filename
),
dp
->
lineno
,
dt
->
mod_name
,
dp
->
function
,
ddebug_describe_flags
(
dp
->
flags
,
&
fbuf
),
ddebug_describe_flags
(
newflags
,
&
nbuf
));
dp
->
flags
=
newflags
;
}
}
mutex_unlock
(
&
ddebug_lock
);
if
(!
nfound
&&
verbose
)
pr_info
(
"no matches for query\n"
);
return
nfound
;
}
/*
* Split the buffer `buf' into space-separated words.
* Handles simple " and ' quoting, i.e. without nested,
* embedded or escaped \". Return the number of words
* or <0 on error.
*/
static
int
ddebug_tokenize
(
char
*
buf
,
char
*
words
[],
int
maxwords
)
{
int
nwords
=
0
;
while
(
*
buf
) {
char
*
end
;
/* Skip leading whitespace */
buf
=
skip_spaces
(
buf
);
if
(!
*
buf
)
break
;
/* oh, it was trailing whitespace */
if
(
*
buf
==
'#'
)
break
;
/* token starts comment, skip rest of line */
/* find `end' of word, whitespace separated or quoted */
if
(
*
buf
==
'"'
||
*
buf
==
'\''
) {
int
quote
=
*
buf
++
;
for
(
end
=
buf
;
*
end
&&
*
end
!=
quote
;
end
++
)
;
if
(!
*
end
) {
pr_err
(
"unclosed quote: %s\n"
,
buf
);
return
-
EINVAL
;
/* unclosed quote */
}
}
else
{
for
(
end
=
buf
;
*
end
&&
!
isspace
(
*
end
);
end
++
)
;
if
(
end
==
buf
) {
pr_err
(
"parse err after word:%d=%s\n"
,
nwords
,
nwords
?
words
[
nwords
-
1
] :
"<none>"
);
return
-
EINVAL
;
}
}
/* `buf' is start of word, `end' is one past its end */
if
(
nwords
==
maxwords
) {
pr_err
(
"too many words, legal max <=%d\n"
,
maxwords
);
return
-
EINVAL
;
/* ran out of words[] before bytes */
}
if
(
*
end
)
*
end
++
=
'\0'
;
/* terminate the word */
words
[
nwords
++
]
=
buf
;
buf
=
end
;
}
if
(
verbose
>=
3
) {
int
i
;
pr_info
(
"split into words:"
);
for
(
i
=
0
;
i
<
nwords
;
i
++
)
pr_cont
(
" \"%s\""
,
words
[
i
]);
pr_cont
(
"\n"
);
}
return
nwords
;
}
/*
* Parse a single line number. Note that the empty string ""
* is treated as a special case and converted to zero, which
* is later treated as a "don't care" value.
*/
static
inline
int
parse_lineno
(
const
char
*
str
,
unsigned
int
*
val
)
{
BUG_ON
(
str
==
NULL
);
if
(
*
str
==
'\0'
) {
*
val
=
0
;
return
0
;
}
if
(
kstrtouint
(
str
,
10
,
val
)
<
0
) {
pr_err
(
"bad line-number: %s\n"
,
str
);
return
-
EINVAL
;
}
return
0
;
}
static
int
parse_linerange
(
struct
ddebug_query
*
query
,
const
char
*
first
)
{
char
*
last
=
strchr
(
first
,
'-'
);
if
(
query
->
first_lineno
||
query
->
last_lineno
) {
pr_err
(
"match-spec: line used 2x\n"
);
return
-
EINVAL
;
}
if
(
last
)
*
last
++
=
'\0'
;
if
(
parse_lineno
(
first
,
&
query
->
first_lineno
)
<
0
)
return
-
EINVAL
;
if
(
last
) {
/* range <first>-<last> */
if
(
parse_lineno
(
last
,
&
query
->
last_lineno
)
<
0
)
return
-
EINVAL
;
/* special case for last lineno not specified */
if
(
query
->
last_lineno
==
0
)
query
->
last_lineno
=
UINT_MAX
;
if
(
query
->
last_lineno
<
query
->
first_lineno
) {
pr_err
(
"last-line:%d < 1st-line:%d\n"
,
query
->
last_lineno
,
query
->
first_lineno
);
return
-
EINVAL
;
}
}
else
{
query
->
last_lineno
=
query
->
first_lineno
;
}
v3pr_info
(
"parsed line %d-%d\n"
,
query
->
first_lineno
,
query
->
last_lineno
);
return
0
;
}
static
int
check_set
(
const
char
*
*
dest
,
char
*
src
,
char
*
name
)
{
int
rc
=
0
;
if
(
*
dest
) {
rc
=
-
EINVAL
;
pr_err
(
"match-spec:%s val:%s overridden by %s\n"
,
name
,
*
dest
,
src
);
}
*
dest
=
src
;
return
rc
;
}
/*
* Parse words[] as a ddebug query specification, which is a series
* of (keyword, value) pairs chosen from these possibilities:
*
* func <function-name>
* file <full-pathname>
* file <base-filename>
* module <module-name>
* format <escaped-string-to-find-in-format>
* line <lineno>
* line <first-lineno>-<last-lineno> // where either may be empty
*
* Only 1 of each type is allowed.
* Returns 0 on success, <0 on error.
*/
static
int
ddebug_parse_query
(
char
*
words
[],
int
nwords
,
struct
ddebug_query
*
query
,
const
char
*
modname
)
{
unsigned
int
i
;
int
rc
=
0
;
char
*
fline
;
/* check we have an even number of words */
if
(
nwords
%
2
!=
0
) {
pr_err
(
"expecting pairs of match-spec <value>\n"
);
return
-
EINVAL
;
}
for
(
i
=
0
;
i
<
nwords
;
i
+=
2
) {
char
*
keyword
=
words
[
i
];
char
*
arg
=
words
[
i
+
1
];
if
(!
strcmp
(
keyword
,
"func"
)) {
rc
=
check_set
(
&
query
->
function
,
arg
,
"func"
);
}
else
if
(!
strcmp
(
keyword
,
"file"
)) {
if
(
check_set
(
&
query
->
filename
,
arg
,
"file"
))
return
-
EINVAL
;
/* tail :$info is function or line-range */
fline
=
strchr
(
query
->
filename
,
':'
);
if
(!
fline
)
continue
;
*
fline
++
=
'\0'
;
if
(
isalpha
(
*
fline
)
||
*
fline
==
'*'
||
*
fline
==
'?'
) {
/* take as function name */
if
(
check_set
(
&
query
->
function
,
fline
,
"func"
))
return
-
EINVAL
;
}
else
{
if
(
parse_linerange
(
query
,
fline
))
return
-
EINVAL
;
}
}
else
if
(!
strcmp
(
keyword
,
"module"
)) {
rc
=
check_set
(
&
query
->
module
,
arg
,
"module"
);
}
else
if
(!
strcmp
(
keyword
,
"format"
)) {
string_unescape_inplace
(
arg
,
UNESCAPE_SPACE
|
UNESCAPE_OCTAL
|
UNESCAPE_SPECIAL
);
rc
=
check_set
(
&
query
->
format
,
arg
,
"format"
);
}
else
if
(!
strcmp
(
keyword
,
"line"
)) {
if
(
parse_linerange
(
query
,
arg
))
return
-
EINVAL
;
}
else
if
(!
strcmp
(
keyword
,
"class"
)) {
rc
=
check_set
(
&
query
->
class_string
,
arg
,
"class"
);
}
else
{
pr_err
(
"unknown keyword \"%s\"\n"
,
keyword
);
return
-
EINVAL
;
}
if
(
rc
)
return
rc
;
}
if
(!
query
->
module
&&
modname
)
/*
* support $modname.dyndbg=<multiple queries>, when
* not given in the query itself
*/
query
->
module
=
modname
;
vpr_info_dq
(
query
,
"parsed"
);
return
0
;
}
/*
* Parse `str' as a flags specification, format [-+=][p]+.
* Sets up *maskp and *flagsp to be used when changing the
* flags fields of matched _ddebug's. Returns 0 on success
* or <0 on error.
*/
static
int
ddebug_parse_flags
(
const
char
*
str
,
struct
flag_settings
*
modifiers
)
{
int
op
,
i
;
switch
(
*
str
) {
case
'+'
:
case
'-'
:
case
'='
:
op
=
*
str
++
;
break
;
default
:
pr_err
(
"bad flag-op %c, at start of %s\n"
,
*
str
,
str
);
return
-
EINVAL
;
}
v3pr_info
(
"op='%c'\n"
,
op
);
for
(;
*
str
;
++
str
) {
for
(
i
=
ARRAY_SIZE
(
opt_array
)
-
1
;
i
>=
0
;
i
--
) {
if
(
*
str
==
opt_array
[
i
].
opt_char
) {
modifiers
->
flags
|=
opt_array
[
i
].
flag
;
break
;
}
}
if
(
i
<
0
) {
pr_err
(
"unknown flag '%c'\n"
,
*
str
);
return
-
EINVAL
;
}
}
v3pr_info
(
"flags=0x%x\n"
,
modifiers
->
flags
);
/* calculate final flags, mask based upon op */
switch
(
op
) {
case
'='
:
/* modifiers->flags already set */
modifiers
->
mask
=
0
;
break
;
case
'+'
:
modifiers
->
mask
=
~
0U
;
break
;
case
'-'
:
modifiers
->
mask
=
~
modifiers
->
flags
;
modifiers
->
flags
=
0
;
break
;
}
v3pr_info
(
"*flagsp=0x%x *maskp=0x%x\n"
,
modifiers
->
flags
,
modifiers
->
mask
);
return
0
;
}
static
int
ddebug_exec_query
(
char
*
query_string
,
const
char
*
modname
)
{
struct
flag_settings
modifiers
=
{};
struct
ddebug_query
query
=
{};
#define
MAXWORDS
9
int
nwords
,
nfound
;
char
*
words
[
MAXWORDS
];
nwords
=
ddebug_tokenize
(
query_string
,
words
,
MAXWORDS
);
if
(
nwords
<=
0
) {
pr_err
(
"tokenize failed\n"
);
return
-
EINVAL
;
}
/* check flags 1st (last arg) so query is pairs of spec,val */
if
(
ddebug_parse_flags
(
words
[
nwords
-
1
],
&
modifiers
)) {
pr_err
(
"flags parse failed\n"
);
return
-
EINVAL
;
}
if
(
ddebug_parse_query
(
words
,
nwords
-
1
,
&
query
,
modname
)) {
pr_err
(
"query parse failed\n"
);
return
-
EINVAL
;
}
/* actually go and implement the change */
nfound
=
ddebug_change
(
&
query
,
&
modifiers
);
vpr_info_dq
(
&
query
,
nfound
?
"applied"
:
"no-match"
);
return
nfound
;
}
/* handle multiple queries in query string, continue on error, return
last error or number of matching callsites. Module name is either
in param (for boot arg) or perhaps in query string.
*/
static
int
ddebug_exec_queries
(
char
*
query
,
const
char
*
modname
)
{
char
*
split
;
int
i
,
errs
=
0
,
exitcode
=
0
,
rc
,
nfound
=
0
;
for
(
i
=
0
;
query
;
query
=
split
) {
split
=
strpbrk
(
query
,
";\n"
);
if
(
split
)
*
split
++
=
'\0'
;
query
=
skip_spaces
(
query
);
if
(!
query
||
!
*
query
||
*
query
==
'#'
)
continue
;
vpr_info
(
"query %d: \"%s\" mod:%s\n"
,
i
,
query
,
modname
?:
"*"
);
rc
=
ddebug_exec_query
(
query
,
modname
);
if
(
rc
<
0
) {
errs
++
;
exitcode
=
rc
;
}
else
{
nfound
+=
rc
;
}
i
++
;
}
if
(
i
)
v2pr_info
(
"processed %d queries, with %d matches, %d errs\n"
,
i
,
nfound
,
errs
);
if
(
exitcode
)
return
exitcode
;
return
nfound
;
}
/* apply a new bitmap to the sys-knob's current bit-state */
static
int
ddebug_apply_class_bitmap
(
const
struct
ddebug_class_param
*
dcp
,
unsigned long
*
new_bits
,
unsigned long
*
old_bits
)
{
#define
QUERY_SIZE
128
char
query
[
QUERY_SIZE
];
const
struct
ddebug_class_map
*
map
=
dcp
->
map
;
int
matches
=
0
;
int
bi
,
ct
;
v2pr_info
(
"apply: 0x%lx to: 0x%lx\n"
,
*
new_bits
,
*
old_bits
);
for
(
bi
=
0
;
bi
<
map
->
length
;
bi
++
) {
if
(
test_bit
(
bi
,
new_bits
)
==
test_bit
(
bi
,
old_bits
))
continue
;
snprintf
(
query
,
QUERY_SIZE
,
"class %s %c%s"
,
map
->
class_names
[
bi
],
test_bit
(
bi
,
new_bits
) ?
'+'
:
'-'
,
dcp
->
flags
);
ct
=
ddebug_exec_queries
(
query
,
NULL
);
matches
+=
ct
;
v2pr_info
(
"bit_%d: %d matches on class: %s -> 0x%lx\n"
,
bi
,
ct
,
map
->
class_names
[
bi
],
*
new_bits
);
}
return
matches
;
}
/* stub to later conditionally add "$module." prefix where not already done */
#define
KP_NAME
(
kp
) kp->name
#define
CLASSMAP_BITMASK
(
width
) ((1UL << (width)) - 1)
/* accept comma-separated-list of [+-] classnames */
static
int
param_set_dyndbg_classnames
(
const
char
*
instr
,
const
struct
kernel_param
*
kp
)
{
const
struct
ddebug_class_param
*
dcp
=
kp
->
arg
;
const
struct
ddebug_class_map
*
map
=
dcp
->
map
;
unsigned long
curr_bits
,
old_bits
;
char
*
cl_str
,
*
p
,
*
tmp
;
int
cls_id
,
totct
=
0
;
bool
wanted
;
cl_str
=
tmp
=
kstrdup_and_replace
(
instr
,
'\n'
,
'\0'
,
GFP_KERNEL
);
if
(!
tmp
)
return
-
ENOMEM
;
/* start with previously set state-bits, then modify */
curr_bits
=
old_bits
=
*
dcp
->
bits
;
vpr_info
(
"\"%s\" > %s:0x%lx\n"
,
cl_str
,
KP_NAME
(
kp
),
curr_bits
);
for
(;
cl_str
;
cl_str
=
p
) {
p
=
strchr
(
cl_str
,
','
);
if
(
p
)
*
p
++
=
'\0'
;
if
(
*
cl_str
==
'-'
) {
wanted
=
false;
cl_str
++
;
}
else
{
wanted
=
true;
if
(
*
cl_str
==
'+'
)
cl_str
++
;
}
cls_id
=
match_string
(
map
->
class_names
,
map
->
length
,
cl_str
);
if
(
cls_id
<
0
) {
pr_err
(
"%s unknown to %s\n"
,
cl_str
,
KP_NAME
(
kp
));
continue
;
}
/* have one or more valid class_ids of one *_NAMES type */
switch
(
map
->
map_type
) {
case
DD_CLASS_TYPE_DISJOINT_NAMES
:
/* the +/- pertains to a single bit */
if
(
test_bit
(
cls_id
,
&
curr_bits
)
==
wanted
) {
v3pr_info
(
"no change on %s\n"
,
cl_str
);
continue
;
}
curr_bits
^=
BIT
(
cls_id
);
totct
+=
ddebug_apply_class_bitmap
(
dcp
,
&
curr_bits
,
dcp
->
bits
);
*
dcp
->
bits
=
curr_bits
;
v2pr_info
(
"%s: changed bit %d:%s\n"
,
KP_NAME
(
kp
),
cls_id
,
map
->
class_names
[
cls_id
]);
break
;
case
DD_CLASS_TYPE_LEVEL_NAMES
:
/* cls_id = N in 0..max. wanted +/- determines N or N-1 */
old_bits
=
CLASSMAP_BITMASK
(
*
dcp
->
lvl
);
curr_bits
=
CLASSMAP_BITMASK
(
cls_id
+
(
wanted
?
1
:
0
));
totct
+=
ddebug_apply_class_bitmap
(
dcp
,
&
curr_bits
,
&
old_bits
);
*
dcp
->
lvl
=
(
cls_id
+
(
wanted
?
1
:
0
));
v2pr_info
(
"%s: changed bit-%d: \"%s\" %lx->%lx\n"
,
KP_NAME
(
kp
),
cls_id
,
map
->
class_names
[
cls_id
],
old_bits
,
curr_bits
);
break
;
default
:
pr_err
(
"illegal map-type value %d\n"
,
map
->
map_type
);
}
}
kfree
(
tmp
);
vpr_info
(
"total matches: %d\n"
,
totct
);
return
0
;
}
/**
* param_set_dyndbg_classes - class FOO >control
* @instr: string echo>d to sysfs, input depends on map_type
* @kp: kp->arg has state: bits/lvl, map, map_type
*
* Enable/disable prdbgs by their class, as given in the arguments to
* DECLARE_DYNDBG_CLASSMAP. For LEVEL map-types, enforce relative
* levels by bitpos.
*
* Returns: 0 or <0 if error.
*/
int
param_set_dyndbg_classes
(
const
char
*
instr
,
const
struct
kernel_param
*
kp
)
{
const
struct
ddebug_class_param
*
dcp
=
kp
->
arg
;
const
struct
ddebug_class_map
*
map
=
dcp
->
map
;
unsigned long
inrep
,
new_bits
,
old_bits
;
int
rc
,
totct
=
0
;
switch
(
map
->
map_type
) {
case
DD_CLASS_TYPE_DISJOINT_NAMES
:
case
DD_CLASS_TYPE_LEVEL_NAMES
:
/* handle [+-]classnames list separately, we are done here */
return
param_set_dyndbg_classnames
(
instr
,
kp
);
case
DD_CLASS_TYPE_DISJOINT_BITS
:
case
DD_CLASS_TYPE_LEVEL_NUM
:
/* numeric input, accept and fall-thru */
rc
=
kstrtoul
(
instr
,
0
,
&
inrep
);
if
(
rc
) {
pr_err
(
"expecting numeric input: %s > %s\n"
,
instr
,
KP_NAME
(
kp
));
return
-
EINVAL
;
}
break
;
default
:
pr_err
(
"%s: bad map type: %d\n"
,
KP_NAME
(
kp
),
map
->
map_type
);
return
-
EINVAL
;
}
/* only _BITS,_NUM (numeric) map-types get here */
switch
(
map
->
map_type
) {
case
DD_CLASS_TYPE_DISJOINT_BITS
:
/* expect bits. mask and warn if too many */
if
(
inrep
&
~
CLASSMAP_BITMASK
(
map
->
length
)) {
pr_warn
(
"%s: input: 0x%lx exceeds mask: 0x%lx, masking\n"
,
KP_NAME
(
kp
),
inrep
,
CLASSMAP_BITMASK
(
map
->
length
));
inrep
&=
CLASSMAP_BITMASK
(
map
->
length
);
}
v2pr_info
(
"bits:%lx > %s\n"
,
inrep
,
KP_NAME
(
kp
));
totct
+=
ddebug_apply_class_bitmap
(
dcp
,
&
inrep
,
dcp
->
bits
);
*
dcp
->
bits
=
inrep
;
break
;
case
DD_CLASS_TYPE_LEVEL_NUM
:
/* input is bitpos, of highest verbosity to be enabled */
if
(
inrep
>
map
->
length
) {
pr_warn
(
"%s: level:%ld exceeds max:%d, clamping\n"
,
KP_NAME
(
kp
),
inrep
,
map
->
length
);
inrep
=
map
->
length
;
}
old_bits
=
CLASSMAP_BITMASK
(
*
dcp
->
lvl
);
new_bits
=
CLASSMAP_BITMASK
(
inrep
);
v2pr_info
(
"lvl:%ld bits:0x%lx > %s\n"
,
inrep
,
new_bits
,
KP_NAME
(
kp
));
totct
+=
ddebug_apply_class_bitmap
(
dcp
,
&
new_bits
,
&
old_bits
);
*
dcp
->
lvl
=
inrep
;
break
;
default
:
pr_warn
(
"%s: bad map type: %d\n"
,
KP_NAME
(
kp
),
map
->
map_type
);
}
vpr_info
(
"%s: total matches: %d\n"
,
KP_NAME
(
kp
),
totct
);
return
0
;
}
EXPORT_SYMBOL
(
param_set_dyndbg_classes
);
/**
* param_get_dyndbg_classes - classes reader
* @buffer: string description of controlled bits -> classes
* @kp: kp->arg has state: bits, map
*
* Reads last written state, underlying prdbg state may have been
* altered by direct >control. Displays 0x for DISJOINT, 0-N for
* LEVEL Returns: #chars written or <0 on error
*/
int
param_get_dyndbg_classes
(
char
*
buffer
,
const
struct
kernel_param
*
kp
)
{
const
struct
ddebug_class_param
*
dcp
=
kp
->
arg
;
const
struct
ddebug_class_map
*
map
=
dcp
->
map
;
switch
(
map
->
map_type
) {
case
DD_CLASS_TYPE_DISJOINT_NAMES
:
case
DD_CLASS_TYPE_DISJOINT_BITS
:
return
scnprintf
(
buffer
,
PAGE_SIZE
,
"0x%lx\n"
,
*
dcp
->
bits
);
case
DD_CLASS_TYPE_LEVEL_NAMES
:
case
DD_CLASS_TYPE_LEVEL_NUM
:
return
scnprintf
(
buffer
,
PAGE_SIZE
,
"%d\n"
,
*
dcp
->
lvl
);
default
:
return
-1
;
}
}
EXPORT_SYMBOL
(
param_get_dyndbg_classes
);
const
struct
kernel_param_ops
param_ops_dyndbg_classes
=
{
.
set
=
param_set_dyndbg_classes
,
.
get
=
param_get_dyndbg_classes
,
};
EXPORT_SYMBOL
(
param_ops_dyndbg_classes
);
#define
PREFIX_SIZE
128
static
int
remaining
(
int
wrote
)
{
if
(
PREFIX_SIZE
-
wrote
>
0
)
return
PREFIX_SIZE
-
wrote
;
return
0
;
}
static
char
*
__dynamic_emit_prefix
(
const
struct
_ddebug
*
desc
,
char
*
buf
)
{
int
pos_after_tid
;
int
pos
=
0
;
if
(
desc
->
flags
&
_DPRINTK_FLAGS_INCL_TID
) {
if
(
in_interrupt
())
pos
+=
snprintf
(
buf
+
pos
,
remaining
(
pos
),
"<intr> "
);
else
pos
+=
snprintf
(
buf
+
pos
,
remaining
(
pos
),
"[%d] "
,
task_pid_vnr
(
current
));
}
pos_after_tid
=
pos
;
if
(
desc
->
flags
&
_DPRINTK_FLAGS_INCL_MODNAME
)
pos
+=
snprintf
(
buf
+
pos
,
remaining
(
pos
),
"%s:"
,
desc
->
modname
);
if
(
desc
->
flags
&
_DPRINTK_FLAGS_INCL_FUNCNAME
)
pos
+=
snprintf
(
buf
+
pos
,
remaining
(
pos
),
"%s:"
,
desc
->
function
);
if
(
desc
->
flags
&
_DPRINTK_FLAGS_INCL_SOURCENAME
)
pos
+=
snprintf
(
buf
+
pos
,
remaining
(
pos
),
"%s:"
,
trim_prefix
(
desc
->
filename
));
if
(
desc
->
flags
&
_DPRINTK_FLAGS_INCL_LINENO
)
pos
+=
snprintf
(
buf
+
pos
,
remaining
(
pos
),
"%d:"
,
desc
->
lineno
);
if
(
pos
-
pos_after_tid
)
pos
+=
snprintf
(
buf
+
pos
,
remaining
(
pos
),
" "
);
if
(
pos
>=
PREFIX_SIZE
)
buf
[
PREFIX_SIZE
-
1
]
=
'\0'
;
return
buf
;
}
static
inline
char
*
dynamic_emit_prefix
(
struct
_ddebug
*
desc
,
char
*
buf
)
{
if
(
unlikely
(
desc
->
flags
&
_DPRINTK_FLAGS_INCL_ANY
))
return
__dynamic_emit_prefix
(
desc
,
buf
);
return
buf
;
}
void
__dynamic_pr_debug
(
struct
_ddebug
*
descriptor
,
const
char
*
fmt
, ...)
{
va_list
args
;
struct
va_format
vaf
;
char
buf
[
PREFIX_SIZE
]
=
""
;
BUG_ON
(!
descriptor
);
BUG_ON
(!
fmt
);
va_start
(
args
,
fmt
);
vaf
.
fmt
=
fmt
;
vaf
.
va
=
&
args
;
printk
(
KERN_DEBUG
"%s%pV"
,
dynamic_emit_prefix
(
descriptor
,
buf
),
&
vaf
);
va_end
(
args
);
}
EXPORT_SYMBOL
(
__dynamic_pr_debug
);
void
__dynamic_dev_dbg
(
struct
_ddebug
*
descriptor
,
const
struct
device
*
dev
,
const
char
*
fmt
, ...)
{
struct
va_format
vaf
;
va_list
args
;
BUG_ON
(!
descriptor
);
BUG_ON
(!
fmt
);
va_start
(
args
,
fmt
);
vaf
.
fmt
=
fmt
;
vaf
.
va
=
&
args
;
if
(!
dev
) {
printk
(
KERN_DEBUG
"(NULL device *): %pV"
,
&
vaf
);
}
else
{
char
buf
[
PREFIX_SIZE
]
=
""
;
dev_printk_emit
(
LOGLEVEL_DEBUG
,
dev
,
"%s%s %s: %pV"
,
dynamic_emit_prefix
(
descriptor
,
buf
),
dev_driver_string
(
dev
),
dev_name
(
dev
),
&
vaf
);
}
va_end
(
args
);
}
EXPORT_SYMBOL
(
__dynamic_dev_dbg
);
#ifdef
CONFIG_NET
void
__dynamic_netdev_dbg
(
struct
_ddebug
*
descriptor
,
const
struct
net_device
*
dev
,
const
char
*
fmt
, ...)
{
struct
va_format
vaf
;
va_list
args
;
BUG_ON
(!
descriptor
);
BUG_ON
(!
fmt
);
va_start
(
args
,
fmt
);
vaf
.
fmt
=
fmt
;
vaf
.
va
=
&
args
;
if
(
dev
&&
dev
->
dev
.
parent
) {
char
buf
[
PREFIX_SIZE
]
=
""
;
dev_printk_emit
(
LOGLEVEL_DEBUG
,
dev
->
dev
.
parent
,
"%s%s %s %s%s: %pV"
,
dynamic_emit_prefix
(
descriptor
,
buf
),
dev_driver_string
(
dev
->
dev
.
parent
),
dev_name
(
dev
->
dev
.
parent
),
netdev_name
(
dev
),
netdev_reg_state
(
dev
),
&
vaf
);
}
else
if
(
dev
) {
printk
(
KERN_DEBUG
"%s%s: %pV"
,
netdev_name
(
dev
),
netdev_reg_state
(
dev
),
&
vaf
);
}
else
{
printk
(
KERN_DEBUG
"(NULL net_device): %pV"
,
&
vaf
);
}
va_end
(
args
);
}
EXPORT_SYMBOL
(
__dynamic_netdev_dbg
);
#endif
#if
IS_ENABLED
(
CONFIG_INFINIBAND
)
void
__dynamic_ibdev_dbg
(
struct
_ddebug
*
descriptor
,
const
struct
ib_device
*
ibdev
,
const
char
*
fmt
, ...)
{
struct
va_format
vaf
;
va_list
args
;
va_start
(
args
,
fmt
);
vaf
.
fmt
=
fmt
;
vaf
.
va
=
&
args
;
if
(
ibdev
&&
ibdev
->
dev
.
parent
) {
char
buf
[
PREFIX_SIZE
]
=
""
;
dev_printk_emit
(
LOGLEVEL_DEBUG
,
ibdev
->
dev
.
parent
,
"%s%s %s %s: %pV"
,
dynamic_emit_prefix
(
descriptor
,
buf
),
dev_driver_string
(
ibdev
->
dev
.
parent
),
dev_name
(
ibdev
->
dev
.
parent
),
dev_name
(
&
ibdev
->
dev
),
&
vaf
);
}
else
if
(
ibdev
) {
printk
(
KERN_DEBUG
"%s: %pV"
,
dev_name
(
&
ibdev
->
dev
),
&
vaf
);
}
else
{
printk
(
KERN_DEBUG
"(NULL ib_device): %pV"
,
&
vaf
);
}
va_end
(
args
);
}
EXPORT_SYMBOL
(
__dynamic_ibdev_dbg
);
#endif
/*
* Install a noop handler to make dyndbg look like a normal kernel cli param.
* This avoids warnings about dyndbg being an unknown cli param when supplied
* by a user.
*/
static
__init
int
dyndbg_setup
(
char
*
str
)
{
return
1
;
}
__setup
(
"dyndbg="
,
dyndbg_setup
);
/*
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL