nmi.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (C) 1991, 1992 Linus Torvalds
  3. * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
  4. *
  5. * Pentium III FXSR, SSE support
  6. * Gareth Hughes <gareth@valinux.com>, May 2000
  7. */
  8. /*
  9. * Handle hardware traps and faults.
  10. */
  11. #include <linux/spinlock.h>
  12. #include <linux/kprobes.h>
  13. #include <linux/kdebug.h>
  14. #include <linux/nmi.h>
  15. #if defined(CONFIG_EDAC)
  16. #include <linux/edac.h>
  17. #endif
  18. #include <linux/atomic.h>
  19. #include <asm/traps.h>
  20. #include <asm/mach_traps.h>
  21. static int ignore_nmis;
  22. int unknown_nmi_panic;
  23. /*
  24. * Prevent NMI reason port (0x61) being accessed simultaneously, can
  25. * only be used in NMI handler.
  26. */
  27. static DEFINE_RAW_SPINLOCK(nmi_reason_lock);
  28. static int __init setup_unknown_nmi_panic(char *str)
  29. {
  30. unknown_nmi_panic = 1;
  31. return 1;
  32. }
  33. __setup("unknown_nmi_panic", setup_unknown_nmi_panic);
  34. static notrace __kprobes void
  35. pci_serr_error(unsigned char reason, struct pt_regs *regs)
  36. {
  37. pr_emerg("NMI: PCI system error (SERR) for reason %02x on CPU %d.\n",
  38. reason, smp_processor_id());
  39. /*
  40. * On some machines, PCI SERR line is used to report memory
  41. * errors. EDAC makes use of it.
  42. */
  43. #if defined(CONFIG_EDAC)
  44. if (edac_handler_set()) {
  45. edac_atomic_assert_error();
  46. return;
  47. }
  48. #endif
  49. if (panic_on_unrecovered_nmi)
  50. panic("NMI: Not continuing");
  51. pr_emerg("Dazed and confused, but trying to continue\n");
  52. /* Clear and disable the PCI SERR error line. */
  53. reason = (reason & NMI_REASON_CLEAR_MASK) | NMI_REASON_CLEAR_SERR;
  54. outb(reason, NMI_REASON_PORT);
  55. }
  56. static notrace __kprobes void
  57. io_check_error(unsigned char reason, struct pt_regs *regs)
  58. {
  59. unsigned long i;
  60. pr_emerg(
  61. "NMI: IOCK error (debug interrupt?) for reason %02x on CPU %d.\n",
  62. reason, smp_processor_id());
  63. show_registers(regs);
  64. if (panic_on_io_nmi)
  65. panic("NMI IOCK error: Not continuing");
  66. /* Re-enable the IOCK line, wait for a few seconds */
  67. reason = (reason & NMI_REASON_CLEAR_MASK) | NMI_REASON_CLEAR_IOCHK;
  68. outb(reason, NMI_REASON_PORT);
  69. i = 20000;
  70. while (--i) {
  71. touch_nmi_watchdog();
  72. udelay(100);
  73. }
  74. reason &= ~NMI_REASON_CLEAR_IOCHK;
  75. outb(reason, NMI_REASON_PORT);
  76. }
  77. static notrace __kprobes void
  78. unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
  79. {
  80. if (notify_die(DIE_NMIUNKNOWN, "nmi", regs, reason, 2, SIGINT) ==
  81. NOTIFY_STOP)
  82. return;
  83. #ifdef CONFIG_MCA
  84. /*
  85. * Might actually be able to figure out what the guilty party
  86. * is:
  87. */
  88. if (MCA_bus) {
  89. mca_handle_nmi();
  90. return;
  91. }
  92. #endif
  93. pr_emerg("Uhhuh. NMI received for unknown reason %02x on CPU %d.\n",
  94. reason, smp_processor_id());
  95. pr_emerg("Do you have a strange power saving mode enabled?\n");
  96. if (unknown_nmi_panic || panic_on_unrecovered_nmi)
  97. panic("NMI: Not continuing");
  98. pr_emerg("Dazed and confused, but trying to continue\n");
  99. }
  100. static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
  101. {
  102. unsigned char reason = 0;
  103. /*
  104. * CPU-specific NMI must be processed before non-CPU-specific
  105. * NMI, otherwise we may lose it, because the CPU-specific
  106. * NMI can not be detected/processed on other CPUs.
  107. */
  108. if (notify_die(DIE_NMI, "nmi", regs, 0, 2, SIGINT) == NOTIFY_STOP)
  109. return;
  110. /* Non-CPU-specific NMI: NMI sources can be processed on any CPU */
  111. raw_spin_lock(&nmi_reason_lock);
  112. reason = get_nmi_reason();
  113. if (reason & NMI_REASON_MASK) {
  114. if (reason & NMI_REASON_SERR)
  115. pci_serr_error(reason, regs);
  116. else if (reason & NMI_REASON_IOCHK)
  117. io_check_error(reason, regs);
  118. #ifdef CONFIG_X86_32
  119. /*
  120. * Reassert NMI in case it became active
  121. * meanwhile as it's edge-triggered:
  122. */
  123. reassert_nmi();
  124. #endif
  125. raw_spin_unlock(&nmi_reason_lock);
  126. return;
  127. }
  128. raw_spin_unlock(&nmi_reason_lock);
  129. unknown_nmi_error(reason, regs);
  130. }
  131. dotraplinkage notrace __kprobes void
  132. do_nmi(struct pt_regs *regs, long error_code)
  133. {
  134. nmi_enter();
  135. inc_irq_stat(__nmi_count);
  136. if (!ignore_nmis)
  137. default_do_nmi(regs);
  138. nmi_exit();
  139. }
  140. void stop_nmi(void)
  141. {
  142. ignore_nmis++;
  143. }
  144. void restart_nmi(void)
  145. {
  146. ignore_nmis--;
  147. }