fda5691ded6ad7f80d67bb2af1884607a4f2027a
[linux-2.6.git] / kernel / panic.c
1 /*
2  *  linux/kernel/panic.c
3  *
4  *  Copyright (C) 1991, 1992  Linus Torvalds
5  */
6
7 /*
8  * This function is used through-out the kernel (including mm and fs)
9  * to indicate a major problem.
10  */
11 #include <linux/config.h>
12 #include <linux/module.h>
13 #include <linux/sched.h>
14 #include <linux/delay.h>
15 #include <linux/reboot.h>
16 #include <linux/notifier.h>
17 #include <linux/init.h>
18 #include <linux/sysrq.h>
19 #include <linux/syscalls.h>
20 #include <linux/interrupt.h>
21 #include <linux/nmi.h>
22 #ifdef CONFIG_KEXEC
23 #include <linux/kexec.h>
24 #endif
25
26 int panic_timeout = 900;
27 int panic_on_oops = 1;
28 int tainted;
29 void (*dump_function_ptr)(const char *, const struct pt_regs *) = 0;
30
31 EXPORT_SYMBOL(panic_timeout);
32 EXPORT_SYMBOL(dump_function_ptr);
33
34 struct notifier_block *panic_notifier_list;
35
36 EXPORT_SYMBOL(panic_notifier_list);
37
38 static int __init panic_setup(char *str)
39 {
40         panic_timeout = simple_strtoul(str, NULL, 0);
41         return 1;
42 }
43 __setup("panic=", panic_setup);
44
45 static long no_blink(long time)
46 {
47         return 0;
48 }
49
50 /* Returns how long it waited in ms */
51 long (*panic_blink)(long time) = no_blink;
52 EXPORT_SYMBOL(panic_blink);
53
54 /**
55  *      panic - halt the system
56  *      @fmt: The text string to print
57  *
58  *      Display a message, then perform cleanups. Functions in the panic
59  *      notifier list are called after the filesystem cache is flushed (when possible).
60  *
61  *      This function never returns.
62  */
63  
64 NORET_TYPE void panic(const char * fmt, ...)
65 {
66         long i;
67         static char buf[1024];
68         va_list args;
69 #if defined(CONFIG_ARCH_S390)
70         unsigned long caller = (unsigned long) __builtin_return_address(0);
71 #endif
72
73         bust_spinlocks(1);
74         va_start(args, fmt);
75         vsnprintf(buf, sizeof(buf), fmt, args);
76         va_end(args);
77
78         printk(KERN_EMERG "Kernel panic: %s\n",buf);
79 #warning MEF netdump_func not part of 2.6.9-1.11-FC2; taking out call for now
80 #if 0
81         if (netdump_func)
82                 BUG();
83 #endif
84         if (in_interrupt())
85                 printk(KERN_EMERG "In interrupt handler - not syncing\n");
86         else if (!current->pid)
87                 printk(KERN_EMERG "In idle task - not syncing\n");
88         else
89                 sys_sync();
90         bust_spinlocks(0);
91
92         notifier_call_chain(&panic_notifier_list, 0, buf);
93         
94 #ifdef CONFIG_SMP
95         smp_send_stop();
96 #endif
97
98         notifier_call_chain(&panic_notifier_list, 0, buf);
99
100         if (panic_timeout > 0)
101         {
102                 /*
103                  * Delay timeout seconds before rebooting the machine. 
104                  * We can't use the "normal" timers since we just panicked..
105                  */
106                 printk(KERN_EMERG "Rebooting in %d seconds..",panic_timeout);
107 #ifdef CONFIG_KEXEC
108  {              
109                 struct kimage *image;
110                 image = xchg(&kexec_image, 0);
111                 if (image) {
112                         printk(KERN_EMERG "by starting a new kernel ..\n");
113                         mdelay(panic_timeout*1000);
114                         machine_kexec(image);
115                 }
116  }
117 #endif
118                 for (i = 0; i < panic_timeout*1000; ) {
119                         touch_nmi_watchdog();
120                         i += panic_blink(i);
121                         mdelay(1);
122                         i++;
123                 }
124                 /*
125                  *      Should we run the reboot notifier. For the moment Im
126                  *      choosing not too. It might crash, be corrupt or do
127                  *      more harm than good for other reasons.
128                  */
129                 machine_restart(NULL);
130         }
131 #ifdef __sparc__
132         {
133                 extern int stop_a_enabled;
134                 /* Make sure the user can actually press L1-A */
135                 stop_a_enabled = 1;
136                 printk(KERN_EMERG "Press L1-A to return to the boot prom\n");
137         }
138 #endif
139 #if defined(CONFIG_ARCH_S390)
140         disabled_wait(caller);
141 #endif
142         local_irq_enable();
143         for (i = 0;;) { 
144                 i += panic_blink(i);
145                 mdelay(1); 
146                 i++; 
147         }
148 }
149
150 EXPORT_SYMBOL(panic);
151
152 /**
153  *      print_tainted - return a string to represent the kernel taint state.
154  *
155  *  'P' - Proprietary module has been loaded.
156  *  'F' - Module has been forcibly loaded.
157  *  'S' - SMP with CPUs not designed for SMP.
158  *  'R' - User forced a module unload.
159  *  'M' - Machine had a machine check experience.
160  *  'B' - System has hit bad_page.
161  *
162  *      The string is overwritten by the next call to print_taint().
163  */
164  
165 const char *print_tainted(void)
166 {
167         static char buf[20];
168         if (tainted) {
169                 snprintf(buf, sizeof(buf), "Tainted: %c%c%c%c%c%c",
170                         tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
171                         tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
172                         tainted & TAINT_UNSAFE_SMP ? 'S' : ' ',
173                         tainted & TAINT_FORCED_RMMOD ? 'R' : ' ',
174                         tainted & TAINT_MACHINE_CHECK ? 'M' : ' ',
175                         tainted & TAINT_BAD_PAGE ? 'B' : ' ');
176         }
177         else
178                 snprintf(buf, sizeof(buf), "Not tainted");
179         return(buf);
180 }
181
182 void add_taint(unsigned flag)
183 {
184         tainted |= flag;
185 }
186 EXPORT_SYMBOL(add_taint);