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