rtmutex-debug.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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/rbtree.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(!RB_EMPTY_ROOT(&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(enum rtmutex_chainwalk chwalk,
  63. struct rt_mutex_waiter *act_waiter,
  64. struct rt_mutex *lock)
  65. {
  66. struct task_struct *task;
  67. if (!debug_locks || chwalk == RT_MUTEX_FULL_CHAINWALK || !act_waiter)
  68. return;
  69. task = rt_mutex_owner(act_waiter->lock);
  70. if (task && task != current) {
  71. act_waiter->deadlock_task_pid = get_pid(task_pid(task));
  72. act_waiter->deadlock_lock = lock;
  73. }
  74. }
  75. void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter)
  76. {
  77. struct task_struct *task;
  78. if (!waiter->deadlock_lock || !debug_locks)
  79. return;
  80. rcu_read_lock();
  81. task = pid_task(waiter->deadlock_task_pid, PIDTYPE_PID);
  82. if (!task) {
  83. rcu_read_unlock();
  84. return;
  85. }
  86. if (!debug_locks_off()) {
  87. rcu_read_unlock();
  88. return;
  89. }
  90. printk("\n============================================\n");
  91. printk( "[ BUG: circular locking deadlock detected! ]\n");
  92. printk("%s\n", print_tainted());
  93. printk( "--------------------------------------------\n");
  94. printk("%s/%d is deadlocking current task %s/%d\n\n",
  95. task->comm, task_pid_nr(task),
  96. current->comm, task_pid_nr(current));
  97. printk("\n1) %s/%d is trying to acquire this lock:\n",
  98. current->comm, task_pid_nr(current));
  99. printk_lock(waiter->lock, 1);
  100. printk("\n2) %s/%d is blocked on this lock:\n",
  101. task->comm, task_pid_nr(task));
  102. printk_lock(waiter->deadlock_lock, 1);
  103. debug_show_held_locks(current);
  104. debug_show_held_locks(task);
  105. printk("\n%s/%d's [blocked] stackdump:\n\n",
  106. task->comm, task_pid_nr(task));
  107. show_stack(task, NULL);
  108. printk("\n%s/%d's [current] stackdump:\n\n",
  109. current->comm, task_pid_nr(current));
  110. dump_stack();
  111. debug_show_all_locks();
  112. rcu_read_unlock();
  113. printk("[ turning off deadlock detection."
  114. "Please report this trace. ]\n\n");
  115. }
  116. void debug_rt_mutex_lock(struct rt_mutex *lock)
  117. {
  118. }
  119. void debug_rt_mutex_unlock(struct rt_mutex *lock)
  120. {
  121. DEBUG_LOCKS_WARN_ON(rt_mutex_owner(lock) != current);
  122. }
  123. void
  124. debug_rt_mutex_proxy_lock(struct rt_mutex *lock, struct task_struct *powner)
  125. {
  126. }
  127. void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock)
  128. {
  129. DEBUG_LOCKS_WARN_ON(!rt_mutex_owner(lock));
  130. }
  131. void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter)
  132. {
  133. memset(waiter, 0x11, sizeof(*waiter));
  134. waiter->deadlock_task_pid = NULL;
  135. }
  136. void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter)
  137. {
  138. put_pid(waiter->deadlock_task_pid);
  139. memset(waiter, 0x22, sizeof(*waiter));
  140. }
  141. void debug_rt_mutex_init(struct rt_mutex *lock, const char *name)
  142. {
  143. /*
  144. * Make sure we are not reinitializing a held lock:
  145. */
  146. debug_check_no_locks_freed((void *)lock, sizeof(*lock));
  147. lock->name = name;
  148. }
  149. void
  150. rt_mutex_deadlock_account_lock(struct rt_mutex *lock, struct task_struct *task)
  151. {
  152. }
  153. void rt_mutex_deadlock_account_unlock(struct task_struct *task)
  154. {
  155. }