Blame view

kernel/rtmutex-debug.c 4.68 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
  #include <linux/sched.h>
  #include <linux/delay.h>
9984de1a5   Paul Gortmaker   kernel: Map most ...
21
  #include <linux/export.h>
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
22
23
24
25
26
27
  #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"
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
31
  static void printk_task(struct task_struct *p)
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
32
33
  {
  	if (p)
ba25f9dcc   Pavel Emelyanov   Use helpers to ob...
34
  		printk("%16s:%5d [%p, %3d]", p->comm, task_pid_nr(p), p, p->prio);
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
35
36
37
  	else
  		printk("<none>");
  }
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  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:...
57
58
59
60
  }
  
  void rt_mutex_debug_task_free(struct task_struct *task)
  {
0fa914c63   Thomas Gleixner   rtmutex: Cleanup ...
61
62
  	DEBUG_LOCKS_WARN_ON(!plist_head_empty(&task->pi_waiters));
  	DEBUG_LOCKS_WARN_ON(task->pi_blocked_on);
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
63
64
65
66
67
68
69
70
71
72
73
  }
  
  /*
   * 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;
0fa914c63   Thomas Gleixner   rtmutex: Cleanup ...
74
  	if (!debug_locks || detect || !act_waiter)
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
75
76
77
78
  		return;
  
  	task = rt_mutex_owner(act_waiter->lock);
  	if (task && task != current) {
48d13e483   Pavel Emelyanov   Don't operate wit...
79
  		act_waiter->deadlock_task_pid = get_pid(task_pid(task));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
80
81
82
83
84
85
86
  		act_waiter->deadlock_lock = lock;
  	}
  }
  
  void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter)
  {
  	struct task_struct *task;
0fa914c63   Thomas Gleixner   rtmutex: Cleanup ...
87
  	if (!waiter->deadlock_lock || !debug_locks)
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
88
  		return;
48d13e483   Pavel Emelyanov   Don't operate wit...
89
90
91
92
  	rcu_read_lock();
  	task = pid_task(waiter->deadlock_task_pid, PIDTYPE_PID);
  	if (!task) {
  		rcu_read_unlock();
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
93
  		return;
48d13e483   Pavel Emelyanov   Don't operate wit...
94
  	}
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
95

68cc3990a   Thomas Gleixner   rtmutex: Add miss...
96
97
  	if (!debug_locks_off()) {
  		rcu_read_unlock();
0fa914c63   Thomas Gleixner   rtmutex: Cleanup ...
98
  		return;
68cc3990a   Thomas Gleixner   rtmutex: Add miss...
99
  	}
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
100
101
102
103
104
105
  
  	printk("
  ============================================
  ");
  	printk(  "[ BUG: circular locking deadlock detected! ]
  ");
fbdc4b9a6   Ben Hutchings   lockdep, rtmutex,...
106
107
  	printk("%s
  ", print_tainted());
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
108
109
110
111
112
  	printk(  "--------------------------------------------
  ");
  	printk("%s/%d is deadlocking current task %s/%d
  
  ",
ba25f9dcc   Pavel Emelyanov   Use helpers to ob...
113
114
  	       task->comm, task_pid_nr(task),
  	       current->comm, task_pid_nr(current));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
115
116
117
118
  
  	printk("
  1) %s/%d is trying to acquire this lock:
  ",
ba25f9dcc   Pavel Emelyanov   Use helpers to ob...
119
  	       current->comm, task_pid_nr(current));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
120
  	printk_lock(waiter->lock, 1);
ba25f9dcc   Pavel Emelyanov   Use helpers to ob...
121
122
123
124
  	printk("
  2) %s/%d is blocked on this lock:
  ",
  		task->comm, task_pid_nr(task));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
125
  	printk_lock(waiter->deadlock_lock, 1);
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
126
127
  	debug_show_held_locks(current);
  	debug_show_held_locks(task);
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
128

ba25f9dcc   Pavel Emelyanov   Use helpers to ob...
129
130
131
132
133
  	printk("
  %s/%d's [blocked] stackdump:
  
  ",
  		task->comm, task_pid_nr(task));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
134
135
136
137
138
  	show_stack(task, NULL);
  	printk("
  %s/%d's [current] stackdump:
  
  ",
ba25f9dcc   Pavel Emelyanov   Use helpers to ob...
139
  		current->comm, task_pid_nr(current));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
140
  	dump_stack();
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
141
  	debug_show_all_locks();
48d13e483   Pavel Emelyanov   Don't operate wit...
142
  	rcu_read_unlock();
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
143

e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
144
145
146
147
  	printk("[ turning off deadlock detection."
  	       "Please report this trace. ]
  
  ");
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
148
  }
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
149
  void debug_rt_mutex_lock(struct rt_mutex *lock)
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
150
  {
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
151
152
153
154
  }
  
  void debug_rt_mutex_unlock(struct rt_mutex *lock)
  {
0fa914c63   Thomas Gleixner   rtmutex: Cleanup ...
155
  	DEBUG_LOCKS_WARN_ON(rt_mutex_owner(lock) != current);
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
156
  }
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
157
158
  void
  debug_rt_mutex_proxy_lock(struct rt_mutex *lock, struct task_struct *powner)
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
159
  {
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
160
161
162
163
  }
  
  void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock)
  {
0fa914c63   Thomas Gleixner   rtmutex: Cleanup ...
164
  	DEBUG_LOCKS_WARN_ON(!rt_mutex_owner(lock));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
165
166
167
168
169
170
171
  }
  
  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...
172
  	waiter->deadlock_task_pid = NULL;
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
173
174
175
176
  }
  
  void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter)
  {
48d13e483   Pavel Emelyanov   Don't operate wit...
177
  	put_pid(waiter->deadlock_task_pid);
0fa914c63   Thomas Gleixner   rtmutex: Cleanup ...
178
179
  	DEBUG_LOCKS_WARN_ON(!plist_node_empty(&waiter->list_entry));
  	DEBUG_LOCKS_WARN_ON(!plist_node_empty(&waiter->pi_list_entry));
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
180
181
182
183
184
  	memset(waiter, 0x22, sizeof(*waiter));
  }
  
  void debug_rt_mutex_init(struct rt_mutex *lock, const char *name)
  {
9a11b49a8   Ingo Molnar   [PATCH] lockdep: ...
185
186
187
188
189
  	/*
  	 * 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:...
190
  }
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
191
192
  void
  rt_mutex_deadlock_account_lock(struct rt_mutex *lock, struct task_struct *task)
e7eebaf6a   Ingo Molnar   [PATCH] pi-futex:...
193
194
195
196
197
198
  {
  }
  
  void rt_mutex_deadlock_account_unlock(struct task_struct *task)
  {
  }