locking/rtmutex: Remove output from deadlock detector
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Fri, 26 Mar 2021 15:29:32 +0000 (16:29 +0100)
committerIngo Molnar <mingo@kernel.org>
Mon, 29 Mar 2021 13:57:02 +0000 (15:57 +0200)
The rtmutex specific deadlock detector predates lockdep coverage of rtmutex
and since commit f5694788ad8da ("rt_mutex: Add lockdep annotations") it
contains a lot of redundant functionality:

 - lockdep will detect an potential deadlock before rtmutex-debug
   has a chance to do so

 - the deadlock debugging is restricted to rtmutexes which are not
   associated to futexes and have an active waiter, which is covered by
   lockdep already

Remove the redundant functionality and move actual deadlock WARN() into the
deadlock code path. The latter needs a seperate cleanup.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210326153943.320398604@linutronix.de
include/linux/rtmutex.h
kernel/locking/rtmutex-debug.c
kernel/locking/rtmutex-debug.h
kernel/locking/rtmutex.c
kernel/locking/rtmutex.h
kernel/locking/rtmutex_common.h

index 48b334b9eb87074cb05733f69110c18a339874e6..0725c4b45749da021f89d0ff2d951530c1e9e9af 100644 (file)
@@ -31,9 +31,6 @@ struct rt_mutex {
        raw_spinlock_t          wait_lock;
        struct rb_root_cached   waiters;
        struct task_struct      *owner;
-#ifdef CONFIG_DEBUG_RT_MUTEXES
-       const char              *name;
-#endif
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
        struct lockdep_map      dep_map;
 #endif
@@ -56,8 +53,6 @@ struct hrtimer_sleeper;
 #endif
 
 #ifdef CONFIG_DEBUG_RT_MUTEXES
-# define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
-       , .name = #mutexname
 
 # define rt_mutex_init(mutex) \
 do { \
@@ -67,7 +62,6 @@ do { \
 
  extern void rt_mutex_debug_task_free(struct task_struct *tsk);
 #else
-# define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
 # define rt_mutex_init(mutex)                  __rt_mutex_init(mutex, NULL, NULL)
 # define rt_mutex_debug_task_free(t)                   do { } while (0)
 #endif
@@ -83,7 +77,6 @@ do { \
        { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
        , .waiters = RB_ROOT_CACHED \
        , .owner = NULL \
-       __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
        __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)}
 
 #define DEFINE_RT_MUTEX(mutexname) \
index 7e411b946d4c36ba83e0a44e4485d442054e23c1..fb150100335fcefc8e5a08188d50f4ea0865d778 100644 (file)
 
 #include "rtmutex_common.h"
 
-static void printk_task(struct task_struct *p)
-{
-       if (p)
-               printk("%16s:%5d [%p, %3d]", p->comm, task_pid_nr(p), p, p->prio);
-       else
-               printk("<none>");
-}
-
-static void printk_lock(struct rt_mutex *lock, int print_owner)
-{
-       printk(" [%p] {%s}\n", lock, lock->name);
-
-       if (print_owner && rt_mutex_owner(lock)) {
-               printk(".. ->owner: %p\n", lock->owner);
-               printk(".. held by:  ");
-               printk_task(rt_mutex_owner(lock));
-               printk("\n");
-       }
-}
-
 void rt_mutex_debug_task_free(struct task_struct *task)
 {
        DEBUG_LOCKS_WARN_ON(!RB_EMPTY_ROOT(&task->pi_waiters.rb_root));
        DEBUG_LOCKS_WARN_ON(task->pi_blocked_on);
 }
 
-/*
- * We fill out the fields in the waiter to store the information about
- * the deadlock. We print when we return. act_waiter can be NULL in
- * case of a remove waiter operation.
- */
-void debug_rt_mutex_deadlock(enum rtmutex_chainwalk chwalk,
-                            struct rt_mutex_waiter *act_waiter,
-                            struct rt_mutex *lock)
-{
-       struct task_struct *task;
-
-       if (!debug_locks || chwalk == RT_MUTEX_FULL_CHAINWALK || !act_waiter)
-               return;
-
-       task = rt_mutex_owner(act_waiter->lock);
-       if (task && task != current) {
-               act_waiter->deadlock_task_pid = get_pid(task_pid(task));
-               act_waiter->deadlock_lock = lock;
-       }
-}
-
-void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter)
-{
-       struct task_struct *task;
-
-       if (!waiter->deadlock_lock || !debug_locks)
-               return;
-
-       rcu_read_lock();
-       task = pid_task(waiter->deadlock_task_pid, PIDTYPE_PID);
-       if (!task) {
-               rcu_read_unlock();
-               return;
-       }
-
-       if (!debug_locks_off()) {
-               rcu_read_unlock();
-               return;
-       }
-
-       pr_warn("\n");
-       pr_warn("============================================\n");
-       pr_warn("WARNING: circular locking deadlock detected!\n");
-       pr_warn("%s\n", print_tainted());
-       pr_warn("--------------------------------------------\n");
-       printk("%s/%d is deadlocking current task %s/%d\n\n",
-              task->comm, task_pid_nr(task),
-              current->comm, task_pid_nr(current));
-
-       printk("\n1) %s/%d is trying to acquire this lock:\n",
-              current->comm, task_pid_nr(current));
-       printk_lock(waiter->lock, 1);
-
-       printk("\n2) %s/%d is blocked on this lock:\n",
-               task->comm, task_pid_nr(task));
-       printk_lock(waiter->deadlock_lock, 1);
-
-       debug_show_held_locks(current);
-       debug_show_held_locks(task);
-
-       printk("\n%s/%d's [blocked] stackdump:\n\n",
-               task->comm, task_pid_nr(task));
-       show_stack(task, NULL, KERN_DEFAULT);
-       printk("\n%s/%d's [current] stackdump:\n\n",
-               current->comm, task_pid_nr(current));
-       dump_stack();
-       debug_show_all_locks();
-       rcu_read_unlock();
-
-       printk("[ turning off deadlock detection."
-              "Please report this trace. ]\n\n");
-}
-
 void debug_rt_mutex_lock(struct rt_mutex *lock)
 {
 }
@@ -153,12 +60,10 @@ void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock)
 void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter)
 {
        memset(waiter, 0x11, sizeof(*waiter));
-       waiter->deadlock_task_pid = NULL;
 }
 
 void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter)
 {
-       put_pid(waiter->deadlock_task_pid);
        memset(waiter, 0x22, sizeof(*waiter));
 }
 
@@ -168,10 +73,8 @@ void debug_rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_cl
         * Make sure we are not reinitializing a held lock:
         */
        debug_check_no_locks_freed((void *)lock, sizeof(*lock));
-       lock->name = name;
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
        lockdep_init_map(&lock->dep_map, name, key, 0);
 #endif
 }
-
index 772c9b012b62377f0207fd8fda8a703fd9fe0355..659e93e256c67775a289b975e0432700363e157a 100644 (file)
@@ -18,18 +18,9 @@ extern void debug_rt_mutex_unlock(struct rt_mutex *lock);
 extern void debug_rt_mutex_proxy_lock(struct rt_mutex *lock,
                                      struct task_struct *powner);
 extern void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock);
-extern void debug_rt_mutex_deadlock(enum rtmutex_chainwalk chwalk,
-                                   struct rt_mutex_waiter *waiter,
-                                   struct rt_mutex *lock);
-extern void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter);
 
 static inline bool debug_rt_mutex_detect_deadlock(struct rt_mutex_waiter *waiter,
                                                  enum rtmutex_chainwalk walk)
 {
        return (waiter != NULL);
 }
-
-static inline void rt_mutex_print_deadlock(struct rt_mutex_waiter *w)
-{
-       debug_rt_mutex_print_deadlock(w);
-}
index 11abc60d147810a5e848d6c3dd0a677f2c25410c..4beca549aeebd4c785496021e18d8648be6ffc39 100644 (file)
@@ -579,7 +579,6 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
         * walk, we detected a deadlock.
         */
        if (lock == orig_lock || rt_mutex_owner(lock) == top_task) {
-               debug_rt_mutex_deadlock(chwalk, orig_waiter, lock);
                raw_spin_unlock(&lock->wait_lock);
                ret = -EDEADLK;
                goto out_unlock_pi;
@@ -1171,8 +1170,6 @@ __rt_mutex_slowlock(struct rt_mutex *lock, int state,
 
                raw_spin_unlock_irq(&lock->wait_lock);
 
-               debug_rt_mutex_print_deadlock(waiter);
-
                schedule();
 
                raw_spin_lock_irq(&lock->wait_lock);
@@ -1196,7 +1193,7 @@ static void rt_mutex_handle_deadlock(int res, int detect_deadlock,
        /*
         * Yell loudly and stop the task right here.
         */
-       rt_mutex_print_deadlock(w);
+       WARN(1, "rtmutex deadlock detected\n");
        while (1) {
                set_current_state(TASK_INTERRUPTIBLE);
                schedule();
@@ -1704,8 +1701,6 @@ int __rt_mutex_start_proxy_lock(struct rt_mutex *lock,
                ret = 0;
        }
 
-       debug_rt_mutex_print_deadlock(waiter);
-
        return ret;
 }
 
index 4dbdec15f1a035dfa3facf6e9420058aa8957a48..d77cb8280aa64b33985c6c8ddad67c887505d25e 100644 (file)
 #define debug_rt_mutex_proxy_unlock(l)                 do { } while (0)
 #define debug_rt_mutex_unlock(l)                       do { } while (0)
 #define debug_rt_mutex_init(m, n, k)                   do { } while (0)
-#define debug_rt_mutex_deadlock(d, a ,l)               do { } while (0)
-#define debug_rt_mutex_print_deadlock(w)               do { } while (0)
-
-static inline void rt_mutex_print_deadlock(struct rt_mutex_waiter *w)
-{
-       WARN(1, "rtmutex deadlock detected\n");
-}
 
 static inline bool debug_rt_mutex_detect_deadlock(struct rt_mutex_waiter *w,
                                                  enum rtmutex_chainwalk walk)
index aa047436dadfbceb59b82fc96bd7dca647307a7b..badb2a2803aae2c8f3e8d582d2e6e955b03c96de 100644 (file)
@@ -29,10 +29,6 @@ struct rt_mutex_waiter {
        struct rb_node          pi_tree_entry;
        struct task_struct      *task;
        struct rt_mutex         *lock;
-#ifdef CONFIG_DEBUG_RT_MUTEXES
-       struct pid              *deadlock_task_pid;
-       struct rt_mutex         *deadlock_lock;
-#endif
        int prio;
        u64 deadline;
 };