Blame view

kernel/rtmutex-debug.c 5.72 KB
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  /*
   * RT-Mutexes: blocking mutual exclusion locks with PI support
   *
   * started by Ingo Molnar and Thomas Gleixner:
   *
   *  Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
   *  Copyright (C) 2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com>
   *
   * This code is based on the rt.c implementation in the preempt-rt tree.
   * Portions of said code are
   *
   *  Copyright (C) 2004  LynuxWorks, Inc., Igor Manyilov, Bill Huey
   *  Copyright (C) 2006  Esben Nielsen
   *  Copyright (C) 2006  Kihon Technologies Inc.,
   *			Steven Rostedt <rostedt@goodmis.org>
   *
   * See rt.c in preempt-rt for proper credits and further information
   */
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
19
20
21
22
23
24
25
26
27
  #include <linux/sched.h>
  #include <linux/delay.h>
  #include <linux/module.h>
  #include <linux/spinlock.h>
  #include <linux/kallsyms.h>
  #include <linux/syscalls.h>
  #include <linux/interrupt.h>
  #include <linux/plist.h>
  #include <linux/fs.h>
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
28
  #include <linux/debug_locks.h>
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
29
30
  
  #include "rtmutex_common.h"
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
31
32
33
34
35
36
37
38
  # define TRACE_WARN_ON(x)			WARN_ON(x)
  # define TRACE_BUG_ON(x)			BUG_ON(x)
  
  # define TRACE_OFF()						\
  do {								\
  	if (rt_trace_on) {					\
  		rt_trace_on = 0;				\
  		console_verbose();				\
1d6154825   Thomas Gleixner   sched: Convert pi...
39
40
  		if (raw_spin_is_locked(&current->pi_lock))	\
  			raw_spin_unlock(&current->pi_lock);	\
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  	}							\
  } while (0)
  
  # define TRACE_OFF_NOLOCK()					\
  do {								\
  	if (rt_trace_on) {					\
  		rt_trace_on = 0;				\
  		console_verbose();				\
  	}							\
  } while (0)
  
  # define TRACE_BUG_LOCKED()			\
  do {						\
  	TRACE_OFF();				\
  	BUG();					\
  } while (0)
  
  # define TRACE_WARN_ON_LOCKED(c)		\
  do {						\
  	if (unlikely(c)) {			\
  		TRACE_OFF();			\
  		WARN_ON(1);			\
  	}					\
  } while (0)
  
  # define TRACE_BUG_ON_LOCKED(c)			\
  do {						\
  	if (unlikely(c))			\
  		TRACE_BUG_LOCKED();		\
  } while (0)
  
  #ifdef CONFIG_SMP
  # define SMP_TRACE_BUG_ON_LOCKED(c)	TRACE_BUG_ON_LOCKED(c)
  #else
  # define SMP_TRACE_BUG_ON_LOCKED(c)	do { } while (0)
  #endif
  
  /*
   * deadlock detection flag. We turn it off when we detect
   * the first problem because we dont want to recurse back
   * into the tracing code when doing error printk or
   * executing a BUG():
   */
a4d63e729   Adrian Bunk   kernel/rtmutex-de...
84
  static int rt_trace_on = 1;
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
85

36c8b5868   Ingo Molnar   [PATCH] sched: cl...
86
  static void printk_task(struct task_struct *p)
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
87
88
  {
  	if (p)
ba25f9dcc   Pavel Emelyanov   Use helpers to ob...
89
  		printk("%16s:%5d [%p, %3d]", p->comm, task_pid_nr(p), p, p->prio);
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
90
91
92
  	else
  		printk("<none>");
  }
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  static void printk_lock(struct rt_mutex *lock, int print_owner)
  {
  	if (lock->name)
  		printk(" [%p] {%s}
  ",
  			lock, lock->name);
  	else
  		printk(" [%p] {%s:%d}
  ",
  			lock, lock->file, lock->line);
  
  	if (print_owner && rt_mutex_owner(lock)) {
  		printk(".. ->owner: %p
  ", lock->owner);
  		printk(".. held by:  ");
  		printk_task(rt_mutex_owner(lock));
  		printk("
  ");
  	}
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
  }
  
  void rt_mutex_debug_task_free(struct task_struct *task)
  {
  	WARN_ON(!plist_head_empty(&task->pi_waiters));
  	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(int detect, struct rt_mutex_waiter *act_waiter,
  			     struct rt_mutex *lock)
  {
  	struct task_struct *task;
  
  	if (!rt_trace_on || detect || !act_waiter)
  		return;
  
  	task = rt_mutex_owner(act_waiter->lock);
  	if (task && task != current) {
48d13e483   Pavel Emelyanov   Don't operate wit...
135
  		act_waiter->deadlock_task_pid = get_pid(task_pid(task));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
136
137
138
139
140
141
142
143
144
145
  		act_waiter->deadlock_lock = lock;
  	}
  }
  
  void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter)
  {
  	struct task_struct *task;
  
  	if (!waiter->deadlock_lock || !rt_trace_on)
  		return;
48d13e483   Pavel Emelyanov   Don't operate wit...
146
147
148
149
  	rcu_read_lock();
  	task = pid_task(waiter->deadlock_task_pid, PIDTYPE_PID);
  	if (!task) {
  		rcu_read_unlock();
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
150
  		return;
48d13e483   Pavel Emelyanov   Don't operate wit...
151
  	}
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
152
153
154
155
156
157
158
159
160
161
162
163
164
  
  	TRACE_OFF_NOLOCK();
  
  	printk("
  ============================================
  ");
  	printk(  "[ BUG: circular locking deadlock detected! ]
  ");
  	printk(  "--------------------------------------------
  ");
  	printk("%s/%d is deadlocking current task %s/%d
  
  ",
ba25f9dcc   Pavel Emelyanov   Use helpers to ob...
165
166
  	       task->comm, task_pid_nr(task),
  	       current->comm, task_pid_nr(current));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
167
168
169
170
  
  	printk("
  1) %s/%d is trying to acquire this lock:
  ",
ba25f9dcc   Pavel Emelyanov   Use helpers to ob...
171
  	       current->comm, task_pid_nr(current));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
172
  	printk_lock(waiter->lock, 1);
ba25f9dcc   Pavel Emelyanov   Use helpers to ob...
173
174
175
176
  	printk("
  2) %s/%d is blocked on this lock:
  ",
  		task->comm, task_pid_nr(task));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
177
  	printk_lock(waiter->deadlock_lock, 1);
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
178
179
  	debug_show_held_locks(current);
  	debug_show_held_locks(task);
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
180

ba25f9dcc   Pavel Emelyanov   Use helpers to ob...
181
182
183
184
185
  	printk("
  %s/%d's [blocked] stackdump:
  
  ",
  		task->comm, task_pid_nr(task));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
186
187
188
189
190
  	show_stack(task, NULL);
  	printk("
  %s/%d's [current] stackdump:
  
  ",
ba25f9dcc   Pavel Emelyanov   Use helpers to ob...
191
  		current->comm, task_pid_nr(current));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
192
  	dump_stack();
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
193
  	debug_show_all_locks();
48d13e483   Pavel Emelyanov   Don't operate wit...
194
  	rcu_read_unlock();
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
195

e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
196
197
198
199
200
201
  	printk("[ turning off deadlock detection."
  	       "Please report this trace. ]
  
  ");
  	local_irq_disable();
  }
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
202
  void debug_rt_mutex_lock(struct rt_mutex *lock)
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
203
  {
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
204
205
206
207
  }
  
  void debug_rt_mutex_unlock(struct rt_mutex *lock)
  {
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
208
  	TRACE_WARN_ON_LOCKED(rt_mutex_owner(lock) != current);
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
209
  }
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
210
211
  void
  debug_rt_mutex_proxy_lock(struct rt_mutex *lock, struct task_struct *powner)
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
212
  {
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
213
214
215
216
  }
  
  void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock)
  {
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
217
  	TRACE_WARN_ON_LOCKED(!rt_mutex_owner(lock));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
218
219
220
221
222
223
224
  }
  
  void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter)
  {
  	memset(waiter, 0x11, sizeof(*waiter));
  	plist_node_init(&waiter->list_entry, MAX_PRIO);
  	plist_node_init(&waiter->pi_list_entry, MAX_PRIO);
48d13e483   Pavel Emelyanov   Don't operate wit...
225
  	waiter->deadlock_task_pid = NULL;
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
226
227
228
229
  }
  
  void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter)
  {
48d13e483   Pavel Emelyanov   Don't operate wit...
230
  	put_pid(waiter->deadlock_task_pid);
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
231
232
  	TRACE_WARN_ON(!plist_node_empty(&waiter->list_entry));
  	TRACE_WARN_ON(!plist_node_empty(&waiter->pi_list_entry));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
233
234
235
236
237
  	memset(waiter, 0x22, sizeof(*waiter));
  }
  
  void debug_rt_mutex_init(struct rt_mutex *lock, const char *name)
  {
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
238
239
240
241
242
  	/*
  	 * Make sure we are not reinitializing a held lock:
  	 */
  	debug_check_no_locks_freed((void *)lock, sizeof(*lock));
  	lock->name = name;
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
243
  }
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
244
245
  void
  rt_mutex_deadlock_account_lock(struct rt_mutex *lock, struct task_struct *task)
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
246
247
248
249
250
251
  {
  }
  
  void rt_mutex_deadlock_account_unlock(struct task_struct *task)
  {
  }