xref: /openbmc/linux/kernel/locking/lockdep_proc.c (revision 6aa7de05)
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 <linux/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 	return seq_list_next(v, &all_lock_classes, pos);
29 }
30 
31 static void *l_start(struct seq_file *m, loff_t *pos)
32 {
33 	return seq_list_start_head(&all_lock_classes, *pos);
34 }
35 
36 static void l_stop(struct seq_file *m, void *v)
37 {
38 }
39 
40 static 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 
57 static 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 
96 static const struct seq_operations lockdep_ops = {
97 	.start	= l_start,
98 	.next	= l_next,
99 	.stop	= l_stop,
100 	.show	= l_show,
101 };
102 
103 static int lockdep_open(struct inode *inode, struct file *file)
104 {
105 	return seq_open(file, &lockdep_ops);
106 }
107 
108 static 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
116 static 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 
127 static void *lc_next(struct seq_file *m, void *v, loff_t *pos)
128 {
129 	(*pos)++;
130 	return lc_start(m, pos);
131 }
132 
133 static void lc_stop(struct seq_file *m, void *v)
134 {
135 }
136 
137 static 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 
166 static 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 
173 static int lockdep_chains_open(struct inode *inode, struct file *file)
174 {
175 	return seq_open(file, &lockdep_chains_ops);
176 }
177 
178 static 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 
186 static 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, " redundant checks:              %11llu\n",
205 		debug_atomic_read(nr_redundant_checks));
206 	seq_printf(m, " redundant links:               %11llu\n",
207 		debug_atomic_read(nr_redundant));
208 	seq_printf(m, " find-mask forwards checks:     %11llu\n",
209 		debug_atomic_read(nr_find_usage_forwards_checks));
210 	seq_printf(m, " find-mask backwards checks:    %11llu\n",
211 		debug_atomic_read(nr_find_usage_backwards_checks));
212 
213 	seq_printf(m, " hardirq on events:             %11llu\n", hi1);
214 	seq_printf(m, " hardirq off events:            %11llu\n", hi2);
215 	seq_printf(m, " redundant hardirq ons:         %11llu\n", hr1);
216 	seq_printf(m, " redundant hardirq offs:        %11llu\n", hr2);
217 	seq_printf(m, " softirq on events:             %11llu\n", si1);
218 	seq_printf(m, " softirq off events:            %11llu\n", si2);
219 	seq_printf(m, " redundant softirq ons:         %11llu\n", sr1);
220 	seq_printf(m, " redundant softirq offs:        %11llu\n", sr2);
221 #endif
222 }
223 
224 static int lockdep_stats_show(struct seq_file *m, void *v)
225 {
226 	struct lock_class *class;
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 	list_for_each_entry(class, &all_lock_classes, lock_entry) {
237 
238 		if (class->usage_mask == 0)
239 			nr_unused++;
240 		if (class->usage_mask == LOCKF_USED)
241 			nr_uncategorized++;
242 		if (class->usage_mask & LOCKF_USED_IN_IRQ)
243 			nr_irq_safe++;
244 		if (class->usage_mask & LOCKF_ENABLED_IRQ)
245 			nr_irq_unsafe++;
246 		if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ)
247 			nr_softirq_safe++;
248 		if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ)
249 			nr_softirq_unsafe++;
250 		if (class->usage_mask & LOCKF_USED_IN_HARDIRQ)
251 			nr_hardirq_safe++;
252 		if (class->usage_mask & LOCKF_ENABLED_HARDIRQ)
253 			nr_hardirq_unsafe++;
254 		if (class->usage_mask & LOCKF_USED_IN_IRQ_READ)
255 			nr_irq_read_safe++;
256 		if (class->usage_mask & LOCKF_ENABLED_IRQ_READ)
257 			nr_irq_read_unsafe++;
258 		if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ_READ)
259 			nr_softirq_read_safe++;
260 		if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ_READ)
261 			nr_softirq_read_unsafe++;
262 		if (class->usage_mask & LOCKF_USED_IN_HARDIRQ_READ)
263 			nr_hardirq_read_safe++;
264 		if (class->usage_mask & LOCKF_ENABLED_HARDIRQ_READ)
265 			nr_hardirq_read_unsafe++;
266 
267 #ifdef CONFIG_PROVE_LOCKING
268 		sum_forward_deps += lockdep_count_forward_deps(class);
269 #endif
270 	}
271 #ifdef CONFIG_DEBUG_LOCKDEP
272 	DEBUG_LOCKS_WARN_ON(debug_atomic_read(nr_unused_locks) != nr_unused);
273 #endif
274 	seq_printf(m, " lock-classes:                  %11lu [max: %lu]\n",
275 			nr_lock_classes, MAX_LOCKDEP_KEYS);
276 	seq_printf(m, " direct dependencies:           %11lu [max: %lu]\n",
277 			nr_list_entries, MAX_LOCKDEP_ENTRIES);
278 	seq_printf(m, " indirect dependencies:         %11lu\n",
279 			sum_forward_deps);
280 
281 	/*
282 	 * Total number of dependencies:
283 	 *
284 	 * All irq-safe locks may nest inside irq-unsafe locks,
285 	 * plus all the other known dependencies:
286 	 */
287 	seq_printf(m, " all direct dependencies:       %11lu\n",
288 			nr_irq_unsafe * nr_irq_safe +
289 			nr_hardirq_unsafe * nr_hardirq_safe +
290 			nr_list_entries);
291 
292 #ifdef CONFIG_PROVE_LOCKING
293 	seq_printf(m, " dependency chains:             %11lu [max: %lu]\n",
294 			nr_lock_chains, MAX_LOCKDEP_CHAINS);
295 	seq_printf(m, " dependency chain hlocks:       %11d [max: %lu]\n",
296 			nr_chain_hlocks, MAX_LOCKDEP_CHAIN_HLOCKS);
297 #endif
298 
299 #ifdef CONFIG_TRACE_IRQFLAGS
300 	seq_printf(m, " in-hardirq chains:             %11u\n",
301 			nr_hardirq_chains);
302 	seq_printf(m, " in-softirq chains:             %11u\n",
303 			nr_softirq_chains);
304 #endif
305 	seq_printf(m, " in-process chains:             %11u\n",
306 			nr_process_chains);
307 	seq_printf(m, " stack-trace entries:           %11lu [max: %lu]\n",
308 			nr_stack_trace_entries, MAX_STACK_TRACE_ENTRIES);
309 	seq_printf(m, " combined max dependencies:     %11u\n",
310 			(nr_hardirq_chains + 1) *
311 			(nr_softirq_chains + 1) *
312 			(nr_process_chains + 1)
313 	);
314 	seq_printf(m, " hardirq-safe locks:            %11lu\n",
315 			nr_hardirq_safe);
316 	seq_printf(m, " hardirq-unsafe locks:          %11lu\n",
317 			nr_hardirq_unsafe);
318 	seq_printf(m, " softirq-safe locks:            %11lu\n",
319 			nr_softirq_safe);
320 	seq_printf(m, " softirq-unsafe locks:          %11lu\n",
321 			nr_softirq_unsafe);
322 	seq_printf(m, " irq-safe locks:                %11lu\n",
323 			nr_irq_safe);
324 	seq_printf(m, " irq-unsafe locks:              %11lu\n",
325 			nr_irq_unsafe);
326 
327 	seq_printf(m, " hardirq-read-safe locks:       %11lu\n",
328 			nr_hardirq_read_safe);
329 	seq_printf(m, " hardirq-read-unsafe locks:     %11lu\n",
330 			nr_hardirq_read_unsafe);
331 	seq_printf(m, " softirq-read-safe locks:       %11lu\n",
332 			nr_softirq_read_safe);
333 	seq_printf(m, " softirq-read-unsafe locks:     %11lu\n",
334 			nr_softirq_read_unsafe);
335 	seq_printf(m, " irq-read-safe locks:           %11lu\n",
336 			nr_irq_read_safe);
337 	seq_printf(m, " irq-read-unsafe locks:         %11lu\n",
338 			nr_irq_read_unsafe);
339 
340 	seq_printf(m, " uncategorized locks:           %11lu\n",
341 			nr_uncategorized);
342 	seq_printf(m, " unused locks:                  %11lu\n",
343 			nr_unused);
344 	seq_printf(m, " max locking depth:             %11u\n",
345 			max_lockdep_depth);
346 #ifdef CONFIG_PROVE_LOCKING
347 	seq_printf(m, " max bfs queue depth:           %11u\n",
348 			max_bfs_queue_depth);
349 #endif
350 	lockdep_stats_debug_show(m);
351 	seq_printf(m, " debug_locks:                   %11u\n",
352 			debug_locks);
353 
354 	return 0;
355 }
356 
357 static int lockdep_stats_open(struct inode *inode, struct file *file)
358 {
359 	return single_open(file, lockdep_stats_show, NULL);
360 }
361 
362 static const struct file_operations proc_lockdep_stats_operations = {
363 	.open		= lockdep_stats_open,
364 	.read		= seq_read,
365 	.llseek		= seq_lseek,
366 	.release	= single_release,
367 };
368 
369 #ifdef CONFIG_LOCK_STAT
370 
371 struct lock_stat_data {
372 	struct lock_class *class;
373 	struct lock_class_stats stats;
374 };
375 
376 struct lock_stat_seq {
377 	struct lock_stat_data *iter_end;
378 	struct lock_stat_data stats[MAX_LOCKDEP_KEYS];
379 };
380 
381 /*
382  * sort on absolute number of contentions
383  */
384 static int lock_stat_cmp(const void *l, const void *r)
385 {
386 	const struct lock_stat_data *dl = l, *dr = r;
387 	unsigned long nl, nr;
388 
389 	nl = dl->stats.read_waittime.nr + dl->stats.write_waittime.nr;
390 	nr = dr->stats.read_waittime.nr + dr->stats.write_waittime.nr;
391 
392 	return nr - nl;
393 }
394 
395 static void seq_line(struct seq_file *m, char c, int offset, int length)
396 {
397 	int i;
398 
399 	for (i = 0; i < offset; i++)
400 		seq_puts(m, " ");
401 	for (i = 0; i < length; i++)
402 		seq_printf(m, "%c", c);
403 	seq_puts(m, "\n");
404 }
405 
406 static void snprint_time(char *buf, size_t bufsiz, s64 nr)
407 {
408 	s64 div;
409 	s32 rem;
410 
411 	nr += 5; /* for display rounding */
412 	div = div_s64_rem(nr, 1000, &rem);
413 	snprintf(buf, bufsiz, "%lld.%02d", (long long)div, (int)rem/10);
414 }
415 
416 static void seq_time(struct seq_file *m, s64 time)
417 {
418 	char num[15];
419 
420 	snprint_time(num, sizeof(num), time);
421 	seq_printf(m, " %14s", num);
422 }
423 
424 static void seq_lock_time(struct seq_file *m, struct lock_time *lt)
425 {
426 	seq_printf(m, "%14lu", lt->nr);
427 	seq_time(m, lt->min);
428 	seq_time(m, lt->max);
429 	seq_time(m, lt->total);
430 	seq_time(m, lt->nr ? div_s64(lt->total, lt->nr) : 0);
431 }
432 
433 static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
434 {
435 	struct lockdep_subclass_key *ckey;
436 	struct lock_class_stats *stats;
437 	struct lock_class *class;
438 	const char *cname;
439 	int i, namelen;
440 	char name[39];
441 
442 	class = data->class;
443 	stats = &data->stats;
444 
445 	namelen = 38;
446 	if (class->name_version > 1)
447 		namelen -= 2; /* XXX truncates versions > 9 */
448 	if (class->subclass)
449 		namelen -= 2;
450 
451 	rcu_read_lock_sched();
452 	cname = rcu_dereference_sched(class->name);
453 	ckey  = rcu_dereference_sched(class->key);
454 
455 	if (!cname && !ckey) {
456 		rcu_read_unlock_sched();
457 		return;
458 
459 	} else if (!cname) {
460 		char str[KSYM_NAME_LEN];
461 		const char *key_name;
462 
463 		key_name = __get_key_name(ckey, str);
464 		snprintf(name, namelen, "%s", key_name);
465 	} else {
466 		snprintf(name, namelen, "%s", cname);
467 	}
468 	rcu_read_unlock_sched();
469 
470 	namelen = strlen(name);
471 	if (class->name_version > 1) {
472 		snprintf(name+namelen, 3, "#%d", class->name_version);
473 		namelen += 2;
474 	}
475 	if (class->subclass) {
476 		snprintf(name+namelen, 3, "/%d", class->subclass);
477 		namelen += 2;
478 	}
479 
480 	if (stats->write_holdtime.nr) {
481 		if (stats->read_holdtime.nr)
482 			seq_printf(m, "%38s-W:", name);
483 		else
484 			seq_printf(m, "%40s:", name);
485 
486 		seq_printf(m, "%14lu ", stats->bounces[bounce_contended_write]);
487 		seq_lock_time(m, &stats->write_waittime);
488 		seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_write]);
489 		seq_lock_time(m, &stats->write_holdtime);
490 		seq_puts(m, "\n");
491 	}
492 
493 	if (stats->read_holdtime.nr) {
494 		seq_printf(m, "%38s-R:", name);
495 		seq_printf(m, "%14lu ", stats->bounces[bounce_contended_read]);
496 		seq_lock_time(m, &stats->read_waittime);
497 		seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_read]);
498 		seq_lock_time(m, &stats->read_holdtime);
499 		seq_puts(m, "\n");
500 	}
501 
502 	if (stats->read_waittime.nr + stats->write_waittime.nr == 0)
503 		return;
504 
505 	if (stats->read_holdtime.nr)
506 		namelen += 2;
507 
508 	for (i = 0; i < LOCKSTAT_POINTS; i++) {
509 		char ip[32];
510 
511 		if (class->contention_point[i] == 0)
512 			break;
513 
514 		if (!i)
515 			seq_line(m, '-', 40-namelen, namelen);
516 
517 		snprintf(ip, sizeof(ip), "[<%p>]",
518 				(void *)class->contention_point[i]);
519 		seq_printf(m, "%40s %14lu %29s %pS\n",
520 			   name, stats->contention_point[i],
521 			   ip, (void *)class->contention_point[i]);
522 	}
523 	for (i = 0; i < LOCKSTAT_POINTS; i++) {
524 		char ip[32];
525 
526 		if (class->contending_point[i] == 0)
527 			break;
528 
529 		if (!i)
530 			seq_line(m, '-', 40-namelen, namelen);
531 
532 		snprintf(ip, sizeof(ip), "[<%p>]",
533 				(void *)class->contending_point[i]);
534 		seq_printf(m, "%40s %14lu %29s %pS\n",
535 			   name, stats->contending_point[i],
536 			   ip, (void *)class->contending_point[i]);
537 	}
538 	if (i) {
539 		seq_puts(m, "\n");
540 		seq_line(m, '.', 0, 40 + 1 + 12 * (14 + 1));
541 		seq_puts(m, "\n");
542 	}
543 }
544 
545 static void seq_header(struct seq_file *m)
546 {
547 	seq_puts(m, "lock_stat version 0.4\n");
548 
549 	if (unlikely(!debug_locks))
550 		seq_printf(m, "*WARNING* lock debugging disabled!! - possibly due to a lockdep warning\n");
551 
552 	seq_line(m, '-', 0, 40 + 1 + 12 * (14 + 1));
553 	seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s "
554 			"%14s %14s\n",
555 			"class name",
556 			"con-bounces",
557 			"contentions",
558 			"waittime-min",
559 			"waittime-max",
560 			"waittime-total",
561 			"waittime-avg",
562 			"acq-bounces",
563 			"acquisitions",
564 			"holdtime-min",
565 			"holdtime-max",
566 			"holdtime-total",
567 			"holdtime-avg");
568 	seq_line(m, '-', 0, 40 + 1 + 12 * (14 + 1));
569 	seq_printf(m, "\n");
570 }
571 
572 static void *ls_start(struct seq_file *m, loff_t *pos)
573 {
574 	struct lock_stat_seq *data = m->private;
575 	struct lock_stat_data *iter;
576 
577 	if (*pos == 0)
578 		return SEQ_START_TOKEN;
579 
580 	iter = data->stats + (*pos - 1);
581 	if (iter >= data->iter_end)
582 		iter = NULL;
583 
584 	return iter;
585 }
586 
587 static void *ls_next(struct seq_file *m, void *v, loff_t *pos)
588 {
589 	(*pos)++;
590 	return ls_start(m, pos);
591 }
592 
593 static void ls_stop(struct seq_file *m, void *v)
594 {
595 }
596 
597 static int ls_show(struct seq_file *m, void *v)
598 {
599 	if (v == SEQ_START_TOKEN)
600 		seq_header(m);
601 	else
602 		seq_stats(m, v);
603 
604 	return 0;
605 }
606 
607 static const struct seq_operations lockstat_ops = {
608 	.start	= ls_start,
609 	.next	= ls_next,
610 	.stop	= ls_stop,
611 	.show	= ls_show,
612 };
613 
614 static int lock_stat_open(struct inode *inode, struct file *file)
615 {
616 	int res;
617 	struct lock_class *class;
618 	struct lock_stat_seq *data = vmalloc(sizeof(struct lock_stat_seq));
619 
620 	if (!data)
621 		return -ENOMEM;
622 
623 	res = seq_open(file, &lockstat_ops);
624 	if (!res) {
625 		struct lock_stat_data *iter = data->stats;
626 		struct seq_file *m = file->private_data;
627 
628 		list_for_each_entry(class, &all_lock_classes, lock_entry) {
629 			iter->class = class;
630 			iter->stats = lock_stats(class);
631 			iter++;
632 		}
633 		data->iter_end = iter;
634 
635 		sort(data->stats, data->iter_end - data->stats,
636 				sizeof(struct lock_stat_data),
637 				lock_stat_cmp, NULL);
638 
639 		m->private = data;
640 	} else
641 		vfree(data);
642 
643 	return res;
644 }
645 
646 static ssize_t lock_stat_write(struct file *file, const char __user *buf,
647 			       size_t count, loff_t *ppos)
648 {
649 	struct lock_class *class;
650 	char c;
651 
652 	if (count) {
653 		if (get_user(c, buf))
654 			return -EFAULT;
655 
656 		if (c != '0')
657 			return count;
658 
659 		list_for_each_entry(class, &all_lock_classes, lock_entry)
660 			clear_lock_stats(class);
661 	}
662 	return count;
663 }
664 
665 static int lock_stat_release(struct inode *inode, struct file *file)
666 {
667 	struct seq_file *seq = file->private_data;
668 
669 	vfree(seq->private);
670 	return seq_release(inode, file);
671 }
672 
673 static const struct file_operations proc_lock_stat_operations = {
674 	.open		= lock_stat_open,
675 	.write		= lock_stat_write,
676 	.read		= seq_read,
677 	.llseek		= seq_lseek,
678 	.release	= lock_stat_release,
679 };
680 #endif /* CONFIG_LOCK_STAT */
681 
682 static int __init lockdep_proc_init(void)
683 {
684 	proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations);
685 #ifdef CONFIG_PROVE_LOCKING
686 	proc_create("lockdep_chains", S_IRUSR, NULL,
687 		    &proc_lockdep_chains_operations);
688 #endif
689 	proc_create("lockdep_stats", S_IRUSR, NULL,
690 		    &proc_lockdep_stats_operations);
691 
692 #ifdef CONFIG_LOCK_STAT
693 	proc_create("lock_stat", S_IRUSR | S_IWUSR, NULL,
694 		    &proc_lock_stat_operations);
695 #endif
696 
697 	return 0;
698 }
699 
700 __initcall(lockdep_proc_init);
701 
702