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