Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * RT-Mutexes: blocking mutual exclusion locks with PI support |
| 3 | * |
| 4 | * started by Ingo Molnar and Thomas Gleixner: |
| 5 | * |
| 6 | * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com> |
| 7 | * Copyright (C) 2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com> |
| 8 | * |
| 9 | * This code is based on the rt.c implementation in the preempt-rt tree. |
| 10 | * Portions of said code are |
| 11 | * |
| 12 | * Copyright (C) 2004 LynuxWorks, Inc., Igor Manyilov, Bill Huey |
| 13 | * Copyright (C) 2006 Esben Nielsen |
| 14 | * Copyright (C) 2006 Kihon Technologies Inc., |
| 15 | * Steven Rostedt <rostedt@goodmis.org> |
| 16 | * |
| 17 | * See rt.c in preempt-rt for proper credits and further information |
| 18 | */ |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 19 | #include <linux/sched.h> |
Clark Williams | 8bd75c7 | 2013-02-07 09:47:07 -0600 | [diff] [blame] | 20 | #include <linux/sched/rt.h> |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 21 | #include <linux/delay.h> |
Paul Gortmaker | 9984de1 | 2011-05-23 14:51:41 -0400 | [diff] [blame] | 22 | #include <linux/export.h> |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 23 | #include <linux/spinlock.h> |
| 24 | #include <linux/kallsyms.h> |
| 25 | #include <linux/syscalls.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/plist.h> |
| 28 | #include <linux/fs.h> |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 29 | #include <linux/debug_locks.h> |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 30 | |
| 31 | #include "rtmutex_common.h" |
| 32 | |
Ingo Molnar | 36c8b58 | 2006-07-03 00:25:41 -0700 | [diff] [blame] | 33 | static void printk_task(struct task_struct *p) |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 34 | { |
| 35 | if (p) |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 36 | printk("%16s:%5d [%p, %3d]", p->comm, task_pid_nr(p), p, p->prio); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 37 | else |
| 38 | printk("<none>"); |
| 39 | } |
| 40 | |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 41 | static void printk_lock(struct rt_mutex *lock, int print_owner) |
| 42 | { |
| 43 | if (lock->name) |
| 44 | printk(" [%p] {%s}\n", |
| 45 | lock, lock->name); |
| 46 | else |
| 47 | printk(" [%p] {%s:%d}\n", |
| 48 | lock, lock->file, lock->line); |
| 49 | |
| 50 | if (print_owner && rt_mutex_owner(lock)) { |
| 51 | printk(".. ->owner: %p\n", lock->owner); |
| 52 | printk(".. held by: "); |
| 53 | printk_task(rt_mutex_owner(lock)); |
| 54 | printk("\n"); |
| 55 | } |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void rt_mutex_debug_task_free(struct task_struct *task) |
| 59 | { |
Thomas Gleixner | 0fa914c | 2011-06-08 09:58:38 +0200 | [diff] [blame] | 60 | DEBUG_LOCKS_WARN_ON(!plist_head_empty(&task->pi_waiters)); |
| 61 | DEBUG_LOCKS_WARN_ON(task->pi_blocked_on); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /* |
| 65 | * We fill out the fields in the waiter to store the information about |
| 66 | * the deadlock. We print when we return. act_waiter can be NULL in |
| 67 | * case of a remove waiter operation. |
| 68 | */ |
| 69 | void debug_rt_mutex_deadlock(int detect, struct rt_mutex_waiter *act_waiter, |
| 70 | struct rt_mutex *lock) |
| 71 | { |
| 72 | struct task_struct *task; |
| 73 | |
Thomas Gleixner | 0fa914c | 2011-06-08 09:58:38 +0200 | [diff] [blame] | 74 | if (!debug_locks || detect || !act_waiter) |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 75 | return; |
| 76 | |
| 77 | task = rt_mutex_owner(act_waiter->lock); |
| 78 | if (task && task != current) { |
Pavel Emelyanov | 48d13e4 | 2008-02-08 04:21:53 -0800 | [diff] [blame] | 79 | act_waiter->deadlock_task_pid = get_pid(task_pid(task)); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 80 | act_waiter->deadlock_lock = lock; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter) |
| 85 | { |
| 86 | struct task_struct *task; |
| 87 | |
Thomas Gleixner | 0fa914c | 2011-06-08 09:58:38 +0200 | [diff] [blame] | 88 | if (!waiter->deadlock_lock || !debug_locks) |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 89 | return; |
| 90 | |
Pavel Emelyanov | 48d13e4 | 2008-02-08 04:21:53 -0800 | [diff] [blame] | 91 | rcu_read_lock(); |
| 92 | task = pid_task(waiter->deadlock_task_pid, PIDTYPE_PID); |
| 93 | if (!task) { |
| 94 | rcu_read_unlock(); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 95 | return; |
Pavel Emelyanov | 48d13e4 | 2008-02-08 04:21:53 -0800 | [diff] [blame] | 96 | } |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 97 | |
Thomas Gleixner | 68cc399 | 2011-10-05 13:20:24 +0200 | [diff] [blame] | 98 | if (!debug_locks_off()) { |
| 99 | rcu_read_unlock(); |
Thomas Gleixner | 0fa914c | 2011-06-08 09:58:38 +0200 | [diff] [blame] | 100 | return; |
Thomas Gleixner | 68cc399 | 2011-10-05 13:20:24 +0200 | [diff] [blame] | 101 | } |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 102 | |
| 103 | printk("\n============================================\n"); |
| 104 | printk( "[ BUG: circular locking deadlock detected! ]\n"); |
Ben Hutchings | fbdc4b9 | 2011-10-28 04:36:55 +0100 | [diff] [blame] | 105 | printk("%s\n", print_tainted()); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 106 | printk( "--------------------------------------------\n"); |
| 107 | printk("%s/%d is deadlocking current task %s/%d\n\n", |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 108 | task->comm, task_pid_nr(task), |
| 109 | current->comm, task_pid_nr(current)); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 110 | |
| 111 | printk("\n1) %s/%d is trying to acquire this lock:\n", |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 112 | current->comm, task_pid_nr(current)); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 113 | printk_lock(waiter->lock, 1); |
| 114 | |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 115 | printk("\n2) %s/%d is blocked on this lock:\n", |
| 116 | task->comm, task_pid_nr(task)); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 117 | printk_lock(waiter->deadlock_lock, 1); |
| 118 | |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 119 | debug_show_held_locks(current); |
| 120 | debug_show_held_locks(task); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 121 | |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 122 | printk("\n%s/%d's [blocked] stackdump:\n\n", |
| 123 | task->comm, task_pid_nr(task)); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 124 | show_stack(task, NULL); |
| 125 | printk("\n%s/%d's [current] stackdump:\n\n", |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 126 | current->comm, task_pid_nr(current)); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 127 | dump_stack(); |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 128 | debug_show_all_locks(); |
Pavel Emelyanov | 48d13e4 | 2008-02-08 04:21:53 -0800 | [diff] [blame] | 129 | rcu_read_unlock(); |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 130 | |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 131 | printk("[ turning off deadlock detection." |
| 132 | "Please report this trace. ]\n\n"); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 135 | void debug_rt_mutex_lock(struct rt_mutex *lock) |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 136 | { |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | void debug_rt_mutex_unlock(struct rt_mutex *lock) |
| 140 | { |
Thomas Gleixner | 0fa914c | 2011-06-08 09:58:38 +0200 | [diff] [blame] | 141 | DEBUG_LOCKS_WARN_ON(rt_mutex_owner(lock) != current); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 144 | void |
| 145 | debug_rt_mutex_proxy_lock(struct rt_mutex *lock, struct task_struct *powner) |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 146 | { |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock) |
| 150 | { |
Thomas Gleixner | 0fa914c | 2011-06-08 09:58:38 +0200 | [diff] [blame] | 151 | DEBUG_LOCKS_WARN_ON(!rt_mutex_owner(lock)); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter) |
| 155 | { |
| 156 | memset(waiter, 0x11, sizeof(*waiter)); |
| 157 | plist_node_init(&waiter->list_entry, MAX_PRIO); |
| 158 | plist_node_init(&waiter->pi_list_entry, MAX_PRIO); |
Pavel Emelyanov | 48d13e4 | 2008-02-08 04:21:53 -0800 | [diff] [blame] | 159 | waiter->deadlock_task_pid = NULL; |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter) |
| 163 | { |
Pavel Emelyanov | 48d13e4 | 2008-02-08 04:21:53 -0800 | [diff] [blame] | 164 | put_pid(waiter->deadlock_task_pid); |
Thomas Gleixner | 0fa914c | 2011-06-08 09:58:38 +0200 | [diff] [blame] | 165 | DEBUG_LOCKS_WARN_ON(!plist_node_empty(&waiter->list_entry)); |
| 166 | DEBUG_LOCKS_WARN_ON(!plist_node_empty(&waiter->pi_list_entry)); |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 167 | memset(waiter, 0x22, sizeof(*waiter)); |
| 168 | } |
| 169 | |
| 170 | void debug_rt_mutex_init(struct rt_mutex *lock, const char *name) |
| 171 | { |
Ingo Molnar | 9a11b49a | 2006-07-03 00:24:33 -0700 | [diff] [blame] | 172 | /* |
| 173 | * Make sure we are not reinitializing a held lock: |
| 174 | */ |
| 175 | debug_check_no_locks_freed((void *)lock, sizeof(*lock)); |
| 176 | lock->name = name; |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Ingo Molnar | 36c8b58 | 2006-07-03 00:25:41 -0700 | [diff] [blame] | 179 | void |
| 180 | rt_mutex_deadlock_account_lock(struct rt_mutex *lock, struct task_struct *task) |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 181 | { |
| 182 | } |
| 183 | |
| 184 | void rt_mutex_deadlock_account_unlock(struct task_struct *task) |
| 185 | { |
| 186 | } |
| 187 | |