162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * lib/debug_locks.c
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Generic place for common debugging facilities for various locks:
662306a36Sopenharmony_ci * spinlocks, rwlocks, mutexes and rwsems.
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * Started by Ingo Molnar:
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci *  Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_ci#include <linux/rwsem.h>
1362306a36Sopenharmony_ci#include <linux/mutex.h>
1462306a36Sopenharmony_ci#include <linux/export.h>
1562306a36Sopenharmony_ci#include <linux/spinlock.h>
1662306a36Sopenharmony_ci#include <linux/debug_locks.h>
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci/*
1962306a36Sopenharmony_ci * We want to turn all lock-debugging facilities on/off at once,
2062306a36Sopenharmony_ci * via a global flag. The reason is that once a single bug has been
2162306a36Sopenharmony_ci * detected and reported, there might be cascade of followup bugs
2262306a36Sopenharmony_ci * that would just muddy the log. So we report the first one and
2362306a36Sopenharmony_ci * shut up after that.
2462306a36Sopenharmony_ci */
2562306a36Sopenharmony_ciint debug_locks __read_mostly = 1;
2662306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(debug_locks);
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/*
2962306a36Sopenharmony_ci * The locking-testsuite uses <debug_locks_silent> to get a
3062306a36Sopenharmony_ci * 'silent failure': nothing is printed to the console when
3162306a36Sopenharmony_ci * a locking bug is detected.
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_ciint debug_locks_silent __read_mostly;
3462306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(debug_locks_silent);
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci/*
3762306a36Sopenharmony_ci * Generic 'turn off all lock debugging' function:
3862306a36Sopenharmony_ci */
3962306a36Sopenharmony_ciint debug_locks_off(void)
4062306a36Sopenharmony_ci{
4162306a36Sopenharmony_ci	if (debug_locks && __debug_locks_off()) {
4262306a36Sopenharmony_ci		if (!debug_locks_silent) {
4362306a36Sopenharmony_ci			console_verbose();
4462306a36Sopenharmony_ci			return 1;
4562306a36Sopenharmony_ci		}
4662306a36Sopenharmony_ci	}
4762306a36Sopenharmony_ci	return 0;
4862306a36Sopenharmony_ci}
4962306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(debug_locks_off);
50