rtmutex-debug.c 4.7 KB

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