| .. | .. |
|---|
| 32 | 32 | |
|---|
| 33 | 33 | #include "rtmutex_common.h" |
|---|
| 34 | 34 | |
|---|
| 35 | | -static void printk_task(struct task_struct *p) |
|---|
| 36 | | -{ |
|---|
| 37 | | - if (p) |
|---|
| 38 | | - printk("%16s:%5d [%p, %3d]", p->comm, task_pid_nr(p), p, p->prio); |
|---|
| 39 | | - else |
|---|
| 40 | | - printk("<none>"); |
|---|
| 41 | | -} |
|---|
| 42 | | - |
|---|
| 43 | | -static void printk_lock(struct rt_mutex *lock, int print_owner) |
|---|
| 44 | | -{ |
|---|
| 45 | | - if (lock->name) |
|---|
| 46 | | - printk(" [%p] {%s}\n", |
|---|
| 47 | | - lock, lock->name); |
|---|
| 48 | | - else |
|---|
| 49 | | - printk(" [%p] {%s:%d}\n", |
|---|
| 50 | | - lock, lock->file, lock->line); |
|---|
| 51 | | - |
|---|
| 52 | | - if (print_owner && rt_mutex_owner(lock)) { |
|---|
| 53 | | - printk(".. ->owner: %p\n", lock->owner); |
|---|
| 54 | | - printk(".. held by: "); |
|---|
| 55 | | - printk_task(rt_mutex_owner(lock)); |
|---|
| 56 | | - printk("\n"); |
|---|
| 57 | | - } |
|---|
| 58 | | -} |
|---|
| 59 | | - |
|---|
| 60 | 35 | void rt_mutex_debug_task_free(struct task_struct *task) |
|---|
| 61 | 36 | { |
|---|
| 62 | 37 | DEBUG_LOCKS_WARN_ON(!RB_EMPTY_ROOT(&task->pi_waiters.rb_root)); |
|---|
| 63 | 38 | DEBUG_LOCKS_WARN_ON(task->pi_blocked_on); |
|---|
| 64 | | -} |
|---|
| 65 | | - |
|---|
| 66 | | -/* |
|---|
| 67 | | - * We fill out the fields in the waiter to store the information about |
|---|
| 68 | | - * the deadlock. We print when we return. act_waiter can be NULL in |
|---|
| 69 | | - * case of a remove waiter operation. |
|---|
| 70 | | - */ |
|---|
| 71 | | -void debug_rt_mutex_deadlock(enum rtmutex_chainwalk chwalk, |
|---|
| 72 | | - struct rt_mutex_waiter *act_waiter, |
|---|
| 73 | | - struct rt_mutex *lock) |
|---|
| 74 | | -{ |
|---|
| 75 | | - struct task_struct *task; |
|---|
| 76 | | - |
|---|
| 77 | | - if (!debug_locks || chwalk == RT_MUTEX_FULL_CHAINWALK || !act_waiter) |
|---|
| 78 | | - return; |
|---|
| 79 | | - |
|---|
| 80 | | - task = rt_mutex_owner(act_waiter->lock); |
|---|
| 81 | | - if (task && task != current) { |
|---|
| 82 | | - act_waiter->deadlock_task_pid = get_pid(task_pid(task)); |
|---|
| 83 | | - act_waiter->deadlock_lock = lock; |
|---|
| 84 | | - } |
|---|
| 85 | | -} |
|---|
| 86 | | - |
|---|
| 87 | | -void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter) |
|---|
| 88 | | -{ |
|---|
| 89 | | - struct task_struct *task; |
|---|
| 90 | | - |
|---|
| 91 | | - if (!waiter->deadlock_lock || !debug_locks) |
|---|
| 92 | | - return; |
|---|
| 93 | | - |
|---|
| 94 | | - rcu_read_lock(); |
|---|
| 95 | | - task = pid_task(waiter->deadlock_task_pid, PIDTYPE_PID); |
|---|
| 96 | | - if (!task) { |
|---|
| 97 | | - rcu_read_unlock(); |
|---|
| 98 | | - return; |
|---|
| 99 | | - } |
|---|
| 100 | | - |
|---|
| 101 | | - if (!debug_locks_off()) { |
|---|
| 102 | | - rcu_read_unlock(); |
|---|
| 103 | | - return; |
|---|
| 104 | | - } |
|---|
| 105 | | - |
|---|
| 106 | | - pr_warn("\n"); |
|---|
| 107 | | - pr_warn("============================================\n"); |
|---|
| 108 | | - pr_warn("WARNING: circular locking deadlock detected!\n"); |
|---|
| 109 | | - pr_warn("%s\n", print_tainted()); |
|---|
| 110 | | - pr_warn("--------------------------------------------\n"); |
|---|
| 111 | | - printk("%s/%d is deadlocking current task %s/%d\n\n", |
|---|
| 112 | | - task->comm, task_pid_nr(task), |
|---|
| 113 | | - current->comm, task_pid_nr(current)); |
|---|
| 114 | | - |
|---|
| 115 | | - printk("\n1) %s/%d is trying to acquire this lock:\n", |
|---|
| 116 | | - current->comm, task_pid_nr(current)); |
|---|
| 117 | | - printk_lock(waiter->lock, 1); |
|---|
| 118 | | - |
|---|
| 119 | | - printk("\n2) %s/%d is blocked on this lock:\n", |
|---|
| 120 | | - task->comm, task_pid_nr(task)); |
|---|
| 121 | | - printk_lock(waiter->deadlock_lock, 1); |
|---|
| 122 | | - |
|---|
| 123 | | - debug_show_held_locks(current); |
|---|
| 124 | | - debug_show_held_locks(task); |
|---|
| 125 | | - |
|---|
| 126 | | - printk("\n%s/%d's [blocked] stackdump:\n\n", |
|---|
| 127 | | - task->comm, task_pid_nr(task)); |
|---|
| 128 | | - show_stack(task, NULL); |
|---|
| 129 | | - printk("\n%s/%d's [current] stackdump:\n\n", |
|---|
| 130 | | - current->comm, task_pid_nr(current)); |
|---|
| 131 | | - dump_stack(); |
|---|
| 132 | | - debug_show_all_locks(); |
|---|
| 133 | | - rcu_read_unlock(); |
|---|
| 134 | | - |
|---|
| 135 | | - printk("[ turning off deadlock detection." |
|---|
| 136 | | - "Please report this trace. ]\n\n"); |
|---|
| 137 | 39 | } |
|---|
| 138 | 40 | |
|---|
| 139 | 41 | void debug_rt_mutex_lock(struct rt_mutex *lock) |
|---|
| .. | .. |
|---|
| 158 | 60 | void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter) |
|---|
| 159 | 61 | { |
|---|
| 160 | 62 | memset(waiter, 0x11, sizeof(*waiter)); |
|---|
| 161 | | - waiter->deadlock_task_pid = NULL; |
|---|
| 162 | 63 | } |
|---|
| 163 | 64 | |
|---|
| 164 | 65 | void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter) |
|---|
| 165 | 66 | { |
|---|
| 166 | | - put_pid(waiter->deadlock_task_pid); |
|---|
| 167 | 67 | memset(waiter, 0x22, sizeof(*waiter)); |
|---|
| 168 | 68 | } |
|---|
| 169 | 69 | |
|---|
| .. | .. |
|---|
| 173 | 73 | * Make sure we are not reinitializing a held lock: |
|---|
| 174 | 74 | */ |
|---|
| 175 | 75 | debug_check_no_locks_freed((void *)lock, sizeof(*lock)); |
|---|
| 176 | | - lock->name = name; |
|---|
| 177 | 76 | |
|---|
| 178 | 77 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
|---|
| 179 | 78 | lockdep_init_map(&lock->dep_map, name, key, 0); |
|---|
| 180 | 79 | #endif |
|---|
| 181 | 80 | } |
|---|
| 182 | | - |
|---|