1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * kernel/lockdep_proc.c
4 *
5 * Runtime locking correctness validator
6 *
7 * Started by Ingo Molnar:
8 *
9 * Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
10 * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra
11 *
12 * Code for /proc/lockdep and /proc/lockdep_stats:
13 *
14 */
15 #include <linux/export.h>
16 #include <linux/proc_fs.h>
17 #include <linux/seq_file.h>
18 #include <linux/kallsyms.h>
19 #include <linux/debug_locks.h>
20 #include <linux/vmalloc.h>
21 #include <linux/sort.h>
22 #include <linux/uaccess.h>
23 #include <asm/div64.h>
24
25 #include "lockdep_internals.h"
26
l_next(struct seq_file * m,void * v,loff_t * pos)27 static void *l_next(struct seq_file *m, void *v, loff_t *pos)
28 {
29 return seq_list_next(v, &all_lock_classes, pos);
30 }
31
l_start(struct seq_file * m,loff_t * pos)32 static void *l_start(struct seq_file *m, loff_t *pos)
33 {
34 return seq_list_start_head(&all_lock_classes, *pos);
35 }
36
l_stop(struct seq_file * m,void * v)37 static void l_stop(struct seq_file *m, void *v)
38 {
39 }
40
print_name(struct seq_file * m,struct lock_class * class)41 static void print_name(struct seq_file *m, struct lock_class *class)
42 {
43 char str[KSYM_NAME_LEN];
44 const char *name = class->name;
45
46 if (!name) {
47 name = __get_key_name(class->key, str);
48 seq_printf(m, "%s", name);
49 } else{
50 seq_printf(m, "%s", name);
51 if (class->name_version > 1)
52 seq_printf(m, "#%d", class->name_version);
53 if (class->subclass)
54 seq_printf(m, "/%d", class->subclass);
55 }
56 }
57
l_show(struct seq_file * m,void * v)58 static int l_show(struct seq_file *m, void *v)
59 {
60 struct lock_class *class = list_entry(v, struct lock_class, lock_entry);
61 struct lock_list *entry;
62 char usage[LOCK_USAGE_CHARS];
63
64 if (v == &all_lock_classes) {
65 seq_printf(m, "all lock classes:\n");
66 return 0;
67 }
68
69 seq_printf(m, "%p", class->key);
70 #ifdef CONFIG_DEBUG_LOCKDEP
71 seq_printf(m, " OPS:%8ld", class->ops);
72 #endif
73 #ifdef CONFIG_PROVE_LOCKING
74 seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class));
75 seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class));
76 #endif
77
78 get_usage_chars(class, usage);
79 seq_printf(m, " %s", usage);
80
81 seq_printf(m, ": ");
82 print_name(m, class);
83 seq_puts(m, "\n");
84
85 list_for_each_entry(entry, &class->locks_after, entry) {
86 if (entry->distance == 1) {
87 seq_printf(m, " -> [%p] ", entry->class->key);
88 print_name(m, entry->class);
89 seq_puts(m, "\n");
90 }
91 }
92 seq_puts(m, "\n");
93
94 return 0;
95 }
96
97 static const struct seq_operations lockdep_ops = {
98 .start = l_start,
99 .next = l_next,
100 .stop = l_stop,
101 .show = l_show,
102 };
103
lockdep_open(struct inode * inode,struct file * file)104 static int lockdep_open(struct inode *inode, struct file *file)
105 {
106 return seq_open(file, &lockdep_ops);
107 }
108
109 static const struct file_operations proc_lockdep_operations = {
110 .open = lockdep_open,
111 .read = seq_read,
112 .llseek = seq_lseek,
113 .release = seq_release,
114 };
115
116 #ifdef CONFIG_PROVE_LOCKING
lc_start(struct seq_file * m,loff_t * pos)117 static void *lc_start(struct seq_file *m, loff_t *pos)
118 {
119 if (*pos == 0)
120 return SEQ_START_TOKEN;
121
122 if (*pos - 1 < nr_lock_chains)
123 return lock_chains + (*pos - 1);
124
125 return NULL;
126 }
127
lc_next(struct seq_file * m,void * v,loff_t * pos)128 static void *lc_next(struct seq_file *m, void *v, loff_t *pos)
129 {
130 (*pos)++;
131 return lc_start(m, pos);
132 }
133
lc_stop(struct seq_file * m,void * v)134 static void lc_stop(struct seq_file *m, void *v)
135 {
136 }
137
lc_show(struct seq_file * m,void * v)138 static int lc_show(struct seq_file *m, void *v)
139 {
140 struct lock_chain *chain = v;
141 struct lock_class *class;
142 int i;
143
144 if (v == SEQ_START_TOKEN) {
145 if (nr_chain_hlocks > MAX_LOCKDEP_CHAIN_HLOCKS)
146 seq_printf(m, "(buggered) ");
147 seq_printf(m, "all lock chains:\n");
148 return 0;
149 }
150
151 seq_printf(m, "irq_context: %d\n", chain->irq_context);
152
153 for (i = 0; i < chain->depth; i++) {
154 class = lock_chain_get_class(chain, i);
155 if (!class->key)
156 continue;
157
158 seq_printf(m, "[%p] ", class->key);
159 print_name(m, class);
160 seq_puts(m, "\n");
161 }
162 seq_puts(m, "\n");
163
164 return 0;
165 }
166
167 static const struct seq_operations lockdep_chains_ops = {
168 .start = lc_start,
169 .next = lc_next,
170 .stop = lc_stop,
171 .show = lc_show,
172 };
173
lockdep_chains_open(struct inode * inode,struct file * file)174 static int lockdep_chains_open(struct inode *inode, struct file *file)
175 {
176 return seq_open(file, &lockdep_chains_ops);
177 }
178
179 static const struct file_operations proc_lockdep_chains_operations = {
180 .open = lockdep_chains_open,
181 .read = seq_read,
182 .llseek = seq_lseek,
183 .release = seq_release,
184 };
185 #endif /* CONFIG_PROVE_LOCKING */
186
lockdep_stats_debug_show(struct seq_file * m)187 static void lockdep_stats_debug_show(struct seq_file *m)
188 {
189 #ifdef CONFIG_DEBUG_LOCKDEP
190 unsigned long long hi1 = debug_atomic_read(hardirqs_on_events),
191 hi2 = debug_atomic_read(hardirqs_off_events),
192 hr1 = debug_atomic_read(redundant_hardirqs_on),
193 hr2 = debug_atomic_read(redundant_hardirqs_off),
194 si1 = debug_atomic_read(softirqs_on_events),
195 si2 = debug_atomic_read(softirqs_off_events),
196 sr1 = debug_atomic_read(redundant_softirqs_on),
197 sr2 = debug_atomic_read(redundant_softirqs_off);
198
199 seq_printf(m, " chain lookup misses: %11llu\n",
200 debug_atomic_read(chain_lookup_misses));
201 seq_printf(m, " chain lookup hits: %11llu\n",
202 debug_atomic_read(chain_lookup_hits));
203 seq_printf(m, " cyclic checks: %11llu\n",
204 debug_atomic_read(nr_cyclic_checks));
205 seq_printf(m, " redundant checks: %11llu\n",
206 debug_atomic_read(nr_redundant_checks));
207 seq_printf(m, " redundant links: %11llu\n",
208 debug_atomic_read(nr_redundant));
209 seq_printf(m, " find-mask forwards checks: %11llu\n",
210 debug_atomic_read(nr_find_usage_forwards_checks));
211 seq_printf(m, " find-mask backwards checks: %11llu\n",
212 debug_atomic_read(nr_find_usage_backwards_checks));
213
214 seq_printf(m, " hardirq on events: %11llu\n", hi1);
215 seq_printf(m, " hardirq off events: %11llu\n", hi2);
216 seq_printf(m, " redundant hardirq ons: %11llu\n", hr1);
217 seq_printf(m, " redundant hardirq offs: %11llu\n", hr2);
218 seq_printf(m, " softirq on events: %11llu\n", si1);
219 seq_printf(m, " softirq off events: %11llu\n", si2);
220 seq_printf(m, " redundant softirq ons: %11llu\n", sr1);
221 seq_printf(m, " redundant softirq offs: %11llu\n", sr2);
222 #endif
223 }
224
lockdep_stats_show(struct seq_file * m,void * v)225 static int lockdep_stats_show(struct seq_file *m, void *v)
226 {
227 unsigned long nr_unused = 0, nr_uncategorized = 0,
228 nr_irq_safe = 0, nr_irq_unsafe = 0,
229 nr_softirq_safe = 0, nr_softirq_unsafe = 0,
230 nr_hardirq_safe = 0, nr_hardirq_unsafe = 0,
231 nr_irq_read_safe = 0, nr_irq_read_unsafe = 0,
232 nr_softirq_read_safe = 0, nr_softirq_read_unsafe = 0,
233 nr_hardirq_read_safe = 0, nr_hardirq_read_unsafe = 0,
234 sum_forward_deps = 0;
235
236 #ifdef CONFIG_PROVE_LOCKING
237 struct lock_class *class;
238
239 list_for_each_entry(class, &all_lock_classes, lock_entry) {
240
241 if (class->usage_mask == 0)
242 nr_unused++;
243 if (class->usage_mask == LOCKF_USED)
244 nr_uncategorized++;
245 if (class->usage_mask & LOCKF_USED_IN_IRQ)
246 nr_irq_safe++;
247 if (class->usage_mask & LOCKF_ENABLED_IRQ)
248 nr_irq_unsafe++;
249 if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ)
250 nr_softirq_safe++;
251 if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ)
252 nr_softirq_unsafe++;
253 if (class->usage_mask & LOCKF_USED_IN_HARDIRQ)
254 nr_hardirq_safe++;
255 if (class->usage_mask & LOCKF_ENABLED_HARDIRQ)
256 nr_hardirq_unsafe++;
257 if (class->usage_mask & LOCKF_USED_IN_IRQ_READ)
258 nr_irq_read_safe++;
259 if (class->usage_mask & LOCKF_ENABLED_IRQ_READ)
260 nr_irq_read_unsafe++;
261 if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ_READ)
262 nr_softirq_read_safe++;
263 if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ_READ)
264 nr_softirq_read_unsafe++;
265 if (class->usage_mask & LOCKF_USED_IN_HARDIRQ_READ)
266 nr_hardirq_read_safe++;
267 if (class->usage_mask & LOCKF_ENABLED_HARDIRQ_READ)
268 nr_hardirq_read_unsafe++;
269
270 sum_forward_deps += lockdep_count_forward_deps(class);
271 }
272 #ifdef CONFIG_DEBUG_LOCKDEP
273 DEBUG_LOCKS_WARN_ON(debug_atomic_read(nr_unused_locks) != nr_unused);
274 #endif
275
276 #endif
277 seq_printf(m, " lock-classes: %11lu [max: %lu]\n",
278 nr_lock_classes, MAX_LOCKDEP_KEYS);
279 seq_printf(m, " direct dependencies: %11lu [max: %lu]\n",
280 nr_list_entries, MAX_LOCKDEP_ENTRIES);
281 seq_printf(m, " indirect dependencies: %11lu\n",
282 sum_forward_deps);
283
284 /*
285 * Total number of dependencies:
286 *
287 * All irq-safe locks may nest inside irq-unsafe locks,
288 * plus all the other known dependencies:
289 */
290 seq_printf(m, " all direct dependencies: %11lu\n",
291 nr_irq_unsafe * nr_irq_safe +
292 nr_hardirq_unsafe * nr_hardirq_safe +
293 nr_list_entries);
294
295 #ifdef CONFIG_PROVE_LOCKING
296 seq_printf(m, " dependency chains: %11lu [max: %lu]\n",
297 nr_lock_chains, MAX_LOCKDEP_CHAINS);
298 seq_printf(m, " dependency chain hlocks: %11d [max: %lu]\n",
299 nr_chain_hlocks, MAX_LOCKDEP_CHAIN_HLOCKS);
300 #endif
301
302 #ifdef CONFIG_TRACE_IRQFLAGS
303 seq_printf(m, " in-hardirq chains: %11u\n",
304 nr_hardirq_chains);
305 seq_printf(m, " in-softirq chains: %11u\n",
306 nr_softirq_chains);
307 #endif
308 seq_printf(m, " in-process chains: %11u\n",
309 nr_process_chains);
310 seq_printf(m, " stack-trace entries: %11lu [max: %lu]\n",
311 nr_stack_trace_entries, MAX_STACK_TRACE_ENTRIES);
312 seq_printf(m, " combined max dependencies: %11u\n",
313 (nr_hardirq_chains + 1) *
314 (nr_softirq_chains + 1) *
315 (nr_process_chains + 1)
316 );
317 seq_printf(m, " hardirq-safe locks: %11lu\n",
318 nr_hardirq_safe);
319 seq_printf(m, " hardirq-unsafe locks: %11lu\n",
320 nr_hardirq_unsafe);
321 seq_printf(m, " softirq-safe locks: %11lu\n",
322 nr_softirq_safe);
323 seq_printf(m, " softirq-unsafe locks: %11lu\n",
324 nr_softirq_unsafe);
325 seq_printf(m, " irq-safe locks: %11lu\n",
326 nr_irq_safe);
327 seq_printf(m, " irq-unsafe locks: %11lu\n",
328 nr_irq_unsafe);
329
330 seq_printf(m, " hardirq-read-safe locks: %11lu\n",
331 nr_hardirq_read_safe);
332 seq_printf(m, " hardirq-read-unsafe locks: %11lu\n",
333 nr_hardirq_read_unsafe);
334 seq_printf(m, " softirq-read-safe locks: %11lu\n",
335 nr_softirq_read_safe);
336 seq_printf(m, " softirq-read-unsafe locks: %11lu\n",
337 nr_softirq_read_unsafe);
338 seq_printf(m, " irq-read-safe locks: %11lu\n",
339 nr_irq_read_safe);
340 seq_printf(m, " irq-read-unsafe locks: %11lu\n",
341 nr_irq_read_unsafe);
342
343 seq_printf(m, " uncategorized locks: %11lu\n",
344 nr_uncategorized);
345 seq_printf(m, " unused locks: %11lu\n",
346 nr_unused);
347 seq_printf(m, " max locking depth: %11u\n",
348 max_lockdep_depth);
349 #ifdef CONFIG_PROVE_LOCKING
350 seq_printf(m, " max bfs queue depth: %11u\n",
351 max_bfs_queue_depth);
352 #endif
353 lockdep_stats_debug_show(m);
354 seq_printf(m, " debug_locks: %11u\n",
355 debug_locks);
356
357 return 0;
358 }
359
lockdep_stats_open(struct inode * inode,struct file * file)360 static int lockdep_stats_open(struct inode *inode, struct file *file)
361 {
362 return single_open(file, lockdep_stats_show, NULL);
363 }
364
365 static const struct file_operations proc_lockdep_stats_operations = {
366 .open = lockdep_stats_open,
367 .read = seq_read,
368 .llseek = seq_lseek,
369 .release = single_release,
370 };
371
372 #ifdef CONFIG_LOCK_STAT
373
374 struct lock_stat_data {
375 struct lock_class *class;
376 struct lock_class_stats stats;
377 };
378
379 struct lock_stat_seq {
380 struct lock_stat_data *iter_end;
381 struct lock_stat_data stats[MAX_LOCKDEP_KEYS];
382 };
383
384 /*
385 * sort on absolute number of contentions
386 */
lock_stat_cmp(const void * l,const void * r)387 static int lock_stat_cmp(const void *l, const void *r)
388 {
389 const struct lock_stat_data *dl = l, *dr = r;
390 unsigned long nl, nr;
391
392 nl = dl->stats.read_waittime.nr + dl->stats.write_waittime.nr;
393 nr = dr->stats.read_waittime.nr + dr->stats.write_waittime.nr;
394
395 return nr - nl;
396 }
397
seq_line(struct seq_file * m,char c,int offset,int length)398 static void seq_line(struct seq_file *m, char c, int offset, int length)
399 {
400 int i;
401
402 for (i = 0; i < offset; i++)
403 seq_puts(m, " ");
404 for (i = 0; i < length; i++)
405 seq_printf(m, "%c", c);
406 seq_puts(m, "\n");
407 }
408
snprint_time(char * buf,size_t bufsiz,s64 nr)409 static void snprint_time(char *buf, size_t bufsiz, s64 nr)
410 {
411 s64 div;
412 s32 rem;
413
414 nr += 5; /* for display rounding */
415 div = div_s64_rem(nr, 1000, &rem);
416 snprintf(buf, bufsiz, "%lld.%02d", (long long)div, (int)rem/10);
417 }
418
seq_time(struct seq_file * m,s64 time)419 static void seq_time(struct seq_file *m, s64 time)
420 {
421 char num[15];
422
423 snprint_time(num, sizeof(num), time);
424 seq_printf(m, " %14s", num);
425 }
426
seq_lock_time(struct seq_file * m,struct lock_time * lt)427 static void seq_lock_time(struct seq_file *m, struct lock_time *lt)
428 {
429 seq_printf(m, "%14lu", lt->nr);
430 seq_time(m, lt->min);
431 seq_time(m, lt->max);
432 seq_time(m, lt->total);
433 seq_time(m, lt->nr ? div_s64(lt->total, lt->nr) : 0);
434 }
435
seq_stats(struct seq_file * m,struct lock_stat_data * data)436 static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
437 {
438 struct lockdep_subclass_key *ckey;
439 struct lock_class_stats *stats;
440 struct lock_class *class;
441 const char *cname;
442 int i, namelen;
443 char name[39];
444
445 class = data->class;
446 stats = &data->stats;
447
448 namelen = 38;
449 if (class->name_version > 1)
450 namelen -= 2; /* XXX truncates versions > 9 */
451 if (class->subclass)
452 namelen -= 2;
453
454 rcu_read_lock_sched();
455 cname = rcu_dereference_sched(class->name);
456 ckey = rcu_dereference_sched(class->key);
457
458 if (!cname && !ckey) {
459 rcu_read_unlock_sched();
460 return;
461
462 } else if (!cname) {
463 char str[KSYM_NAME_LEN];
464 const char *key_name;
465
466 key_name = __get_key_name(ckey, str);
467 snprintf(name, namelen, "%s", key_name);
468 } else {
469 snprintf(name, namelen, "%s", cname);
470 }
471 rcu_read_unlock_sched();
472
473 namelen = strlen(name);
474 if (class->name_version > 1) {
475 snprintf(name+namelen, 3, "#%d", class->name_version);
476 namelen += 2;
477 }
478 if (class->subclass) {
479 snprintf(name+namelen, 3, "/%d", class->subclass);
480 namelen += 2;
481 }
482
483 if (stats->write_holdtime.nr) {
484 if (stats->read_holdtime.nr)
485 seq_printf(m, "%38s-W:", name);
486 else
487 seq_printf(m, "%40s:", name);
488
489 seq_printf(m, "%14lu ", stats->bounces[bounce_contended_write]);
490 seq_lock_time(m, &stats->write_waittime);
491 seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_write]);
492 seq_lock_time(m, &stats->write_holdtime);
493 seq_puts(m, "\n");
494 }
495
496 if (stats->read_holdtime.nr) {
497 seq_printf(m, "%38s-R:", name);
498 seq_printf(m, "%14lu ", stats->bounces[bounce_contended_read]);
499 seq_lock_time(m, &stats->read_waittime);
500 seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_read]);
501 seq_lock_time(m, &stats->read_holdtime);
502 seq_puts(m, "\n");
503 }
504
505 if (stats->read_waittime.nr + stats->write_waittime.nr == 0)
506 return;
507
508 if (stats->read_holdtime.nr)
509 namelen += 2;
510
511 for (i = 0; i < LOCKSTAT_POINTS; i++) {
512 char ip[32];
513
514 if (class->contention_point[i] == 0)
515 break;
516
517 if (!i)
518 seq_line(m, '-', 40-namelen, namelen);
519
520 snprintf(ip, sizeof(ip), "[<%p>]",
521 (void *)class->contention_point[i]);
522 seq_printf(m, "%40s %14lu %29s %pS\n",
523 name, stats->contention_point[i],
524 ip, (void *)class->contention_point[i]);
525 }
526 for (i = 0; i < LOCKSTAT_POINTS; i++) {
527 char ip[32];
528
529 if (class->contending_point[i] == 0)
530 break;
531
532 if (!i)
533 seq_line(m, '-', 40-namelen, namelen);
534
535 snprintf(ip, sizeof(ip), "[<%p>]",
536 (void *)class->contending_point[i]);
537 seq_printf(m, "%40s %14lu %29s %pS\n",
538 name, stats->contending_point[i],
539 ip, (void *)class->contending_point[i]);
540 }
541 if (i) {
542 seq_puts(m, "\n");
543 seq_line(m, '.', 0, 40 + 1 + 12 * (14 + 1));
544 seq_puts(m, "\n");
545 }
546 }
547
seq_header(struct seq_file * m)548 static void seq_header(struct seq_file *m)
549 {
550 seq_puts(m, "lock_stat version 0.4\n");
551
552 if (unlikely(!debug_locks))
553 seq_printf(m, "*WARNING* lock debugging disabled!! - possibly due to a lockdep warning\n");
554
555 seq_line(m, '-', 0, 40 + 1 + 12 * (14 + 1));
556 seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s "
557 "%14s %14s\n",
558 "class name",
559 "con-bounces",
560 "contentions",
561 "waittime-min",
562 "waittime-max",
563 "waittime-total",
564 "waittime-avg",
565 "acq-bounces",
566 "acquisitions",
567 "holdtime-min",
568 "holdtime-max",
569 "holdtime-total",
570 "holdtime-avg");
571 seq_line(m, '-', 0, 40 + 1 + 12 * (14 + 1));
572 seq_printf(m, "\n");
573 }
574
ls_start(struct seq_file * m,loff_t * pos)575 static void *ls_start(struct seq_file *m, loff_t *pos)
576 {
577 struct lock_stat_seq *data = m->private;
578 struct lock_stat_data *iter;
579
580 if (*pos == 0)
581 return SEQ_START_TOKEN;
582
583 iter = data->stats + (*pos - 1);
584 if (iter >= data->iter_end)
585 iter = NULL;
586
587 return iter;
588 }
589
ls_next(struct seq_file * m,void * v,loff_t * pos)590 static void *ls_next(struct seq_file *m, void *v, loff_t *pos)
591 {
592 (*pos)++;
593 return ls_start(m, pos);
594 }
595
ls_stop(struct seq_file * m,void * v)596 static void ls_stop(struct seq_file *m, void *v)
597 {
598 }
599
ls_show(struct seq_file * m,void * v)600 static int ls_show(struct seq_file *m, void *v)
601 {
602 if (v == SEQ_START_TOKEN)
603 seq_header(m);
604 else
605 seq_stats(m, v);
606
607 return 0;
608 }
609
610 static const struct seq_operations lockstat_ops = {
611 .start = ls_start,
612 .next = ls_next,
613 .stop = ls_stop,
614 .show = ls_show,
615 };
616
lock_stat_open(struct inode * inode,struct file * file)617 static int lock_stat_open(struct inode *inode, struct file *file)
618 {
619 int res;
620 struct lock_class *class;
621 struct lock_stat_seq *data = vmalloc(sizeof(struct lock_stat_seq));
622
623 if (!data)
624 return -ENOMEM;
625
626 res = seq_open(file, &lockstat_ops);
627 if (!res) {
628 struct lock_stat_data *iter = data->stats;
629 struct seq_file *m = file->private_data;
630
631 list_for_each_entry(class, &all_lock_classes, lock_entry) {
632 iter->class = class;
633 iter->stats = lock_stats(class);
634 iter++;
635 }
636 data->iter_end = iter;
637
638 sort(data->stats, data->iter_end - data->stats,
639 sizeof(struct lock_stat_data),
640 lock_stat_cmp, NULL);
641
642 m->private = data;
643 } else
644 vfree(data);
645
646 return res;
647 }
648
lock_stat_write(struct file * file,const char __user * buf,size_t count,loff_t * ppos)649 static ssize_t lock_stat_write(struct file *file, const char __user *buf,
650 size_t count, loff_t *ppos)
651 {
652 struct lock_class *class;
653 char c;
654
655 if (count) {
656 if (get_user(c, buf))
657 return -EFAULT;
658
659 if (c != '0')
660 return count;
661
662 list_for_each_entry(class, &all_lock_classes, lock_entry)
663 clear_lock_stats(class);
664 }
665 return count;
666 }
667
lock_stat_release(struct inode * inode,struct file * file)668 static int lock_stat_release(struct inode *inode, struct file *file)
669 {
670 struct seq_file *seq = file->private_data;
671
672 vfree(seq->private);
673 return seq_release(inode, file);
674 }
675
676 static const struct file_operations proc_lock_stat_operations = {
677 .open = lock_stat_open,
678 .write = lock_stat_write,
679 .read = seq_read,
680 .llseek = seq_lseek,
681 .release = lock_stat_release,
682 };
683 #endif /* CONFIG_LOCK_STAT */
684
lockdep_proc_init(void)685 static int __init lockdep_proc_init(void)
686 {
687 proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations);
688 #ifdef CONFIG_PROVE_LOCKING
689 proc_create("lockdep_chains", S_IRUSR, NULL,
690 &proc_lockdep_chains_operations);
691 #endif
692 proc_create("lockdep_stats", S_IRUSR, NULL,
693 &proc_lockdep_stats_operations);
694
695 #ifdef CONFIG_LOCK_STAT
696 proc_create("lock_stat", S_IRUSR | S_IWUSR, NULL,
697 &proc_lock_stat_operations);
698 #endif
699
700 return 0;
701 }
702
703 __initcall(lockdep_proc_init);
704
705