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