[PATCH] lib/spinlock_debug: Prevent a unnecessary recursive spin_dump()
From: Byungchul Park
Date: Thu Mar 17 2016 - 22:35:24 EST
Printing "lockup suspected" for the same lock more than once is
meaningless. Furtheremore, it can cause an infinite recursion if it's
on the way printing something by printk().
Signed-off-by: Byungchul Park <byungchul.park@xxxxxxx>
---
kernel/locking/spinlock_debug.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/kernel/locking/spinlock_debug.c b/kernel/locking/spinlock_debug.c
index fd24588..30559c6 100644
--- a/kernel/locking/spinlock_debug.c
+++ b/kernel/locking/spinlock_debug.c
@@ -138,14 +138,25 @@ static void __spin_lock_debug(raw_spinlock_t *lock)
{
u64 i;
u64 loops = loops_per_jiffy * HZ;
+ static raw_spinlock_t *suspected_lock = NULL;
for (i = 0; i < loops; i++) {
if (arch_spin_trylock(&lock->raw_lock))
return;
__delay(1);
}
- /* lockup suspected: */
- spin_dump(lock, "lockup suspected");
+
+ /*
+ * When we suspect a lockup, it's good enough to inform it once for
+ * the same lock. Otherwise it could cause an infinite recursion if
+ * it's within printk().
+ */
+ if (suspected_lock != lock) {
+ suspected_lock = lock;
+ /* lockup suspected: */
+ spin_dump(lock, "lockup suspected");
+ suspected_lock = NULL;
+ }
#ifdef CONFIG_SMP
trigger_all_cpu_backtrace();
#endif
--
1.9.1