aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Thompson <daniel.thompson@linaro.org>2022-04-13 16:04:07 +0100
committerDaniel Thompson <daniel.thompson@linaro.org>2022-04-13 17:22:53 +0100
commit4f886ca3243fd3ede50a2064c548aa6a5ef5a65e (patch)
tree79464ecf0c1a7593aa81d67e5c1734d9c1251b61
parentd11936e6dfeb5eb28f5be3f5fe80de0d47b8de6a (diff)
kgdb: spinlock wrappers that degrade to trylock if halted for debug
kgdb (and kdb) runs in an unusual calling context and most spin locking whilst cores are halted inside the debugger risks deadlock. kgdb is largely successful in avoiding incorrect use of locks. However kdb has an element of "fingers crossed and hope" regarding lock correctness. In practice this isn't quite as awful as it sounds (users do not continually walk face first into deadlocks) but we need to start fixing some of these problems. The major problem with fixing them by avoiding locks altogether is that we end up with a robust-but-feature-free debugger that can't summarize the system state in a manner the developer at the keyboard can absorb. Let's try to tackle this by introducing locking calls that can degrade to trylock if we are running in the debugger. These new locking calls allow us to provide graceful failure instead of deadlock in some cases. They are also designed to permit dead-code elimination to keep !CONFIG_KGDB kernels from paying the cost. Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
-rw-r--r--include/linux/kgdb.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
index 258cdde8d356..9007037df142 100644
--- a/include/linux/kgdb.h
+++ b/include/linux/kgdb.h
@@ -366,4 +366,11 @@ extern void kgdb_free_init_mem(void);
static inline void kgdb_panic(const char *msg) {}
static inline void kgdb_free_init_mem(void) { }
#endif /* ! CONFIG_KGDB */
+
+#define raw_spin_lock_irqsave_dbg(lock, flags) \
+ (in_dbg_master() \
+ ? ({ raw_spin_trylock_irqsave(lock, flags); }) \
+ : ({ raw_spin_lock_irqsave(lock, flags); 1; }) \
+ )
+
#endif /* _KGDB_H_ */