Commit | Line | Data |
---|---|---|
e7eebaf6 IM |
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 | */ | |
e7eebaf6 IM |
19 | #include <linux/sched.h> |
20 | #include <linux/delay.h> | |
9984de1a | 21 | #include <linux/export.h> |
e7eebaf6 IM |
22 | #include <linux/spinlock.h> |
23 | #include <linux/kallsyms.h> | |
24 | #include <linux/syscalls.h> | |
25 | #include <linux/interrupt.h> | |
26 | #include <linux/plist.h> | |
27 | #include <linux/fs.h> | |
9a11b49a | 28 | #include <linux/debug_locks.h> |
e7eebaf6 IM |
29 | |
30 | #include "rtmutex_common.h" | |
31 | ||
36c8b586 | 32 | static void printk_task(struct task_struct *p) |
e7eebaf6 IM |
33 | { |
34 | if (p) | |
ba25f9dc | 35 | printk("%16s:%5d [%p, %3d]", p->comm, task_pid_nr(p), p, p->prio); |
e7eebaf6 IM |
36 | else |
37 | printk("<none>"); | |
38 | } | |
39 | ||
e7eebaf6 IM |
40 | static void printk_lock(struct rt_mutex *lock, int print_owner) |
41 | { | |
42 | if (lock->name) | |
43 | printk(" [%p] {%s}\n", | |
44 | lock, lock->name); | |
45 | else | |
46 | printk(" [%p] {%s:%d}\n", | |
47 | lock, lock->file, lock->line); | |
48 | ||
49 | if (print_owner && rt_mutex_owner(lock)) { | |
50 | printk(".. ->owner: %p\n", lock->owner); | |
51 | printk(".. held by: "); | |
52 | printk_task(rt_mutex_owner(lock)); | |
53 | printk("\n"); | |
54 | } | |
e7eebaf6 IM |
55 | } |
56 | ||
57 | void rt_mutex_debug_task_free(struct task_struct *task) | |
58 | { | |
0fa914c6 TG |
59 | DEBUG_LOCKS_WARN_ON(!plist_head_empty(&task->pi_waiters)); |
60 | DEBUG_LOCKS_WARN_ON(task->pi_blocked_on); | |
e7eebaf6 IM |
61 | } |
62 | ||
63 | /* | |
64 | * We fill out the fields in the waiter to store the information about | |
65 | * the deadlock. We print when we return. act_waiter can be NULL in | |
66 | * case of a remove waiter operation. | |
67 | */ | |
68 | void debug_rt_mutex_deadlock(int detect, struct rt_mutex_waiter *act_waiter, | |
69 | struct rt_mutex *lock) | |
70 | { | |
71 | struct task_struct *task; | |
72 | ||
0fa914c6 | 73 | if (!debug_locks || detect || !act_waiter) |
e7eebaf6 IM |
74 | return; |
75 | ||
76 | task = rt_mutex_owner(act_waiter->lock); | |
77 | if (task && task != current) { | |
48d13e48 | 78 | act_waiter->deadlock_task_pid = get_pid(task_pid(task)); |
e7eebaf6 IM |
79 | act_waiter->deadlock_lock = lock; |
80 | } | |
81 | } | |
82 | ||
83 | void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter) | |
84 | { | |
85 | struct task_struct *task; | |
86 | ||
0fa914c6 | 87 | if (!waiter->deadlock_lock || !debug_locks) |
e7eebaf6 IM |
88 | return; |
89 | ||
48d13e48 PE |
90 | rcu_read_lock(); |
91 | task = pid_task(waiter->deadlock_task_pid, PIDTYPE_PID); | |
92 | if (!task) { | |
93 | rcu_read_unlock(); | |
e7eebaf6 | 94 | return; |
48d13e48 | 95 | } |
e7eebaf6 | 96 | |
68cc3990 TG |
97 | if (!debug_locks_off()) { |
98 | rcu_read_unlock(); | |
0fa914c6 | 99 | return; |
68cc3990 | 100 | } |
e7eebaf6 IM |
101 | |
102 | printk("\n============================================\n"); | |
103 | printk( "[ BUG: circular locking deadlock detected! ]\n"); | |
fbdc4b9a | 104 | printk("%s\n", print_tainted()); |
e7eebaf6 IM |
105 | printk( "--------------------------------------------\n"); |
106 | printk("%s/%d is deadlocking current task %s/%d\n\n", | |
ba25f9dc PE |
107 | task->comm, task_pid_nr(task), |
108 | current->comm, task_pid_nr(current)); | |
e7eebaf6 IM |
109 | |
110 | printk("\n1) %s/%d is trying to acquire this lock:\n", | |
ba25f9dc | 111 | current->comm, task_pid_nr(current)); |
e7eebaf6 IM |
112 | printk_lock(waiter->lock, 1); |
113 | ||
ba25f9dc PE |
114 | printk("\n2) %s/%d is blocked on this lock:\n", |
115 | task->comm, task_pid_nr(task)); | |
e7eebaf6 IM |
116 | printk_lock(waiter->deadlock_lock, 1); |
117 | ||
9a11b49a IM |
118 | debug_show_held_locks(current); |
119 | debug_show_held_locks(task); | |
e7eebaf6 | 120 | |
ba25f9dc PE |
121 | printk("\n%s/%d's [blocked] stackdump:\n\n", |
122 | task->comm, task_pid_nr(task)); | |
e7eebaf6 IM |
123 | show_stack(task, NULL); |
124 | printk("\n%s/%d's [current] stackdump:\n\n", | |
ba25f9dc | 125 | current->comm, task_pid_nr(current)); |
e7eebaf6 | 126 | dump_stack(); |
9a11b49a | 127 | debug_show_all_locks(); |
48d13e48 | 128 | rcu_read_unlock(); |
9a11b49a | 129 | |
e7eebaf6 IM |
130 | printk("[ turning off deadlock detection." |
131 | "Please report this trace. ]\n\n"); | |
e7eebaf6 IM |
132 | } |
133 | ||
9a11b49a | 134 | void debug_rt_mutex_lock(struct rt_mutex *lock) |
e7eebaf6 | 135 | { |
e7eebaf6 IM |
136 | } |
137 | ||
138 | void debug_rt_mutex_unlock(struct rt_mutex *lock) | |
139 | { | |
0fa914c6 | 140 | DEBUG_LOCKS_WARN_ON(rt_mutex_owner(lock) != current); |
e7eebaf6 IM |
141 | } |
142 | ||
9a11b49a IM |
143 | void |
144 | debug_rt_mutex_proxy_lock(struct rt_mutex *lock, struct task_struct *powner) | |
e7eebaf6 | 145 | { |
e7eebaf6 IM |
146 | } |
147 | ||
148 | void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock) | |
149 | { | |
0fa914c6 | 150 | DEBUG_LOCKS_WARN_ON(!rt_mutex_owner(lock)); |
e7eebaf6 IM |
151 | } |
152 | ||
153 | void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter) | |
154 | { | |
155 | memset(waiter, 0x11, sizeof(*waiter)); | |
156 | plist_node_init(&waiter->list_entry, MAX_PRIO); | |
157 | plist_node_init(&waiter->pi_list_entry, MAX_PRIO); | |
48d13e48 | 158 | waiter->deadlock_task_pid = NULL; |
e7eebaf6 IM |
159 | } |
160 | ||
161 | void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter) | |
162 | { | |
48d13e48 | 163 | put_pid(waiter->deadlock_task_pid); |
0fa914c6 TG |
164 | DEBUG_LOCKS_WARN_ON(!plist_node_empty(&waiter->list_entry)); |
165 | DEBUG_LOCKS_WARN_ON(!plist_node_empty(&waiter->pi_list_entry)); | |
e7eebaf6 IM |
166 | memset(waiter, 0x22, sizeof(*waiter)); |
167 | } | |
168 | ||
169 | void debug_rt_mutex_init(struct rt_mutex *lock, const char *name) | |
170 | { | |
9a11b49a IM |
171 | /* |
172 | * Make sure we are not reinitializing a held lock: | |
173 | */ | |
174 | debug_check_no_locks_freed((void *)lock, sizeof(*lock)); | |
175 | lock->name = name; | |
e7eebaf6 IM |
176 | } |
177 | ||
36c8b586 IM |
178 | void |
179 | rt_mutex_deadlock_account_lock(struct rt_mutex *lock, struct task_struct *task) | |
e7eebaf6 IM |
180 | { |
181 | } | |
182 | ||
183 | void rt_mutex_deadlock_account_unlock(struct task_struct *task) | |
184 | { | |
185 | } | |
186 |