This can protect an infinit recursion by unnecessary warning, too.

-----8<-----
>From 81f06a6f9c7f2e782267a2539c6c869d4214354c Mon Sep 17 00:00:00 2001
From: Byungchul Park <byungchul.p...@lge.com>
Date: Fri, 18 Mar 2016 11:35:24 +0900
Subject: [PATCH] lib/spinlock_debug: Prevent a unnecessary recursive
 spin_dump()

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.p...@lge.com>
---
 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

Reply via email to