11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/kernel/panic.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds 51da177e4SLinus Torvalds */ 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds /* 81da177e4SLinus Torvalds * This function is used through-out the kernel (including mm and fs) 91da177e4SLinus Torvalds * to indicate a major problem. 101da177e4SLinus Torvalds */ 11657b3010SAndrew Morton #include <linux/debug_locks.h> 12c95dbf27SIngo Molnar #include <linux/interrupt.h> 13456b565cSSimon Kagstrom #include <linux/kmsg_dump.h> 1479b4cc5eSArjan van de Ven #include <linux/kallsyms.h> 15c95dbf27SIngo Molnar #include <linux/notifier.h> 16c95dbf27SIngo Molnar #include <linux/module.h> 17c95dbf27SIngo Molnar #include <linux/random.h> 18c95dbf27SIngo Molnar #include <linux/reboot.h> 19c95dbf27SIngo Molnar #include <linux/delay.h> 20c95dbf27SIngo Molnar #include <linux/kexec.h> 21c95dbf27SIngo Molnar #include <linux/sched.h> 22c95dbf27SIngo Molnar #include <linux/sysrq.h> 23c95dbf27SIngo Molnar #include <linux/init.h> 24c95dbf27SIngo Molnar #include <linux/nmi.h> 25bd89bb29SArjan van de Ven #include <linux/dmi.h> 261da177e4SLinus Torvalds 27c7ff0d9cSTAMUKI Shoichi #define PANIC_TIMER_STEP 100 28c7ff0d9cSTAMUKI Shoichi #define PANIC_BLINK_SPD 18 29c7ff0d9cSTAMUKI Shoichi 30*2a01bb38SKyle McMartin int panic_on_oops = CONFIG_PANIC_ON_OOPS_VALUE; 3125ddbb18SAndi Kleen static unsigned long tainted_mask; 32dd287796SAndrew Morton static int pause_on_oops; 33dd287796SAndrew Morton static int pause_on_oops_flag; 34dd287796SAndrew Morton static DEFINE_SPINLOCK(pause_on_oops_lock); 351da177e4SLinus Torvalds 36dd287796SAndrew Morton int panic_timeout; 3781e88fdcSHuang Ying EXPORT_SYMBOL_GPL(panic_timeout); 381da177e4SLinus Torvalds 39e041c683SAlan Stern ATOMIC_NOTIFIER_HEAD(panic_notifier_list); 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds EXPORT_SYMBOL(panic_notifier_list); 421da177e4SLinus Torvalds 43c7ff0d9cSTAMUKI Shoichi static long no_blink(int state) 448aeee85aSAnton Blanchard { 45c7ff0d9cSTAMUKI Shoichi return 0; 46c7ff0d9cSTAMUKI Shoichi } 478aeee85aSAnton Blanchard 48c7ff0d9cSTAMUKI Shoichi /* Returns how long it waited in ms */ 49c7ff0d9cSTAMUKI Shoichi long (*panic_blink)(int state); 50c7ff0d9cSTAMUKI Shoichi EXPORT_SYMBOL(panic_blink); 518aeee85aSAnton Blanchard 5293e13a36SMichael Holzheu /* 5393e13a36SMichael Holzheu * Stop ourself in panic -- architecture code may override this 5493e13a36SMichael Holzheu */ 5593e13a36SMichael Holzheu void __weak panic_smp_self_stop(void) 5693e13a36SMichael Holzheu { 5793e13a36SMichael Holzheu while (1) 5893e13a36SMichael Holzheu cpu_relax(); 5993e13a36SMichael Holzheu } 6093e13a36SMichael Holzheu 611da177e4SLinus Torvalds /** 621da177e4SLinus Torvalds * panic - halt the system 631da177e4SLinus Torvalds * @fmt: The text string to print 641da177e4SLinus Torvalds * 651da177e4SLinus Torvalds * Display a message, then perform cleanups. 661da177e4SLinus Torvalds * 671da177e4SLinus Torvalds * This function never returns. 681da177e4SLinus Torvalds */ 699402c95fSJoe Perches void panic(const char *fmt, ...) 701da177e4SLinus Torvalds { 7193e13a36SMichael Holzheu static DEFINE_SPINLOCK(panic_lock); 721da177e4SLinus Torvalds static char buf[1024]; 731da177e4SLinus Torvalds va_list args; 74c7ff0d9cSTAMUKI Shoichi long i, i_next = 0; 75c7ff0d9cSTAMUKI Shoichi int state = 0; 761da177e4SLinus Torvalds 77dc009d92SEric W. Biederman /* 78c95dbf27SIngo Molnar * It's possible to come here directly from a panic-assertion and 79c95dbf27SIngo Molnar * not have preempt disabled. Some functions called from here want 80dc009d92SEric W. Biederman * preempt to be disabled. No point enabling it later though... 8193e13a36SMichael Holzheu * 8293e13a36SMichael Holzheu * Only one CPU is allowed to execute the panic code from here. For 8393e13a36SMichael Holzheu * multiple parallel invocations of panic, all other CPUs either 8493e13a36SMichael Holzheu * stop themself or will wait until they are stopped by the 1st CPU 8593e13a36SMichael Holzheu * with smp_send_stop(). 86dc009d92SEric W. Biederman */ 8793e13a36SMichael Holzheu if (!spin_trylock(&panic_lock)) 8893e13a36SMichael Holzheu panic_smp_self_stop(); 89dc009d92SEric W. Biederman 905b530fc1SAnton Blanchard console_verbose(); 911da177e4SLinus Torvalds bust_spinlocks(1); 921da177e4SLinus Torvalds va_start(args, fmt); 931da177e4SLinus Torvalds vsnprintf(buf, sizeof(buf), fmt, args); 941da177e4SLinus Torvalds va_end(args); 951da177e4SLinus Torvalds printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf); 965cb27301SIngo Molnar #ifdef CONFIG_DEBUG_BUGVERBOSE 976e6f0a1fSAndi Kleen /* 986e6f0a1fSAndi Kleen * Avoid nested stack-dumping if a panic occurs during oops processing 996e6f0a1fSAndi Kleen */ 100026ee1f6SJason Wessel if (!test_taint(TAINT_DIE) && oops_in_progress <= 1) 1015cb27301SIngo Molnar dump_stack(); 1025cb27301SIngo Molnar #endif 1031da177e4SLinus Torvalds 104dc009d92SEric W. Biederman /* 105dc009d92SEric W. Biederman * If we have crashed and we have a crash kernel loaded let it handle 106dc009d92SEric W. Biederman * everything else. 107dc009d92SEric W. Biederman * Do we want to call this before we try to display a message? 108dc009d92SEric W. Biederman */ 1096e274d14SAlexander Nyberg crash_kexec(NULL); 110dc009d92SEric W. Biederman 1110f4bd46eSKOSAKI Motohiro kmsg_dump(KMSG_DUMP_PANIC); 1120f4bd46eSKOSAKI Motohiro 113dc009d92SEric W. Biederman /* 114dc009d92SEric W. Biederman * Note smp_send_stop is the usual smp shutdown function, which 115dc009d92SEric W. Biederman * unfortunately means it may not be hardened to work in a panic 116dc009d92SEric W. Biederman * situation. 117dc009d92SEric W. Biederman */ 1181da177e4SLinus Torvalds smp_send_stop(); 1191da177e4SLinus Torvalds 120e041c683SAlan Stern atomic_notifier_call_chain(&panic_notifier_list, 0, buf); 1211da177e4SLinus Torvalds 122d014e889SAaro Koskinen bust_spinlocks(0); 123d014e889SAaro Koskinen 124c7ff0d9cSTAMUKI Shoichi if (!panic_blink) 125c7ff0d9cSTAMUKI Shoichi panic_blink = no_blink; 126c7ff0d9cSTAMUKI Shoichi 127dc009d92SEric W. Biederman if (panic_timeout > 0) { 1281da177e4SLinus Torvalds /* 1291da177e4SLinus Torvalds * Delay timeout seconds before rebooting the machine. 130c95dbf27SIngo Molnar * We can't use the "normal" timers since we just panicked. 1311da177e4SLinus Torvalds */ 1321da177e4SLinus Torvalds printk(KERN_EMERG "Rebooting in %d seconds..", panic_timeout); 133c95dbf27SIngo Molnar 134c7ff0d9cSTAMUKI Shoichi for (i = 0; i < panic_timeout * 1000; i += PANIC_TIMER_STEP) { 1351da177e4SLinus Torvalds touch_nmi_watchdog(); 136c7ff0d9cSTAMUKI Shoichi if (i >= i_next) { 137c7ff0d9cSTAMUKI Shoichi i += panic_blink(state ^= 1); 138c7ff0d9cSTAMUKI Shoichi i_next = i + 3600 / PANIC_BLINK_SPD; 139c7ff0d9cSTAMUKI Shoichi } 140c7ff0d9cSTAMUKI Shoichi mdelay(PANIC_TIMER_STEP); 1411da177e4SLinus Torvalds } 1424302fbc8SHugh Dickins } 1434302fbc8SHugh Dickins if (panic_timeout != 0) { 144c95dbf27SIngo Molnar /* 145c95dbf27SIngo Molnar * This will not be a clean reboot, with everything 1462f048ea8SEric W. Biederman * shutting down. But if there is a chance of 1472f048ea8SEric W. Biederman * rebooting the system it will be rebooted. 1481da177e4SLinus Torvalds */ 1492f048ea8SEric W. Biederman emergency_restart(); 1501da177e4SLinus Torvalds } 1511da177e4SLinus Torvalds #ifdef __sparc__ 1521da177e4SLinus Torvalds { 1531da177e4SLinus Torvalds extern int stop_a_enabled; 154a271c241STom 'spot' Callaway /* Make sure the user can actually press Stop-A (L1-A) */ 1551da177e4SLinus Torvalds stop_a_enabled = 1; 156a271c241STom 'spot' Callaway printk(KERN_EMERG "Press Stop-A (L1-A) to return to the boot prom\n"); 1571da177e4SLinus Torvalds } 1581da177e4SLinus Torvalds #endif 159347a8dc3SMartin Schwidefsky #if defined(CONFIG_S390) 160c95dbf27SIngo Molnar { 161c95dbf27SIngo Molnar unsigned long caller; 162c95dbf27SIngo Molnar 163c95dbf27SIngo Molnar caller = (unsigned long)__builtin_return_address(0); 1641da177e4SLinus Torvalds disabled_wait(caller); 165c95dbf27SIngo Molnar } 1661da177e4SLinus Torvalds #endif 1671da177e4SLinus Torvalds local_irq_enable(); 168c7ff0d9cSTAMUKI Shoichi for (i = 0; ; i += PANIC_TIMER_STEP) { 169c22db941SJan Beulich touch_softlockup_watchdog(); 170c7ff0d9cSTAMUKI Shoichi if (i >= i_next) { 171c7ff0d9cSTAMUKI Shoichi i += panic_blink(state ^= 1); 172c7ff0d9cSTAMUKI Shoichi i_next = i + 3600 / PANIC_BLINK_SPD; 173c7ff0d9cSTAMUKI Shoichi } 174c7ff0d9cSTAMUKI Shoichi mdelay(PANIC_TIMER_STEP); 1751da177e4SLinus Torvalds } 1761da177e4SLinus Torvalds } 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds EXPORT_SYMBOL(panic); 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds 18125ddbb18SAndi Kleen struct tnt { 18225ddbb18SAndi Kleen u8 bit; 18325ddbb18SAndi Kleen char true; 18425ddbb18SAndi Kleen char false; 18525ddbb18SAndi Kleen }; 18625ddbb18SAndi Kleen 18725ddbb18SAndi Kleen static const struct tnt tnts[] = { 18825ddbb18SAndi Kleen { TAINT_PROPRIETARY_MODULE, 'P', 'G' }, 18925ddbb18SAndi Kleen { TAINT_FORCED_MODULE, 'F', ' ' }, 19025ddbb18SAndi Kleen { TAINT_UNSAFE_SMP, 'S', ' ' }, 19125ddbb18SAndi Kleen { TAINT_FORCED_RMMOD, 'R', ' ' }, 19225ddbb18SAndi Kleen { TAINT_MACHINE_CHECK, 'M', ' ' }, 19325ddbb18SAndi Kleen { TAINT_BAD_PAGE, 'B', ' ' }, 19425ddbb18SAndi Kleen { TAINT_USER, 'U', ' ' }, 19525ddbb18SAndi Kleen { TAINT_DIE, 'D', ' ' }, 19625ddbb18SAndi Kleen { TAINT_OVERRIDDEN_ACPI_TABLE, 'A', ' ' }, 19725ddbb18SAndi Kleen { TAINT_WARN, 'W', ' ' }, 19826e9a397SLinus Torvalds { TAINT_CRAP, 'C', ' ' }, 19992946bc7SBen Hutchings { TAINT_FIRMWARE_WORKAROUND, 'I', ' ' }, 2002449b8baSBen Hutchings { TAINT_OOT_MODULE, 'O', ' ' }, 20125ddbb18SAndi Kleen }; 20225ddbb18SAndi Kleen 2031da177e4SLinus Torvalds /** 2041da177e4SLinus Torvalds * print_tainted - return a string to represent the kernel taint state. 2051da177e4SLinus Torvalds * 2061da177e4SLinus Torvalds * 'P' - Proprietary module has been loaded. 2071da177e4SLinus Torvalds * 'F' - Module has been forcibly loaded. 2081da177e4SLinus Torvalds * 'S' - SMP with CPUs not designed for SMP. 2091da177e4SLinus Torvalds * 'R' - User forced a module unload. 2101da177e4SLinus Torvalds * 'M' - System experienced a machine check exception. 2111da177e4SLinus Torvalds * 'B' - System has hit bad_page. 2121da177e4SLinus Torvalds * 'U' - Userspace-defined naughtiness. 213a8005992SArjan van de Ven * 'D' - Kernel has oopsed before 2141da177e4SLinus Torvalds * 'A' - ACPI table overridden. 2151da177e4SLinus Torvalds * 'W' - Taint on warning. 216061b1bd3SGreg Kroah-Hartman * 'C' - modules from drivers/staging are loaded. 21792946bc7SBen Hutchings * 'I' - Working around severe firmware bug. 2182449b8baSBen Hutchings * 'O' - Out-of-tree module has been loaded. 2191da177e4SLinus Torvalds * 220fe002a41SRobert P. J. Day * The string is overwritten by the next call to print_tainted(). 2211da177e4SLinus Torvalds */ 2221da177e4SLinus Torvalds const char *print_tainted(void) 2231da177e4SLinus Torvalds { 22425ddbb18SAndi Kleen static char buf[ARRAY_SIZE(tnts) + sizeof("Tainted: ") + 1]; 22525ddbb18SAndi Kleen 22625ddbb18SAndi Kleen if (tainted_mask) { 22725ddbb18SAndi Kleen char *s; 22825ddbb18SAndi Kleen int i; 22925ddbb18SAndi Kleen 23025ddbb18SAndi Kleen s = buf + sprintf(buf, "Tainted: "); 23125ddbb18SAndi Kleen for (i = 0; i < ARRAY_SIZE(tnts); i++) { 23225ddbb18SAndi Kleen const struct tnt *t = &tnts[i]; 23325ddbb18SAndi Kleen *s++ = test_bit(t->bit, &tainted_mask) ? 23425ddbb18SAndi Kleen t->true : t->false; 2351da177e4SLinus Torvalds } 23625ddbb18SAndi Kleen *s = 0; 23725ddbb18SAndi Kleen } else 2381da177e4SLinus Torvalds snprintf(buf, sizeof(buf), "Not tainted"); 239c95dbf27SIngo Molnar 240c95dbf27SIngo Molnar return buf; 2411da177e4SLinus Torvalds } 2421da177e4SLinus Torvalds 24325ddbb18SAndi Kleen int test_taint(unsigned flag) 24425ddbb18SAndi Kleen { 24525ddbb18SAndi Kleen return test_bit(flag, &tainted_mask); 24625ddbb18SAndi Kleen } 24725ddbb18SAndi Kleen EXPORT_SYMBOL(test_taint); 24825ddbb18SAndi Kleen 24925ddbb18SAndi Kleen unsigned long get_taint(void) 25025ddbb18SAndi Kleen { 25125ddbb18SAndi Kleen return tainted_mask; 25225ddbb18SAndi Kleen } 25325ddbb18SAndi Kleen 2541da177e4SLinus Torvalds void add_taint(unsigned flag) 2551da177e4SLinus Torvalds { 2569eeba613SFrederic Weisbecker /* 2579eeba613SFrederic Weisbecker * Can't trust the integrity of the kernel anymore. 2589eeba613SFrederic Weisbecker * We don't call directly debug_locks_off() because the issue 2599eeba613SFrederic Weisbecker * is not necessarily serious enough to set oops_in_progress to 1 2609ec84aceSBen Hutchings * Also we want to keep up lockdep for staging/out-of-tree 2619ec84aceSBen Hutchings * development and post-warning case. 2629eeba613SFrederic Weisbecker */ 263df754e6aSPeter Zijlstra switch (flag) { 264df754e6aSPeter Zijlstra case TAINT_CRAP: 2659ec84aceSBen Hutchings case TAINT_OOT_MODULE: 266df754e6aSPeter Zijlstra case TAINT_WARN: 267df754e6aSPeter Zijlstra case TAINT_FIRMWARE_WORKAROUND: 268df754e6aSPeter Zijlstra break; 269df754e6aSPeter Zijlstra 270df754e6aSPeter Zijlstra default: 271df754e6aSPeter Zijlstra if (__debug_locks_off()) 272b48ccb09SIngo Molnar printk(KERN_WARNING "Disabling lock debugging due to kernel taint\n"); 273df754e6aSPeter Zijlstra } 2749eeba613SFrederic Weisbecker 27525ddbb18SAndi Kleen set_bit(flag, &tainted_mask); 2761da177e4SLinus Torvalds } 2771da177e4SLinus Torvalds EXPORT_SYMBOL(add_taint); 278dd287796SAndrew Morton 279dd287796SAndrew Morton static void spin_msec(int msecs) 280dd287796SAndrew Morton { 281dd287796SAndrew Morton int i; 282dd287796SAndrew Morton 283dd287796SAndrew Morton for (i = 0; i < msecs; i++) { 284dd287796SAndrew Morton touch_nmi_watchdog(); 285dd287796SAndrew Morton mdelay(1); 286dd287796SAndrew Morton } 287dd287796SAndrew Morton } 288dd287796SAndrew Morton 289dd287796SAndrew Morton /* 290dd287796SAndrew Morton * It just happens that oops_enter() and oops_exit() are identically 291dd287796SAndrew Morton * implemented... 292dd287796SAndrew Morton */ 293dd287796SAndrew Morton static void do_oops_enter_exit(void) 294dd287796SAndrew Morton { 295dd287796SAndrew Morton unsigned long flags; 296dd287796SAndrew Morton static int spin_counter; 297dd287796SAndrew Morton 298dd287796SAndrew Morton if (!pause_on_oops) 299dd287796SAndrew Morton return; 300dd287796SAndrew Morton 301dd287796SAndrew Morton spin_lock_irqsave(&pause_on_oops_lock, flags); 302dd287796SAndrew Morton if (pause_on_oops_flag == 0) { 303dd287796SAndrew Morton /* This CPU may now print the oops message */ 304dd287796SAndrew Morton pause_on_oops_flag = 1; 305dd287796SAndrew Morton } else { 306dd287796SAndrew Morton /* We need to stall this CPU */ 307dd287796SAndrew Morton if (!spin_counter) { 308dd287796SAndrew Morton /* This CPU gets to do the counting */ 309dd287796SAndrew Morton spin_counter = pause_on_oops; 310dd287796SAndrew Morton do { 311dd287796SAndrew Morton spin_unlock(&pause_on_oops_lock); 312dd287796SAndrew Morton spin_msec(MSEC_PER_SEC); 313dd287796SAndrew Morton spin_lock(&pause_on_oops_lock); 314dd287796SAndrew Morton } while (--spin_counter); 315dd287796SAndrew Morton pause_on_oops_flag = 0; 316dd287796SAndrew Morton } else { 317dd287796SAndrew Morton /* This CPU waits for a different one */ 318dd287796SAndrew Morton while (spin_counter) { 319dd287796SAndrew Morton spin_unlock(&pause_on_oops_lock); 320dd287796SAndrew Morton spin_msec(1); 321dd287796SAndrew Morton spin_lock(&pause_on_oops_lock); 322dd287796SAndrew Morton } 323dd287796SAndrew Morton } 324dd287796SAndrew Morton } 325dd287796SAndrew Morton spin_unlock_irqrestore(&pause_on_oops_lock, flags); 326dd287796SAndrew Morton } 327dd287796SAndrew Morton 328dd287796SAndrew Morton /* 329c95dbf27SIngo Molnar * Return true if the calling CPU is allowed to print oops-related info. 330c95dbf27SIngo Molnar * This is a bit racy.. 331dd287796SAndrew Morton */ 332dd287796SAndrew Morton int oops_may_print(void) 333dd287796SAndrew Morton { 334dd287796SAndrew Morton return pause_on_oops_flag == 0; 335dd287796SAndrew Morton } 336dd287796SAndrew Morton 337dd287796SAndrew Morton /* 338dd287796SAndrew Morton * Called when the architecture enters its oops handler, before it prints 339c95dbf27SIngo Molnar * anything. If this is the first CPU to oops, and it's oopsing the first 340c95dbf27SIngo Molnar * time then let it proceed. 341dd287796SAndrew Morton * 342c95dbf27SIngo Molnar * This is all enabled by the pause_on_oops kernel boot option. We do all 343c95dbf27SIngo Molnar * this to ensure that oopses don't scroll off the screen. It has the 344c95dbf27SIngo Molnar * side-effect of preventing later-oopsing CPUs from mucking up the display, 345c95dbf27SIngo Molnar * too. 346dd287796SAndrew Morton * 347c95dbf27SIngo Molnar * It turns out that the CPU which is allowed to print ends up pausing for 348c95dbf27SIngo Molnar * the right duration, whereas all the other CPUs pause for twice as long: 349c95dbf27SIngo Molnar * once in oops_enter(), once in oops_exit(). 350dd287796SAndrew Morton */ 351dd287796SAndrew Morton void oops_enter(void) 352dd287796SAndrew Morton { 353bdff7870SThomas Gleixner tracing_off(); 354c95dbf27SIngo Molnar /* can't trust the integrity of the kernel anymore: */ 355c95dbf27SIngo Molnar debug_locks_off(); 356dd287796SAndrew Morton do_oops_enter_exit(); 357dd287796SAndrew Morton } 358dd287796SAndrew Morton 359dd287796SAndrew Morton /* 3602c3b20e9SArjan van de Ven * 64-bit random ID for oopses: 3612c3b20e9SArjan van de Ven */ 3622c3b20e9SArjan van de Ven static u64 oops_id; 3632c3b20e9SArjan van de Ven 3642c3b20e9SArjan van de Ven static int init_oops_id(void) 3652c3b20e9SArjan van de Ven { 3662c3b20e9SArjan van de Ven if (!oops_id) 3672c3b20e9SArjan van de Ven get_random_bytes(&oops_id, sizeof(oops_id)); 368d6624f99SArjan van de Ven else 369d6624f99SArjan van de Ven oops_id++; 3702c3b20e9SArjan van de Ven 3712c3b20e9SArjan van de Ven return 0; 3722c3b20e9SArjan van de Ven } 3732c3b20e9SArjan van de Ven late_initcall(init_oops_id); 3742c3b20e9SArjan van de Ven 375863a6049SAnton Blanchard void print_oops_end_marker(void) 37671c33911SArjan van de Ven { 37771c33911SArjan van de Ven init_oops_id(); 37871c33911SArjan van de Ven printk(KERN_WARNING "---[ end trace %016llx ]---\n", 37971c33911SArjan van de Ven (unsigned long long)oops_id); 38071c33911SArjan van de Ven } 38171c33911SArjan van de Ven 3822c3b20e9SArjan van de Ven /* 383dd287796SAndrew Morton * Called when the architecture exits its oops handler, after printing 384dd287796SAndrew Morton * everything. 385dd287796SAndrew Morton */ 386dd287796SAndrew Morton void oops_exit(void) 387dd287796SAndrew Morton { 388dd287796SAndrew Morton do_oops_enter_exit(); 38971c33911SArjan van de Ven print_oops_end_marker(); 390456b565cSSimon Kagstrom kmsg_dump(KMSG_DUMP_OOPS); 391dd287796SAndrew Morton } 3923162f751SArjan van de Ven 39379b4cc5eSArjan van de Ven #ifdef WANT_WARN_ON_SLOWPATH 3940f6f49a8SLinus Torvalds struct slowpath_args { 3950f6f49a8SLinus Torvalds const char *fmt; 396a8f18b90SArjan van de Ven va_list args; 3970f6f49a8SLinus Torvalds }; 3980f6f49a8SLinus Torvalds 399b2be0527SBen Hutchings static void warn_slowpath_common(const char *file, int line, void *caller, 400b2be0527SBen Hutchings unsigned taint, struct slowpath_args *args) 4010f6f49a8SLinus Torvalds { 402bd89bb29SArjan van de Ven const char *board; 403bd89bb29SArjan van de Ven 404a8f18b90SArjan van de Ven printk(KERN_WARNING "------------[ cut here ]------------\n"); 4050f6f49a8SLinus Torvalds printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller); 406bd89bb29SArjan van de Ven board = dmi_get_system_info(DMI_PRODUCT_NAME); 407bd89bb29SArjan van de Ven if (board) 408bd89bb29SArjan van de Ven printk(KERN_WARNING "Hardware name: %s\n", board); 40974853dbaSArjan van de Ven 4100f6f49a8SLinus Torvalds if (args) 4110f6f49a8SLinus Torvalds vprintk(args->fmt, args->args); 412a8f18b90SArjan van de Ven 413a8f18b90SArjan van de Ven print_modules(); 414a8f18b90SArjan van de Ven dump_stack(); 415a8f18b90SArjan van de Ven print_oops_end_marker(); 416b2be0527SBen Hutchings add_taint(taint); 417a8f18b90SArjan van de Ven } 4180f6f49a8SLinus Torvalds 4190f6f49a8SLinus Torvalds void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...) 4200f6f49a8SLinus Torvalds { 4210f6f49a8SLinus Torvalds struct slowpath_args args; 4220f6f49a8SLinus Torvalds 4230f6f49a8SLinus Torvalds args.fmt = fmt; 4240f6f49a8SLinus Torvalds va_start(args.args, fmt); 425b2be0527SBen Hutchings warn_slowpath_common(file, line, __builtin_return_address(0), 426b2be0527SBen Hutchings TAINT_WARN, &args); 4270f6f49a8SLinus Torvalds va_end(args.args); 4280f6f49a8SLinus Torvalds } 42957adc4d2SAndi Kleen EXPORT_SYMBOL(warn_slowpath_fmt); 43057adc4d2SAndi Kleen 431b2be0527SBen Hutchings void warn_slowpath_fmt_taint(const char *file, int line, 432b2be0527SBen Hutchings unsigned taint, const char *fmt, ...) 433b2be0527SBen Hutchings { 434b2be0527SBen Hutchings struct slowpath_args args; 435b2be0527SBen Hutchings 436b2be0527SBen Hutchings args.fmt = fmt; 437b2be0527SBen Hutchings va_start(args.args, fmt); 438b2be0527SBen Hutchings warn_slowpath_common(file, line, __builtin_return_address(0), 439b2be0527SBen Hutchings taint, &args); 440b2be0527SBen Hutchings va_end(args.args); 441b2be0527SBen Hutchings } 442b2be0527SBen Hutchings EXPORT_SYMBOL(warn_slowpath_fmt_taint); 443b2be0527SBen Hutchings 44457adc4d2SAndi Kleen void warn_slowpath_null(const char *file, int line) 44557adc4d2SAndi Kleen { 446b2be0527SBen Hutchings warn_slowpath_common(file, line, __builtin_return_address(0), 447b2be0527SBen Hutchings TAINT_WARN, NULL); 44857adc4d2SAndi Kleen } 44957adc4d2SAndi Kleen EXPORT_SYMBOL(warn_slowpath_null); 45079b4cc5eSArjan van de Ven #endif 45179b4cc5eSArjan van de Ven 4523162f751SArjan van de Ven #ifdef CONFIG_CC_STACKPROTECTOR 45354371a43SArjan van de Ven 4543162f751SArjan van de Ven /* 4553162f751SArjan van de Ven * Called when gcc's -fstack-protector feature is used, and 4563162f751SArjan van de Ven * gcc detects corruption of the on-stack canary value 4573162f751SArjan van de Ven */ 4583162f751SArjan van de Ven void __stack_chk_fail(void) 4593162f751SArjan van de Ven { 460517a92c4SIngo Molnar panic("stack-protector: Kernel stack is corrupted in: %p\n", 461517a92c4SIngo Molnar __builtin_return_address(0)); 4623162f751SArjan van de Ven } 4633162f751SArjan van de Ven EXPORT_SYMBOL(__stack_chk_fail); 46454371a43SArjan van de Ven 4653162f751SArjan van de Ven #endif 466f44dd164SRusty Russell 467f44dd164SRusty Russell core_param(panic, panic_timeout, int, 0644); 468f44dd164SRusty Russell core_param(pause_on_oops, pause_on_oops, int, 0644); 469d404ab0aSOlaf Hering 470d404ab0aSOlaf Hering static int __init oops_setup(char *s) 471d404ab0aSOlaf Hering { 472d404ab0aSOlaf Hering if (!s) 473d404ab0aSOlaf Hering return -EINVAL; 474d404ab0aSOlaf Hering if (!strcmp(s, "panic")) 475d404ab0aSOlaf Hering panic_on_oops = 1; 476d404ab0aSOlaf Hering return 0; 477d404ab0aSOlaf Hering } 478d404ab0aSOlaf Hering early_param("oops", oops_setup); 479