~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/kernel/locking/rtmutex-debug.c

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.14 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.57 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.138 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.193 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp