panic.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * linux/kernel/panic.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. /*
  7. * This function is used through-out the kernel (including mm and fs)
  8. * to indicate a major problem.
  9. */
  10. #include <linux/config.h>
  11. #include <linux/module.h>
  12. #include <linux/sched.h>
  13. #include <linux/delay.h>
  14. #include <linux/reboot.h>
  15. #include <linux/notifier.h>
  16. #include <linux/init.h>
  17. #include <linux/sysrq.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/nmi.h>
  20. #include <linux/kexec.h>
  21. int panic_timeout;
  22. int panic_on_oops;
  23. int tainted;
  24. EXPORT_SYMBOL(panic_timeout);
  25. struct notifier_block *panic_notifier_list;
  26. EXPORT_SYMBOL(panic_notifier_list);
  27. static int __init panic_setup(char *str)
  28. {
  29. panic_timeout = simple_strtoul(str, NULL, 0);
  30. return 1;
  31. }
  32. __setup("panic=", panic_setup);
  33. static long no_blink(long time)
  34. {
  35. return 0;
  36. }
  37. /* Returns how long it waited in ms */
  38. long (*panic_blink)(long time);
  39. EXPORT_SYMBOL(panic_blink);
  40. /**
  41. * panic - halt the system
  42. * @fmt: The text string to print
  43. *
  44. * Display a message, then perform cleanups.
  45. *
  46. * This function never returns.
  47. */
  48. NORET_TYPE void panic(const char * fmt, ...)
  49. {
  50. long i;
  51. static char buf[1024];
  52. va_list args;
  53. #if defined(CONFIG_S390)
  54. unsigned long caller = (unsigned long) __builtin_return_address(0);
  55. #endif
  56. /*
  57. * It's possible to come here directly from a panic-assertion and not
  58. * have preempt disabled. Some functions called from here want
  59. * preempt to be disabled. No point enabling it later though...
  60. */
  61. preempt_disable();
  62. bust_spinlocks(1);
  63. va_start(args, fmt);
  64. vsnprintf(buf, sizeof(buf), fmt, args);
  65. va_end(args);
  66. printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
  67. bust_spinlocks(0);
  68. /*
  69. * If we have crashed and we have a crash kernel loaded let it handle
  70. * everything else.
  71. * Do we want to call this before we try to display a message?
  72. */
  73. crash_kexec(NULL);
  74. #ifdef CONFIG_SMP
  75. /*
  76. * Note smp_send_stop is the usual smp shutdown function, which
  77. * unfortunately means it may not be hardened to work in a panic
  78. * situation.
  79. */
  80. smp_send_stop();
  81. #endif
  82. notifier_call_chain(&panic_notifier_list, 0, buf);
  83. if (!panic_blink)
  84. panic_blink = no_blink;
  85. if (panic_timeout > 0) {
  86. /*
  87. * Delay timeout seconds before rebooting the machine.
  88. * We can't use the "normal" timers since we just panicked..
  89. */
  90. printk(KERN_EMERG "Rebooting in %d seconds..",panic_timeout);
  91. for (i = 0; i < panic_timeout*1000; ) {
  92. touch_nmi_watchdog();
  93. i += panic_blink(i);
  94. mdelay(1);
  95. i++;
  96. }
  97. /* This will not be a clean reboot, with everything
  98. * shutting down. But if there is a chance of
  99. * rebooting the system it will be rebooted.
  100. */
  101. emergency_restart();
  102. }
  103. #ifdef __sparc__
  104. {
  105. extern int stop_a_enabled;
  106. /* Make sure the user can actually press Stop-A (L1-A) */
  107. stop_a_enabled = 1;
  108. printk(KERN_EMERG "Press Stop-A (L1-A) to return to the boot prom\n");
  109. }
  110. #endif
  111. #if defined(CONFIG_S390)
  112. disabled_wait(caller);
  113. #endif
  114. local_irq_enable();
  115. for (i = 0;;) {
  116. i += panic_blink(i);
  117. mdelay(1);
  118. i++;
  119. }
  120. }
  121. EXPORT_SYMBOL(panic);
  122. /**
  123. * print_tainted - return a string to represent the kernel taint state.
  124. *
  125. * 'P' - Proprietary module has been loaded.
  126. * 'F' - Module has been forcibly loaded.
  127. * 'S' - SMP with CPUs not designed for SMP.
  128. * 'R' - User forced a module unload.
  129. * 'M' - Machine had a machine check experience.
  130. * 'B' - System has hit bad_page.
  131. *
  132. * The string is overwritten by the next call to print_taint().
  133. */
  134. const char *print_tainted(void)
  135. {
  136. static char buf[20];
  137. if (tainted) {
  138. snprintf(buf, sizeof(buf), "Tainted: %c%c%c%c%c%c",
  139. tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
  140. tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
  141. tainted & TAINT_UNSAFE_SMP ? 'S' : ' ',
  142. tainted & TAINT_FORCED_RMMOD ? 'R' : ' ',
  143. tainted & TAINT_MACHINE_CHECK ? 'M' : ' ',
  144. tainted & TAINT_BAD_PAGE ? 'B' : ' ');
  145. }
  146. else
  147. snprintf(buf, sizeof(buf), "Not tainted");
  148. return(buf);
  149. }
  150. void add_taint(unsigned flag)
  151. {
  152. tainted |= flag;
  153. }
  154. EXPORT_SYMBOL(add_taint);