blob: 8eafd1bd273ed43dd3b4f35898241530e851e719 [file] [log] [blame]
Ingo Molnare7eebaf2006-06-27 02:54:55 -07001/*
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 */
Ingo Molnare7eebaf2006-06-27 02:54:55 -070019#include <linux/sched.h>
20#include <linux/delay.h>
Paul Gortmaker9984de12011-05-23 14:51:41 -040021#include <linux/export.h>
Ingo Molnare7eebaf2006-06-27 02:54:55 -070022#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>
Ingo Molnar9a11b49a2006-07-03 00:24:33 -070028#include <linux/debug_locks.h>
Ingo Molnare7eebaf2006-06-27 02:54:55 -070029
30#include "rtmutex_common.h"
31
Ingo Molnar36c8b582006-07-03 00:25:41 -070032static void printk_task(struct task_struct *p)
Ingo Molnare7eebaf2006-06-27 02:54:55 -070033{
34 if (p)
Pavel Emelyanovba25f9d2007-10-18 23:40:40 -070035 printk("%16s:%5d [%p, %3d]", p->comm, task_pid_nr(p), p, p->prio);
Ingo Molnare7eebaf2006-06-27 02:54:55 -070036 else
37 printk("<none>");
38}
39
Ingo Molnare7eebaf2006-06-27 02:54:55 -070040static 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 }
Ingo Molnare7eebaf2006-06-27 02:54:55 -070055}
56
57void rt_mutex_debug_task_free(struct task_struct *task)
58{
Thomas Gleixner0fa914c2011-06-08 09:58:38 +020059 DEBUG_LOCKS_WARN_ON(!plist_head_empty(&task->pi_waiters));
60 DEBUG_LOCKS_WARN_ON(task->pi_blocked_on);
Ingo Molnare7eebaf2006-06-27 02:54:55 -070061}
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 */
68void debug_rt_mutex_deadlock(int detect, struct rt_mutex_waiter *act_waiter,
69 struct rt_mutex *lock)
70{
71 struct task_struct *task;
72
Thomas Gleixner0fa914c2011-06-08 09:58:38 +020073 if (!debug_locks || detect || !act_waiter)
Ingo Molnare7eebaf2006-06-27 02:54:55 -070074 return;
75
76 task = rt_mutex_owner(act_waiter->lock);
77 if (task && task != current) {
Pavel Emelyanov48d13e42008-02-08 04:21:53 -080078 act_waiter->deadlock_task_pid = get_pid(task_pid(task));
Ingo Molnare7eebaf2006-06-27 02:54:55 -070079 act_waiter->deadlock_lock = lock;
80 }
81}
82
83void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter)
84{
85 struct task_struct *task;
86
Thomas Gleixner0fa914c2011-06-08 09:58:38 +020087 if (!waiter->deadlock_lock || !debug_locks)
Ingo Molnare7eebaf2006-06-27 02:54:55 -070088 return;
89
Pavel Emelyanov48d13e42008-02-08 04:21:53 -080090 rcu_read_lock();
91 task = pid_task(waiter->deadlock_task_pid, PIDTYPE_PID);
92 if (!task) {
93 rcu_read_unlock();
Ingo Molnare7eebaf2006-06-27 02:54:55 -070094 return;
Pavel Emelyanov48d13e42008-02-08 04:21:53 -080095 }
Ingo Molnare7eebaf2006-06-27 02:54:55 -070096
Thomas Gleixner68cc3992011-10-05 13:20:24 +020097 if (!debug_locks_off()) {
98 rcu_read_unlock();
Thomas Gleixner0fa914c2011-06-08 09:58:38 +020099 return;
Thomas Gleixner68cc3992011-10-05 13:20:24 +0200100 }
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700101
102 printk("\n============================================\n");
103 printk( "[ BUG: circular locking deadlock detected! ]\n");
104 printk( "--------------------------------------------\n");
105 printk("%s/%d is deadlocking current task %s/%d\n\n",
Pavel Emelyanovba25f9d2007-10-18 23:40:40 -0700106 task->comm, task_pid_nr(task),
107 current->comm, task_pid_nr(current));
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700108
109 printk("\n1) %s/%d is trying to acquire this lock:\n",
Pavel Emelyanovba25f9d2007-10-18 23:40:40 -0700110 current->comm, task_pid_nr(current));
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700111 printk_lock(waiter->lock, 1);
112
Pavel Emelyanovba25f9d2007-10-18 23:40:40 -0700113 printk("\n2) %s/%d is blocked on this lock:\n",
114 task->comm, task_pid_nr(task));
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700115 printk_lock(waiter->deadlock_lock, 1);
116
Ingo Molnar9a11b49a2006-07-03 00:24:33 -0700117 debug_show_held_locks(current);
118 debug_show_held_locks(task);
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700119
Pavel Emelyanovba25f9d2007-10-18 23:40:40 -0700120 printk("\n%s/%d's [blocked] stackdump:\n\n",
121 task->comm, task_pid_nr(task));
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700122 show_stack(task, NULL);
123 printk("\n%s/%d's [current] stackdump:\n\n",
Pavel Emelyanovba25f9d2007-10-18 23:40:40 -0700124 current->comm, task_pid_nr(current));
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700125 dump_stack();
Ingo Molnar9a11b49a2006-07-03 00:24:33 -0700126 debug_show_all_locks();
Pavel Emelyanov48d13e42008-02-08 04:21:53 -0800127 rcu_read_unlock();
Ingo Molnar9a11b49a2006-07-03 00:24:33 -0700128
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700129 printk("[ turning off deadlock detection."
130 "Please report this trace. ]\n\n");
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700131}
132
Ingo Molnar9a11b49a2006-07-03 00:24:33 -0700133void debug_rt_mutex_lock(struct rt_mutex *lock)
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700134{
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700135}
136
137void debug_rt_mutex_unlock(struct rt_mutex *lock)
138{
Thomas Gleixner0fa914c2011-06-08 09:58:38 +0200139 DEBUG_LOCKS_WARN_ON(rt_mutex_owner(lock) != current);
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700140}
141
Ingo Molnar9a11b49a2006-07-03 00:24:33 -0700142void
143debug_rt_mutex_proxy_lock(struct rt_mutex *lock, struct task_struct *powner)
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700144{
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700145}
146
147void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock)
148{
Thomas Gleixner0fa914c2011-06-08 09:58:38 +0200149 DEBUG_LOCKS_WARN_ON(!rt_mutex_owner(lock));
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700150}
151
152void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter)
153{
154 memset(waiter, 0x11, sizeof(*waiter));
155 plist_node_init(&waiter->list_entry, MAX_PRIO);
156 plist_node_init(&waiter->pi_list_entry, MAX_PRIO);
Pavel Emelyanov48d13e42008-02-08 04:21:53 -0800157 waiter->deadlock_task_pid = NULL;
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700158}
159
160void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter)
161{
Pavel Emelyanov48d13e42008-02-08 04:21:53 -0800162 put_pid(waiter->deadlock_task_pid);
Thomas Gleixner0fa914c2011-06-08 09:58:38 +0200163 DEBUG_LOCKS_WARN_ON(!plist_node_empty(&waiter->list_entry));
164 DEBUG_LOCKS_WARN_ON(!plist_node_empty(&waiter->pi_list_entry));
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700165 memset(waiter, 0x22, sizeof(*waiter));
166}
167
168void debug_rt_mutex_init(struct rt_mutex *lock, const char *name)
169{
Ingo Molnar9a11b49a2006-07-03 00:24:33 -0700170 /*
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;
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700175}
176
Ingo Molnar36c8b582006-07-03 00:25:41 -0700177void
178rt_mutex_deadlock_account_lock(struct rt_mutex *lock, struct task_struct *task)
Ingo Molnare7eebaf2006-06-27 02:54:55 -0700179{
180}
181
182void rt_mutex_deadlock_account_unlock(struct task_struct *task)
183{
184}
185