| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * 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 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #include <linux/sched.h>
 | 
					
						
							| 
									
										
										
										
											2013-02-07 09:47:07 -06:00
										 |  |  | #include <linux/sched/rt.h>
 | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | #include <linux/delay.h>
 | 
					
						
							| 
									
										
										
										
											2011-05-23 14:51:41 -04:00
										 |  |  | #include <linux/export.h>
 | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | #include <linux/spinlock.h>
 | 
					
						
							|  |  |  | #include <linux/kallsyms.h>
 | 
					
						
							|  |  |  | #include <linux/syscalls.h>
 | 
					
						
							|  |  |  | #include <linux/interrupt.h>
 | 
					
						
							|  |  |  | #include <linux/plist.h>
 | 
					
						
							|  |  |  | #include <linux/fs.h>
 | 
					
						
							| 
									
										
										
										
											2006-07-03 00:24:33 -07:00
										 |  |  | #include <linux/debug_locks.h>
 | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "rtmutex_common.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-03 00:25:41 -07:00
										 |  |  | static void printk_task(struct task_struct *p) | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (p) | 
					
						
							| 
									
										
										
										
											2007-10-18 23:40:40 -07:00
										 |  |  | 		printk("%16s:%5d [%p, %3d]", p->comm, task_pid_nr(p), p, p->prio); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		printk("<none>"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void printk_lock(struct rt_mutex *lock, int print_owner) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (lock->name) | 
					
						
							|  |  |  | 		printk(" [%p] {%s}\n", | 
					
						
							|  |  |  | 			lock, lock->name); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		printk(" [%p] {%s:%d}\n", | 
					
						
							|  |  |  | 			lock, lock->file, lock->line); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (print_owner && rt_mutex_owner(lock)) { | 
					
						
							|  |  |  | 		printk(".. ->owner: %p\n", lock->owner); | 
					
						
							|  |  |  | 		printk(".. held by:  "); | 
					
						
							|  |  |  | 		printk_task(rt_mutex_owner(lock)); | 
					
						
							|  |  |  | 		printk("\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void rt_mutex_debug_task_free(struct task_struct *task) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-08 09:58:38 +02:00
										 |  |  | 	DEBUG_LOCKS_WARN_ON(!plist_head_empty(&task->pi_waiters)); | 
					
						
							|  |  |  | 	DEBUG_LOCKS_WARN_ON(task->pi_blocked_on); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * 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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-08 09:58:38 +02:00
										 |  |  | 	if (!debug_locks || detect || !act_waiter) | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	task = rt_mutex_owner(act_waiter->lock); | 
					
						
							|  |  |  | 	if (task && task != current) { | 
					
						
							| 
									
										
										
										
											2008-02-08 04:21:53 -08:00
										 |  |  | 		act_waiter->deadlock_task_pid = get_pid(task_pid(task)); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 		act_waiter->deadlock_lock = lock; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct task_struct *task; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-08 09:58:38 +02:00
										 |  |  | 	if (!waiter->deadlock_lock || !debug_locks) | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-08 04:21:53 -08:00
										 |  |  | 	rcu_read_lock(); | 
					
						
							|  |  |  | 	task = pid_task(waiter->deadlock_task_pid, PIDTYPE_PID); | 
					
						
							|  |  |  | 	if (!task) { | 
					
						
							|  |  |  | 		rcu_read_unlock(); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2008-02-08 04:21:53 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-05 13:20:24 +02:00
										 |  |  | 	if (!debug_locks_off()) { | 
					
						
							|  |  |  | 		rcu_read_unlock(); | 
					
						
							| 
									
										
										
										
											2011-06-08 09:58:38 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:20:24 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	printk("\n============================================\n"); | 
					
						
							|  |  |  | 	printk(  "[ BUG: circular locking deadlock detected! ]\n"); | 
					
						
							| 
									
										
										
										
											2011-10-28 04:36:55 +01:00
										 |  |  | 	printk("%s\n", print_tainted()); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 	printk(  "--------------------------------------------\n"); | 
					
						
							|  |  |  | 	printk("%s/%d is deadlocking current task %s/%d\n\n", | 
					
						
							| 
									
										
										
										
											2007-10-18 23:40:40 -07:00
										 |  |  | 	       task->comm, task_pid_nr(task), | 
					
						
							|  |  |  | 	       current->comm, task_pid_nr(current)); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	printk("\n1) %s/%d is trying to acquire this lock:\n", | 
					
						
							| 
									
										
										
										
											2007-10-18 23:40:40 -07:00
										 |  |  | 	       current->comm, task_pid_nr(current)); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 	printk_lock(waiter->lock, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-18 23:40:40 -07:00
										 |  |  | 	printk("\n2) %s/%d is blocked on this lock:\n", | 
					
						
							|  |  |  | 		task->comm, task_pid_nr(task)); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 	printk_lock(waiter->deadlock_lock, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-03 00:24:33 -07:00
										 |  |  | 	debug_show_held_locks(current); | 
					
						
							|  |  |  | 	debug_show_held_locks(task); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-18 23:40:40 -07:00
										 |  |  | 	printk("\n%s/%d's [blocked] stackdump:\n\n", | 
					
						
							|  |  |  | 		task->comm, task_pid_nr(task)); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 	show_stack(task, NULL); | 
					
						
							|  |  |  | 	printk("\n%s/%d's [current] stackdump:\n\n", | 
					
						
							| 
									
										
										
										
											2007-10-18 23:40:40 -07:00
										 |  |  | 		current->comm, task_pid_nr(current)); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 	dump_stack(); | 
					
						
							| 
									
										
										
										
											2006-07-03 00:24:33 -07:00
										 |  |  | 	debug_show_all_locks(); | 
					
						
							| 
									
										
										
										
											2008-02-08 04:21:53 -08:00
										 |  |  | 	rcu_read_unlock(); | 
					
						
							| 
									
										
										
										
											2006-07-03 00:24:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 	printk("[ turning off deadlock detection." | 
					
						
							|  |  |  | 	       "Please report this trace. ]\n\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-03 00:24:33 -07:00
										 |  |  | void debug_rt_mutex_lock(struct rt_mutex *lock) | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void debug_rt_mutex_unlock(struct rt_mutex *lock) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-08 09:58:38 +02:00
										 |  |  | 	DEBUG_LOCKS_WARN_ON(rt_mutex_owner(lock) != current); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-03 00:24:33 -07:00
										 |  |  | void | 
					
						
							|  |  |  | debug_rt_mutex_proxy_lock(struct rt_mutex *lock, struct task_struct *powner) | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-08 09:58:38 +02:00
										 |  |  | 	DEBUG_LOCKS_WARN_ON(!rt_mutex_owner(lock)); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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); | 
					
						
							| 
									
										
										
										
											2008-02-08 04:21:53 -08:00
										 |  |  | 	waiter->deadlock_task_pid = NULL; | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-02-08 04:21:53 -08:00
										 |  |  | 	put_pid(waiter->deadlock_task_pid); | 
					
						
							| 
									
										
										
										
											2011-06-08 09:58:38 +02:00
										 |  |  | 	DEBUG_LOCKS_WARN_ON(!plist_node_empty(&waiter->list_entry)); | 
					
						
							|  |  |  | 	DEBUG_LOCKS_WARN_ON(!plist_node_empty(&waiter->pi_list_entry)); | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | 	memset(waiter, 0x22, sizeof(*waiter)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void debug_rt_mutex_init(struct rt_mutex *lock, const char *name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-07-03 00:24:33 -07:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Make sure we are not reinitializing a held lock: | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	debug_check_no_locks_freed((void *)lock, sizeof(*lock)); | 
					
						
							|  |  |  | 	lock->name = name; | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-03 00:25:41 -07:00
										 |  |  | void | 
					
						
							|  |  |  | rt_mutex_deadlock_account_lock(struct rt_mutex *lock, struct task_struct *task) | 
					
						
							| 
									
										
										
										
											2006-06-27 02:54:55 -07:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void rt_mutex_deadlock_account_unlock(struct task_struct *task) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |