Blame view

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

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

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

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