android_kernel_xiaomi_sm8450/lib/debug_locks.c

46 lines
1.2 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0-only
/*
* lib/debug_locks.c
*
* Generic place for common debugging facilities for various locks:
* spinlocks, rwlocks, mutexes and rwsems.
*
* Started by Ingo Molnar:
*
* Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
*/
#include <linux/rwsem.h>
#include <linux/mutex.h>
#include <linux/export.h>
#include <linux/spinlock.h>
#include <linux/debug_locks.h>
/*
* We want to turn all lock-debugging facilities on/off at once,
* via a global flag. The reason is that once a single bug has been
* detected and reported, there might be cascade of followup bugs
* that would just muddy the log. So we report the first one and
* shut up after that.
*/
int debug_locks __read_mostly = 1;
rcu: Introduce lockdep-based checking to RCU read-side primitives Inspection is proving insufficient to catch all RCU misuses, which is understandable given that rcu_dereference() might be protected by any of four different flavors of RCU (RCU, RCU-bh, RCU-sched, and SRCU), and might also/instead be protected by any of a number of locking primitives. It is therefore time to enlist the aid of lockdep. This set of patches is inspired by earlier work by Peter Zijlstra and Thomas Gleixner, and takes the following approach: o Set up separate lockdep classes for RCU, RCU-bh, and RCU-sched. o Set up separate lockdep classes for each instance of SRCU. o Create primitives that check for being in an RCU read-side critical section. These return exact answers if lockdep is fully enabled, but if unsure, report being in an RCU read-side critical section. (We want to avoid false positives!) The primitives are: For RCU: rcu_read_lock_held(void) For RCU-bh: rcu_read_lock_bh_held(void) For RCU-sched: rcu_read_lock_sched_held(void) For SRCU: srcu_read_lock_held(struct srcu_struct *sp) o Add rcu_dereference_check(), which takes a second argument in which one places a boolean expression based on the above primitives and/or lockdep_is_held(). o A new kernel configuration parameter, CONFIG_PROVE_RCU, enables rcu_dereference_check(). This depends on CONFIG_PROVE_LOCKING, and should be quite helpful during the transition period while CONFIG_PROVE_RCU-unaware patches are in flight. The existing rcu_dereference() primitive does no checking, but upcoming patches will change that. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: laijs@cn.fujitsu.com Cc: dipankar@in.ibm.com Cc: mathieu.desnoyers@polymtl.ca Cc: josh@joshtriplett.org Cc: dvhltc@us.ibm.com Cc: niv@us.ibm.com Cc: peterz@infradead.org Cc: rostedt@goodmis.org Cc: Valdis.Kletnieks@vt.edu Cc: dhowells@redhat.com LKML-Reference: <1266887105-1528-1-git-send-email-paulmck@linux.vnet.ibm.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-23 10:04:45 +09:00
EXPORT_SYMBOL_GPL(debug_locks);
/*
* The locking-testsuite uses <debug_locks_silent> to get a
* 'silent failure': nothing is printed to the console when
* a locking bug is detected.
*/
int debug_locks_silent __read_mostly;
EXPORT_SYMBOL_GPL(debug_locks_silent);
/*
* Generic 'turn off all lock debugging' function:
*/
int debug_locks_off(void)
{
FROMLIST: lockdep: Remove console_verbose when disable lock debugging debug_locks_off can be called in scenarios where the kernel doesn't immediately panic. For instance, debug_locks_off is called with a mismatched preempt_count or when registering an improper lockdep map and fails the sanity check for lock-class key [1]. Both of these issues were discovered in vendor kernel code and were fixed. When console_verbose is enabled, we have found that kernel tends to be unstable because it is spending much of its time printing to the serial log, so the system may miss watchdog pats. We explicitly set our system to reduce the loglevel in order to prevent such scenarios, however lockdep can circumvent the commandline setting. Thus, when we ran into the kernel bugs, we first ended up trying to debug why the kernel wasn't able to respond to watchdog pets and why it was spending all of its time flushing the console, which did not quickly lead us to the "real" lock dependency issue. Remove the console_verbose when turning off lock debugging. Other debug facilities, such as KASAN, KFENCE, SPINLOCK_DEBUG, and DEBUG_OBJECTS don't set console_verbose when issues are detected. Current other uses for console_verbose are in situations where kernel is in a panic path. [1]: kernel/locking/lockdep.c:lockdep_init_map_waits:4617 Signed-off-by: Elliot Berman <eberman@codeaurora.org> Link: https://lore.kernel.org/lkml/20210623045559.15750-1-eberman@codeaurora.org/ Bug: 191903062 Change-Id: If33587c49d316155a1745c9e0ef1a9ce23410a2b Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
2021-06-18 04:51:25 +09:00
if (debug_locks && __debug_locks_off() && !debug_locks_silent)
return 1;
return 0;
}
EXPORT_SYMBOL_GPL(debug_locks_off);