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