xref: /linux/lib/debug_locks.c (revision 8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17)
1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
29a11b49aSIngo Molnar /*
39a11b49aSIngo Molnar  * lib/debug_locks.c
49a11b49aSIngo Molnar  *
59a11b49aSIngo Molnar  * Generic place for common debugging facilities for various locks:
69a11b49aSIngo Molnar  * spinlocks, rwlocks, mutexes and rwsems.
79a11b49aSIngo Molnar  *
89a11b49aSIngo Molnar  * Started by Ingo Molnar:
99a11b49aSIngo Molnar  *
109a11b49aSIngo Molnar  *  Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
119a11b49aSIngo Molnar  */
129a11b49aSIngo Molnar #include <linux/rwsem.h>
139a11b49aSIngo Molnar #include <linux/mutex.h>
148bc3bcc9SPaul Gortmaker #include <linux/export.h>
159a11b49aSIngo Molnar #include <linux/spinlock.h>
169a11b49aSIngo Molnar #include <linux/debug_locks.h>
179a11b49aSIngo Molnar 
189a11b49aSIngo Molnar /*
199a11b49aSIngo Molnar  * We want to turn all lock-debugging facilities on/off at once,
209a11b49aSIngo Molnar  * via a global flag. The reason is that once a single bug has been
219a11b49aSIngo Molnar  * detected and reported, there might be cascade of followup bugs
229a11b49aSIngo Molnar  * that would just muddy the log. So we report the first one and
239a11b49aSIngo Molnar  * shut up after that.
249a11b49aSIngo Molnar  */
2501a14bdaSWaiman Long int debug_locks __read_mostly = 1;
26632ee200SPaul E. McKenney EXPORT_SYMBOL_GPL(debug_locks);
279a11b49aSIngo Molnar 
289a11b49aSIngo Molnar /*
299a11b49aSIngo Molnar  * The locking-testsuite uses <debug_locks_silent> to get a
309a11b49aSIngo Molnar  * 'silent failure': nothing is printed to the console when
319a11b49aSIngo Molnar  * a locking bug is detected.
329a11b49aSIngo Molnar  */
3301a14bdaSWaiman Long int debug_locks_silent __read_mostly;
34040a0a37SMaarten Lankhorst EXPORT_SYMBOL_GPL(debug_locks_silent);
359a11b49aSIngo Molnar 
369a11b49aSIngo Molnar /*
379a11b49aSIngo Molnar  * Generic 'turn off all lock debugging' function:
389a11b49aSIngo Molnar  */
debug_locks_off(void)39*49faa777SPeter Zijlstra int debug_locks_off(void)
409a11b49aSIngo Molnar {
419506a742SWaiman Long 	if (debug_locks && __debug_locks_off()) {
429a11b49aSIngo Molnar 		if (!debug_locks_silent) {
439a11b49aSIngo Molnar 			console_verbose();
449a11b49aSIngo Molnar 			return 1;
459a11b49aSIngo Molnar 		}
469a11b49aSIngo Molnar 	}
479a11b49aSIngo Molnar 	return 0;
489a11b49aSIngo Molnar }
49040a0a37SMaarten Lankhorst EXPORT_SYMBOL_GPL(debug_locks_off);
50