spurious.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*
  2. * linux/kernel/irq/spurious.c
  3. *
  4. * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
  5. *
  6. * This file contains spurious interrupt handling.
  7. */
  8. #include <linux/jiffies.h>
  9. #include <linux/irq.h>
  10. #include <linux/module.h>
  11. #include <linux/kallsyms.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/timer.h>
  15. #include "internals.h"
  16. static int irqfixup __read_mostly;
  17. #define POLL_SPURIOUS_IRQ_INTERVAL (HZ/10)
  18. static void poll_spurious_irqs(unsigned long dummy);
  19. static DEFINE_TIMER(poll_spurious_irq_timer, poll_spurious_irqs, 0, 0);
  20. static int irq_poll_cpu;
  21. static atomic_t irq_poll_active;
  22. /*
  23. * We wait here for a poller to finish.
  24. *
  25. * If the poll runs on this CPU, then we yell loudly and return
  26. * false. That will leave the interrupt line disabled in the worst
  27. * case, but it should never happen.
  28. *
  29. * We wait until the poller is done and then recheck disabled and
  30. * action (about to be disabled). Only if it's still active, we return
  31. * true and let the handler run.
  32. */
  33. bool irq_wait_for_poll(struct irq_desc *desc)
  34. {
  35. if (WARN_ONCE(irq_poll_cpu == smp_processor_id(),
  36. "irq poll in progress on cpu %d for irq %d\n",
  37. smp_processor_id(), desc->irq_data.irq))
  38. return false;
  39. #ifdef CONFIG_SMP
  40. do {
  41. raw_spin_unlock(&desc->lock);
  42. while (desc->status & IRQ_INPROGRESS)
  43. cpu_relax();
  44. raw_spin_lock(&desc->lock);
  45. } while (desc->status & IRQ_INPROGRESS);
  46. /* Might have been disabled in meantime */
  47. return !(desc->status & IRQ_DISABLED) && desc->action;
  48. #else
  49. return false;
  50. #endif
  51. }
  52. /*
  53. * Recovery handler for misrouted interrupts.
  54. */
  55. static int try_one_irq(int irq, struct irq_desc *desc, bool force)
  56. {
  57. struct irqaction *action;
  58. int ok = 0;
  59. raw_spin_lock(&desc->lock);
  60. /* PER_CPU and nested thread interrupts are never polled */
  61. if (desc->status & (IRQ_PER_CPU | IRQ_NESTED_THREAD))
  62. goto out;
  63. /*
  64. * Do not poll disabled interrupts unless the spurious
  65. * disabled poller asks explicitely.
  66. */
  67. if ((desc->status & IRQ_DISABLED) && !force)
  68. goto out;
  69. /*
  70. * All handlers must agree on IRQF_SHARED, so we test just the
  71. * first. Check for action->next as well.
  72. */
  73. action = desc->action;
  74. if (!action || !(action->flags & IRQF_SHARED) ||
  75. (action->flags & __IRQF_TIMER) || !action->next)
  76. goto out;
  77. /* Already running on another processor */
  78. if (desc->status & IRQ_INPROGRESS) {
  79. /*
  80. * Already running: If it is shared get the other
  81. * CPU to go looking for our mystery interrupt too
  82. */
  83. desc->status |= IRQ_PENDING;
  84. goto out;
  85. }
  86. /* Honour the normal IRQ locking and mark it poll in progress */
  87. desc->status |= IRQ_INPROGRESS | IRQ_POLL_INPROGRESS;
  88. do {
  89. desc->status &= ~IRQ_PENDING;
  90. raw_spin_unlock(&desc->lock);
  91. if (handle_IRQ_event(irq, action) != IRQ_NONE)
  92. ok = 1;
  93. raw_spin_lock(&desc->lock);
  94. action = desc->action;
  95. } while ((desc->status & IRQ_PENDING) && action);
  96. desc->status &= ~(IRQ_INPROGRESS | IRQ_POLL_INPROGRESS);
  97. out:
  98. raw_spin_unlock(&desc->lock);
  99. return ok;
  100. }
  101. static int misrouted_irq(int irq)
  102. {
  103. struct irq_desc *desc;
  104. int i, ok = 0;
  105. if (atomic_inc_return(&irq_poll_active) == 1)
  106. goto out;
  107. irq_poll_cpu = smp_processor_id();
  108. for_each_irq_desc(i, desc) {
  109. if (!i)
  110. continue;
  111. if (i == irq) /* Already tried */
  112. continue;
  113. if (try_one_irq(i, desc, false))
  114. ok = 1;
  115. }
  116. out:
  117. atomic_dec(&irq_poll_active);
  118. /* So the caller can adjust the irq error counts */
  119. return ok;
  120. }
  121. static void poll_spurious_irqs(unsigned long dummy)
  122. {
  123. struct irq_desc *desc;
  124. int i;
  125. if (atomic_inc_return(&irq_poll_active) != 1)
  126. goto out;
  127. irq_poll_cpu = smp_processor_id();
  128. for_each_irq_desc(i, desc) {
  129. unsigned int status;
  130. if (!i)
  131. continue;
  132. /* Racy but it doesn't matter */
  133. status = desc->status;
  134. barrier();
  135. if (!(status & IRQ_SPURIOUS_DISABLED))
  136. continue;
  137. local_irq_disable();
  138. try_one_irq(i, desc, true);
  139. local_irq_enable();
  140. }
  141. out:
  142. atomic_dec(&irq_poll_active);
  143. mod_timer(&poll_spurious_irq_timer,
  144. jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
  145. }
  146. /*
  147. * If 99,900 of the previous 100,000 interrupts have not been handled
  148. * then assume that the IRQ is stuck in some manner. Drop a diagnostic
  149. * and try to turn the IRQ off.
  150. *
  151. * (The other 100-of-100,000 interrupts may have been a correctly
  152. * functioning device sharing an IRQ with the failing one)
  153. */
  154. static void
  155. __report_bad_irq(unsigned int irq, struct irq_desc *desc,
  156. irqreturn_t action_ret)
  157. {
  158. struct irqaction *action;
  159. unsigned long flags;
  160. if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
  161. printk(KERN_ERR "irq event %d: bogus return value %x\n",
  162. irq, action_ret);
  163. } else {
  164. printk(KERN_ERR "irq %d: nobody cared (try booting with "
  165. "the \"irqpoll\" option)\n", irq);
  166. }
  167. dump_stack();
  168. printk(KERN_ERR "handlers:\n");
  169. /*
  170. * We need to take desc->lock here. note_interrupt() is called
  171. * w/o desc->lock held, but IRQ_PROGRESS set. We might race
  172. * with something else removing an action. It's ok to take
  173. * desc->lock here. See synchronize_irq().
  174. */
  175. raw_spin_lock_irqsave(&desc->lock, flags);
  176. action = desc->action;
  177. while (action) {
  178. printk(KERN_ERR "[<%p>]", action->handler);
  179. print_symbol(" (%s)",
  180. (unsigned long)action->handler);
  181. printk("\n");
  182. action = action->next;
  183. }
  184. raw_spin_unlock_irqrestore(&desc->lock, flags);
  185. }
  186. static void
  187. report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
  188. {
  189. static int count = 100;
  190. if (count > 0) {
  191. count--;
  192. __report_bad_irq(irq, desc, action_ret);
  193. }
  194. }
  195. static inline int
  196. try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
  197. irqreturn_t action_ret)
  198. {
  199. struct irqaction *action;
  200. if (!irqfixup)
  201. return 0;
  202. /* We didn't actually handle the IRQ - see if it was misrouted? */
  203. if (action_ret == IRQ_NONE)
  204. return 1;
  205. /*
  206. * But for 'irqfixup == 2' we also do it for handled interrupts if
  207. * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
  208. * traditional PC timer interrupt.. Legacy)
  209. */
  210. if (irqfixup < 2)
  211. return 0;
  212. if (!irq)
  213. return 1;
  214. /*
  215. * Since we don't get the descriptor lock, "action" can
  216. * change under us. We don't really care, but we don't
  217. * want to follow a NULL pointer. So tell the compiler to
  218. * just load it once by using a barrier.
  219. */
  220. action = desc->action;
  221. barrier();
  222. return action && (action->flags & IRQF_IRQPOLL);
  223. }
  224. void note_interrupt(unsigned int irq, struct irq_desc *desc,
  225. irqreturn_t action_ret)
  226. {
  227. if (desc->status & IRQ_POLL_INPROGRESS)
  228. return;
  229. if (unlikely(action_ret != IRQ_HANDLED)) {
  230. /*
  231. * If we are seeing only the odd spurious IRQ caused by
  232. * bus asynchronicity then don't eventually trigger an error,
  233. * otherwise the counter becomes a doomsday timer for otherwise
  234. * working systems
  235. */
  236. if (time_after(jiffies, desc->last_unhandled + HZ/10))
  237. desc->irqs_unhandled = 1;
  238. else
  239. desc->irqs_unhandled++;
  240. desc->last_unhandled = jiffies;
  241. if (unlikely(action_ret != IRQ_NONE))
  242. report_bad_irq(irq, desc, action_ret);
  243. }
  244. if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
  245. int ok = misrouted_irq(irq);
  246. if (action_ret == IRQ_NONE)
  247. desc->irqs_unhandled -= ok;
  248. }
  249. desc->irq_count++;
  250. if (likely(desc->irq_count < 100000))
  251. return;
  252. desc->irq_count = 0;
  253. if (unlikely(desc->irqs_unhandled > 99900)) {
  254. /*
  255. * The interrupt is stuck
  256. */
  257. __report_bad_irq(irq, desc, action_ret);
  258. /*
  259. * Now kill the IRQ
  260. */
  261. printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
  262. desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
  263. desc->depth++;
  264. desc->irq_data.chip->irq_disable(&desc->irq_data);
  265. mod_timer(&poll_spurious_irq_timer,
  266. jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
  267. }
  268. desc->irqs_unhandled = 0;
  269. }
  270. int noirqdebug __read_mostly;
  271. int noirqdebug_setup(char *str)
  272. {
  273. noirqdebug = 1;
  274. printk(KERN_INFO "IRQ lockup detection disabled\n");
  275. return 1;
  276. }
  277. __setup("noirqdebug", noirqdebug_setup);
  278. module_param(noirqdebug, bool, 0644);
  279. MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
  280. static int __init irqfixup_setup(char *str)
  281. {
  282. irqfixup = 1;
  283. printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
  284. printk(KERN_WARNING "This may impact system performance.\n");
  285. return 1;
  286. }
  287. __setup("irqfixup", irqfixup_setup);
  288. module_param(irqfixup, int, 0644);
  289. static int __init irqpoll_setup(char *str)
  290. {
  291. irqfixup = 2;
  292. printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
  293. "enabled\n");
  294. printk(KERN_WARNING "This may significantly impact system "
  295. "performance\n");
  296. return 1;
  297. }
  298. __setup("irqpoll", irqpoll_setup);