1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * linux/kernel/panic.c 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds 61da177e4SLinus Torvalds */ 71da177e4SLinus Torvalds 81da177e4SLinus Torvalds /* 91da177e4SLinus Torvalds * This function is used through-out the kernel (including mm and fs) 101da177e4SLinus Torvalds * to indicate a major problem. 111da177e4SLinus Torvalds */ 12657b3010SAndrew Morton #include <linux/debug_locks.h> 13b17b0153SIngo Molnar #include <linux/sched/debug.h> 14c95dbf27SIngo Molnar #include <linux/interrupt.h> 157d92bda2SDouglas Anderson #include <linux/kgdb.h> 16456b565cSSimon Kagstrom #include <linux/kmsg_dump.h> 1779b4cc5eSArjan van de Ven #include <linux/kallsyms.h> 18c95dbf27SIngo Molnar #include <linux/notifier.h> 19c7c3f05eSSergey Senozhatsky #include <linux/vt_kern.h> 20c95dbf27SIngo Molnar #include <linux/module.h> 21c95dbf27SIngo Molnar #include <linux/random.h> 22de7edd31SSteven Rostedt (Red Hat) #include <linux/ftrace.h> 23c95dbf27SIngo Molnar #include <linux/reboot.h> 24c95dbf27SIngo Molnar #include <linux/delay.h> 25c95dbf27SIngo Molnar #include <linux/kexec.h> 26f39650deSAndy Shevchenko #include <linux/panic_notifier.h> 27c95dbf27SIngo Molnar #include <linux/sched.h> 285d5dd3e4SAndy Shevchenko #include <linux/string_helpers.h> 29c95dbf27SIngo Molnar #include <linux/sysrq.h> 30c95dbf27SIngo Molnar #include <linux/init.h> 31c95dbf27SIngo Molnar #include <linux/nmi.h> 3208d78658SVitaly Kuznetsov #include <linux/console.h> 332553b67aSJosh Poimboeuf #include <linux/bug.h> 347a46ec0eSKees Cook #include <linux/ratelimit.h> 35b1fca27dSAndi Kleen #include <linux/debugfs.h> 368b05aa26SKees Cook #include <linux/sysfs.h> 375a5d7e9bSPeter Zijlstra #include <linux/context_tracking.h> 3823b36fecSMarco Elver #include <trace/events/error_report.h> 39b1fca27dSAndi Kleen #include <asm/sections.h> 401da177e4SLinus Torvalds 41c7ff0d9cSTAMUKI Shoichi #define PANIC_TIMER_STEP 100 42c7ff0d9cSTAMUKI Shoichi #define PANIC_BLINK_SPD 18 43c7ff0d9cSTAMUKI Shoichi 4460c958d8SGuilherme G. Piccoli #ifdef CONFIG_SMP 4560c958d8SGuilherme G. Piccoli /* 4660c958d8SGuilherme G. Piccoli * Should we dump all CPUs backtraces in an oops event? 4760c958d8SGuilherme G. Piccoli * Defaults to 0, can be changed via sysctl. 4860c958d8SGuilherme G. Piccoli */ 499df91869Stangmeng static unsigned int __read_mostly sysctl_oops_all_cpu_backtrace; 509df91869Stangmeng #else 519df91869Stangmeng #define sysctl_oops_all_cpu_backtrace 0 5260c958d8SGuilherme G. Piccoli #endif /* CONFIG_SMP */ 5360c958d8SGuilherme G. Piccoli 542a01bb38SKyle McMartin int panic_on_oops = CONFIG_PANIC_ON_OOPS_VALUE; 55bc4f2f54SKees Cook static unsigned long tainted_mask = 56595b893eSKees Cook IS_ENABLED(CONFIG_RANDSTRUCT) ? (1 << TAINT_RANDSTRUCT) : 0; 57dd287796SAndrew Morton static int pause_on_oops; 58dd287796SAndrew Morton static int pause_on_oops_flag; 59dd287796SAndrew Morton static DEFINE_SPINLOCK(pause_on_oops_lock); 605375b708SHATAYAMA Daisuke bool crash_kexec_post_notifiers; 619e3961a0SPrarit Bhargava int panic_on_warn __read_mostly; 62db38d5c1SRafael Aquini unsigned long panic_on_taint; 63db38d5c1SRafael Aquini bool panic_on_taint_nousertaint = false; 649fc9e278SKees Cook static unsigned int warn_limit __read_mostly; 651da177e4SLinus Torvalds 665800dc3cSJason Baron int panic_timeout = CONFIG_PANIC_TIMEOUT; 6781e88fdcSHuang Ying EXPORT_SYMBOL_GPL(panic_timeout); 681da177e4SLinus Torvalds 69d999bd93SFeng Tang #define PANIC_PRINT_TASK_INFO 0x00000001 70d999bd93SFeng Tang #define PANIC_PRINT_MEM_INFO 0x00000002 71d999bd93SFeng Tang #define PANIC_PRINT_TIMER_INFO 0x00000004 72d999bd93SFeng Tang #define PANIC_PRINT_LOCK_INFO 0x00000008 73d999bd93SFeng Tang #define PANIC_PRINT_FTRACE_INFO 0x00000010 74de6da1e8SFeng Tang #define PANIC_PRINT_ALL_PRINTK_MSG 0x00000020 758d470a45SGuilherme G. Piccoli #define PANIC_PRINT_ALL_CPU_BT 0x00000040 7681c9d43fSFeng Tang unsigned long panic_print; 77d999bd93SFeng Tang 78e041c683SAlan Stern ATOMIC_NOTIFIER_HEAD(panic_notifier_list); 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds EXPORT_SYMBOL(panic_notifier_list); 811da177e4SLinus Torvalds 829360d035SKees Cook #ifdef CONFIG_SYSCTL 839df91869Stangmeng static struct ctl_table kern_panic_table[] = { 849360d035SKees Cook #ifdef CONFIG_SMP 859df91869Stangmeng { 869df91869Stangmeng .procname = "oops_all_cpu_backtrace", 879df91869Stangmeng .data = &sysctl_oops_all_cpu_backtrace, 889df91869Stangmeng .maxlen = sizeof(int), 899df91869Stangmeng .mode = 0644, 909df91869Stangmeng .proc_handler = proc_dointvec_minmax, 919df91869Stangmeng .extra1 = SYSCTL_ZERO, 929df91869Stangmeng .extra2 = SYSCTL_ONE, 939df91869Stangmeng }, 949360d035SKees Cook #endif 959fc9e278SKees Cook { 969fc9e278SKees Cook .procname = "warn_limit", 979fc9e278SKees Cook .data = &warn_limit, 989fc9e278SKees Cook .maxlen = sizeof(warn_limit), 999fc9e278SKees Cook .mode = 0644, 1009fc9e278SKees Cook .proc_handler = proc_douintvec, 1019fc9e278SKees Cook }, 1029df91869Stangmeng { } 1039df91869Stangmeng }; 1049df91869Stangmeng 1059df91869Stangmeng static __init int kernel_panic_sysctls_init(void) 1069df91869Stangmeng { 1079df91869Stangmeng register_sysctl_init("kernel", kern_panic_table); 1089df91869Stangmeng return 0; 1099df91869Stangmeng } 1109df91869Stangmeng late_initcall(kernel_panic_sysctls_init); 1119df91869Stangmeng #endif 1129df91869Stangmeng 1138b05aa26SKees Cook static atomic_t warn_count = ATOMIC_INIT(0); 1148b05aa26SKees Cook 1158b05aa26SKees Cook #ifdef CONFIG_SYSFS 1168b05aa26SKees Cook static ssize_t warn_count_show(struct kobject *kobj, struct kobj_attribute *attr, 1178b05aa26SKees Cook char *page) 1188b05aa26SKees Cook { 1198b05aa26SKees Cook return sysfs_emit(page, "%d\n", atomic_read(&warn_count)); 1208b05aa26SKees Cook } 1218b05aa26SKees Cook 1228b05aa26SKees Cook static struct kobj_attribute warn_count_attr = __ATTR_RO(warn_count); 1238b05aa26SKees Cook 1248b05aa26SKees Cook static __init int kernel_panic_sysfs_init(void) 1258b05aa26SKees Cook { 1268b05aa26SKees Cook sysfs_add_file_to_group(kernel_kobj, &warn_count_attr.attr, NULL); 1278b05aa26SKees Cook return 0; 1288b05aa26SKees Cook } 1298b05aa26SKees Cook late_initcall(kernel_panic_sysfs_init); 1308b05aa26SKees Cook #endif 1318b05aa26SKees Cook 132c7ff0d9cSTAMUKI Shoichi static long no_blink(int state) 1338aeee85aSAnton Blanchard { 134c7ff0d9cSTAMUKI Shoichi return 0; 135c7ff0d9cSTAMUKI Shoichi } 1368aeee85aSAnton Blanchard 137c7ff0d9cSTAMUKI Shoichi /* Returns how long it waited in ms */ 138c7ff0d9cSTAMUKI Shoichi long (*panic_blink)(int state); 139c7ff0d9cSTAMUKI Shoichi EXPORT_SYMBOL(panic_blink); 1408aeee85aSAnton Blanchard 14193e13a36SMichael Holzheu /* 14293e13a36SMichael Holzheu * Stop ourself in panic -- architecture code may override this 14393e13a36SMichael Holzheu */ 1447412a60dSJosh Poimboeuf void __weak __noreturn panic_smp_self_stop(void) 14593e13a36SMichael Holzheu { 14693e13a36SMichael Holzheu while (1) 14793e13a36SMichael Holzheu cpu_relax(); 14893e13a36SMichael Holzheu } 14993e13a36SMichael Holzheu 15058c5661fSHidehiro Kawai /* 15158c5661fSHidehiro Kawai * Stop ourselves in NMI context if another CPU has already panicked. Arch code 15258c5661fSHidehiro Kawai * may override this to prepare for crash dumping, e.g. save regs info. 15358c5661fSHidehiro Kawai */ 15427dea14cSJosh Poimboeuf void __weak __noreturn nmi_panic_self_stop(struct pt_regs *regs) 15558c5661fSHidehiro Kawai { 15658c5661fSHidehiro Kawai panic_smp_self_stop(); 15758c5661fSHidehiro Kawai } 15858c5661fSHidehiro Kawai 1590ee59413SHidehiro Kawai /* 1600ee59413SHidehiro Kawai * Stop other CPUs in panic. Architecture dependent code may override this 1610ee59413SHidehiro Kawai * with more suitable version. For example, if the architecture supports 1620ee59413SHidehiro Kawai * crash dump, it should save registers of each stopped CPU and disable 1630ee59413SHidehiro Kawai * per-CPU features such as virtualization extensions. 1640ee59413SHidehiro Kawai */ 1650ee59413SHidehiro Kawai void __weak crash_smp_send_stop(void) 1660ee59413SHidehiro Kawai { 1670ee59413SHidehiro Kawai static int cpus_stopped; 1680ee59413SHidehiro Kawai 1690ee59413SHidehiro Kawai /* 1700ee59413SHidehiro Kawai * This function can be called twice in panic path, but obviously 1710ee59413SHidehiro Kawai * we execute this only once. 1720ee59413SHidehiro Kawai */ 1730ee59413SHidehiro Kawai if (cpus_stopped) 1740ee59413SHidehiro Kawai return; 1750ee59413SHidehiro Kawai 1760ee59413SHidehiro Kawai /* 1770ee59413SHidehiro Kawai * Note smp_send_stop is the usual smp shutdown function, which 1780ee59413SHidehiro Kawai * unfortunately means it may not be hardened to work in a panic 1790ee59413SHidehiro Kawai * situation. 1800ee59413SHidehiro Kawai */ 1810ee59413SHidehiro Kawai smp_send_stop(); 1820ee59413SHidehiro Kawai cpus_stopped = 1; 1830ee59413SHidehiro Kawai } 1840ee59413SHidehiro Kawai 1851717f209SHidehiro Kawai atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID); 1861717f209SHidehiro Kawai 187ebc41f20SHidehiro Kawai /* 188ebc41f20SHidehiro Kawai * A variant of panic() called from NMI context. We return if we've already 189ebc41f20SHidehiro Kawai * panicked on this CPU. If another CPU already panicked, loop in 190ebc41f20SHidehiro Kawai * nmi_panic_self_stop() which can provide architecture dependent code such 191ebc41f20SHidehiro Kawai * as saving register state for crash dump. 192ebc41f20SHidehiro Kawai */ 193ebc41f20SHidehiro Kawai void nmi_panic(struct pt_regs *regs, const char *msg) 194ebc41f20SHidehiro Kawai { 195ebc41f20SHidehiro Kawai int old_cpu, cpu; 196ebc41f20SHidehiro Kawai 197ebc41f20SHidehiro Kawai cpu = raw_smp_processor_id(); 198ebc41f20SHidehiro Kawai old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, cpu); 199ebc41f20SHidehiro Kawai 200ebc41f20SHidehiro Kawai if (old_cpu == PANIC_CPU_INVALID) 201ebc41f20SHidehiro Kawai panic("%s", msg); 202ebc41f20SHidehiro Kawai else if (old_cpu != cpu) 203ebc41f20SHidehiro Kawai nmi_panic_self_stop(regs); 204ebc41f20SHidehiro Kawai } 205ebc41f20SHidehiro Kawai EXPORT_SYMBOL(nmi_panic); 206ebc41f20SHidehiro Kawai 207f953f140SGuilherme G. Piccoli static void panic_print_sys_info(bool console_flush) 208d999bd93SFeng Tang { 209f953f140SGuilherme G. Piccoli if (console_flush) { 210de6da1e8SFeng Tang if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG) 211de6da1e8SFeng Tang console_flush_on_panic(CONSOLE_REPLAY_ALL); 212f953f140SGuilherme G. Piccoli return; 213f953f140SGuilherme G. Piccoli } 214de6da1e8SFeng Tang 215d999bd93SFeng Tang if (panic_print & PANIC_PRINT_TASK_INFO) 216d999bd93SFeng Tang show_state(); 217d999bd93SFeng Tang 218d999bd93SFeng Tang if (panic_print & PANIC_PRINT_MEM_INFO) 219527ed4f7SKefeng Wang show_mem(); 220d999bd93SFeng Tang 221d999bd93SFeng Tang if (panic_print & PANIC_PRINT_TIMER_INFO) 222d999bd93SFeng Tang sysrq_timer_list_show(); 223d999bd93SFeng Tang 224d999bd93SFeng Tang if (panic_print & PANIC_PRINT_LOCK_INFO) 225d999bd93SFeng Tang debug_show_all_locks(); 226d999bd93SFeng Tang 227d999bd93SFeng Tang if (panic_print & PANIC_PRINT_FTRACE_INFO) 228d999bd93SFeng Tang ftrace_dump(DUMP_ALL); 229d999bd93SFeng Tang } 230d999bd93SFeng Tang 23179cc1ba7SKees Cook void check_panic_on_warn(const char *origin) 23279cc1ba7SKees Cook { 2337535b832SKees Cook unsigned int limit; 2347535b832SKees Cook 23579cc1ba7SKees Cook if (panic_on_warn) 23679cc1ba7SKees Cook panic("%s: panic_on_warn set ...\n", origin); 2379fc9e278SKees Cook 2387535b832SKees Cook limit = READ_ONCE(warn_limit); 2397535b832SKees Cook if (atomic_inc_return(&warn_count) >= limit && limit) 2409fc9e278SKees Cook panic("%s: system warned too often (kernel.warn_limit is %d)", 2417535b832SKees Cook origin, limit); 24279cc1ba7SKees Cook } 24379cc1ba7SKees Cook 244b905039eSGuilherme G. Piccoli /* 245b905039eSGuilherme G. Piccoli * Helper that triggers the NMI backtrace (if set in panic_print) 246b905039eSGuilherme G. Piccoli * and then performs the secondary CPUs shutdown - we cannot have 247b905039eSGuilherme G. Piccoli * the NMI backtrace after the CPUs are off! 248b905039eSGuilherme G. Piccoli */ 249b905039eSGuilherme G. Piccoli static void panic_other_cpus_shutdown(bool crash_kexec) 250b905039eSGuilherme G. Piccoli { 251b905039eSGuilherme G. Piccoli if (panic_print & PANIC_PRINT_ALL_CPU_BT) 252b905039eSGuilherme G. Piccoli trigger_all_cpu_backtrace(); 253b905039eSGuilherme G. Piccoli 254b905039eSGuilherme G. Piccoli /* 255b905039eSGuilherme G. Piccoli * Note that smp_send_stop() is the usual SMP shutdown function, 256b905039eSGuilherme G. Piccoli * which unfortunately may not be hardened to work in a panic 257b905039eSGuilherme G. Piccoli * situation. If we want to do crash dump after notifier calls 258b905039eSGuilherme G. Piccoli * and kmsg_dump, we will need architecture dependent extra 259b905039eSGuilherme G. Piccoli * bits in addition to stopping other CPUs, hence we rely on 260b905039eSGuilherme G. Piccoli * crash_smp_send_stop() for that. 261b905039eSGuilherme G. Piccoli */ 262b905039eSGuilherme G. Piccoli if (!crash_kexec) 263b905039eSGuilherme G. Piccoli smp_send_stop(); 264b905039eSGuilherme G. Piccoli else 265b905039eSGuilherme G. Piccoli crash_smp_send_stop(); 266b905039eSGuilherme G. Piccoli } 267b905039eSGuilherme G. Piccoli 2681da177e4SLinus Torvalds /** 2691da177e4SLinus Torvalds * panic - halt the system 2701da177e4SLinus Torvalds * @fmt: The text string to print 2711da177e4SLinus Torvalds * 2721da177e4SLinus Torvalds * Display a message, then perform cleanups. 2731da177e4SLinus Torvalds * 2741da177e4SLinus Torvalds * This function never returns. 2751da177e4SLinus Torvalds */ 2769402c95fSJoe Perches void panic(const char *fmt, ...) 2771da177e4SLinus Torvalds { 2781da177e4SLinus Torvalds static char buf[1024]; 2791da177e4SLinus Torvalds va_list args; 280b49dec1cSBorislav Petkov long i, i_next = 0, len; 281c7ff0d9cSTAMUKI Shoichi int state = 0; 2821717f209SHidehiro Kawai int old_cpu, this_cpu; 283b26e27ddSHidehiro Kawai bool _crash_kexec_post_notifiers = crash_kexec_post_notifiers; 2841da177e4SLinus Torvalds 2851a2383e8STiezhu Yang if (panic_on_warn) { 2861a2383e8STiezhu Yang /* 2871a2383e8STiezhu Yang * This thread may hit another WARN() in the panic path. 2881a2383e8STiezhu Yang * Resetting this prevents additional WARN() from panicking the 2891a2383e8STiezhu Yang * system on this thread. Other threads are blocked by the 2901a2383e8STiezhu Yang * panic_mutex in panic(). 2911a2383e8STiezhu Yang */ 2921a2383e8STiezhu Yang panic_on_warn = 0; 2931a2383e8STiezhu Yang } 2941a2383e8STiezhu Yang 295dc009d92SEric W. Biederman /* 296190320c3SVikram Mulukutla * Disable local interrupts. This will prevent panic_smp_self_stop 297190320c3SVikram Mulukutla * from deadlocking the first cpu that invokes the panic, since 298190320c3SVikram Mulukutla * there is nothing to prevent an interrupt handler (that runs 2991717f209SHidehiro Kawai * after setting panic_cpu) from invoking panic() again. 300190320c3SVikram Mulukutla */ 301190320c3SVikram Mulukutla local_irq_disable(); 30220bb759aSWill Deacon preempt_disable_notrace(); 303190320c3SVikram Mulukutla 304190320c3SVikram Mulukutla /* 305c95dbf27SIngo Molnar * It's possible to come here directly from a panic-assertion and 306c95dbf27SIngo Molnar * not have preempt disabled. Some functions called from here want 307dc009d92SEric W. Biederman * preempt to be disabled. No point enabling it later though... 30893e13a36SMichael Holzheu * 30993e13a36SMichael Holzheu * Only one CPU is allowed to execute the panic code from here. For 31093e13a36SMichael Holzheu * multiple parallel invocations of panic, all other CPUs either 31193e13a36SMichael Holzheu * stop themself or will wait until they are stopped by the 1st CPU 31293e13a36SMichael Holzheu * with smp_send_stop(). 3131717f209SHidehiro Kawai * 3141717f209SHidehiro Kawai * `old_cpu == PANIC_CPU_INVALID' means this is the 1st CPU which 3151717f209SHidehiro Kawai * comes here, so go ahead. 3161717f209SHidehiro Kawai * `old_cpu == this_cpu' means we came from nmi_panic() which sets 3171717f209SHidehiro Kawai * panic_cpu to this CPU. In this case, this is also the 1st CPU. 318dc009d92SEric W. Biederman */ 3191717f209SHidehiro Kawai this_cpu = raw_smp_processor_id(); 3201717f209SHidehiro Kawai old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, this_cpu); 3211717f209SHidehiro Kawai 3221717f209SHidehiro Kawai if (old_cpu != PANIC_CPU_INVALID && old_cpu != this_cpu) 32393e13a36SMichael Holzheu panic_smp_self_stop(); 324dc009d92SEric W. Biederman 3255b530fc1SAnton Blanchard console_verbose(); 3261da177e4SLinus Torvalds bust_spinlocks(1); 3271da177e4SLinus Torvalds va_start(args, fmt); 328b49dec1cSBorislav Petkov len = vscnprintf(buf, sizeof(buf), fmt, args); 3291da177e4SLinus Torvalds va_end(args); 330b49dec1cSBorislav Petkov 331b49dec1cSBorislav Petkov if (len && buf[len - 1] == '\n') 332b49dec1cSBorislav Petkov buf[len - 1] = '\0'; 333b49dec1cSBorislav Petkov 334d7c0847fSFabian Frederick pr_emerg("Kernel panic - not syncing: %s\n", buf); 3355cb27301SIngo Molnar #ifdef CONFIG_DEBUG_BUGVERBOSE 3366e6f0a1fSAndi Kleen /* 3376e6f0a1fSAndi Kleen * Avoid nested stack-dumping if a panic occurs during oops processing 3386e6f0a1fSAndi Kleen */ 339026ee1f6SJason Wessel if (!test_taint(TAINT_DIE) && oops_in_progress <= 1) 3405cb27301SIngo Molnar dump_stack(); 3415cb27301SIngo Molnar #endif 3421da177e4SLinus Torvalds 343dc009d92SEric W. Biederman /* 3447d92bda2SDouglas Anderson * If kgdb is enabled, give it a chance to run before we stop all 3457d92bda2SDouglas Anderson * the other CPUs or else we won't be able to debug processes left 3467d92bda2SDouglas Anderson * running on them. 3477d92bda2SDouglas Anderson */ 3487d92bda2SDouglas Anderson kgdb_panic(buf); 3497d92bda2SDouglas Anderson 3507d92bda2SDouglas Anderson /* 351dc009d92SEric W. Biederman * If we have crashed and we have a crash kernel loaded let it handle 352dc009d92SEric W. Biederman * everything else. 353f06e5153SMasami Hiramatsu * If we want to run this after calling panic_notifiers, pass 354f06e5153SMasami Hiramatsu * the "crash_kexec_post_notifiers" option to the kernel. 3557bbee5caSHidehiro Kawai * 3567bbee5caSHidehiro Kawai * Bypass the panic_cpu check and call __crash_kexec directly. 357dc009d92SEric W. Biederman */ 358b905039eSGuilherme G. Piccoli if (!_crash_kexec_post_notifiers) 3597bbee5caSHidehiro Kawai __crash_kexec(NULL); 360dc009d92SEric W. Biederman 361b905039eSGuilherme G. Piccoli panic_other_cpus_shutdown(_crash_kexec_post_notifiers); 3621da177e4SLinus Torvalds 3636723734cSKees Cook /* 3646723734cSKees Cook * Run any panic handlers, including those that might need to 3656723734cSKees Cook * add information to the kmsg dump output. 3666723734cSKees Cook */ 367e041c683SAlan Stern atomic_notifier_call_chain(&panic_notifier_list, 0, buf); 3681da177e4SLinus Torvalds 369f953f140SGuilherme G. Piccoli panic_print_sys_info(false); 370f953f140SGuilherme G. Piccoli 3716723734cSKees Cook kmsg_dump(KMSG_DUMP_PANIC); 3726723734cSKees Cook 373f06e5153SMasami Hiramatsu /* 374f06e5153SMasami Hiramatsu * If you doubt kdump always works fine in any situation, 375f06e5153SMasami Hiramatsu * "crash_kexec_post_notifiers" offers you a chance to run 376f06e5153SMasami Hiramatsu * panic_notifiers and dumping kmsg before kdump. 377f06e5153SMasami Hiramatsu * Note: since some panic_notifiers can make crashed kernel 378f06e5153SMasami Hiramatsu * more unstable, it can increase risks of the kdump failure too. 3797bbee5caSHidehiro Kawai * 3807bbee5caSHidehiro Kawai * Bypass the panic_cpu check and call __crash_kexec directly. 381f06e5153SMasami Hiramatsu */ 382b26e27ddSHidehiro Kawai if (_crash_kexec_post_notifiers) 3837bbee5caSHidehiro Kawai __crash_kexec(NULL); 384f06e5153SMasami Hiramatsu 385c7c3f05eSSergey Senozhatsky console_unblank(); 386d014e889SAaro Koskinen 38708d78658SVitaly Kuznetsov /* 38808d78658SVitaly Kuznetsov * We may have ended up stopping the CPU holding the lock (in 38908d78658SVitaly Kuznetsov * smp_send_stop()) while still having some valuable data in the console 39008d78658SVitaly Kuznetsov * buffer. Try to acquire the lock then release it regardless of the 3917625b3a0SVitaly Kuznetsov * result. The release will also print the buffers out. Locks debug 3927625b3a0SVitaly Kuznetsov * should be disabled to avoid reporting bad unlock balance when 3937625b3a0SVitaly Kuznetsov * panic() is not being callled from OOPS. 39408d78658SVitaly Kuznetsov */ 3957625b3a0SVitaly Kuznetsov debug_locks_off(); 396de6da1e8SFeng Tang console_flush_on_panic(CONSOLE_FLUSH_PENDING); 39708d78658SVitaly Kuznetsov 398f953f140SGuilherme G. Piccoli panic_print_sys_info(true); 399d999bd93SFeng Tang 400c7ff0d9cSTAMUKI Shoichi if (!panic_blink) 401c7ff0d9cSTAMUKI Shoichi panic_blink = no_blink; 402c7ff0d9cSTAMUKI Shoichi 403dc009d92SEric W. Biederman if (panic_timeout > 0) { 4041da177e4SLinus Torvalds /* 4051da177e4SLinus Torvalds * Delay timeout seconds before rebooting the machine. 406c95dbf27SIngo Molnar * We can't use the "normal" timers since we just panicked. 4071da177e4SLinus Torvalds */ 408ff7a28a0SJiri Slaby pr_emerg("Rebooting in %d seconds..\n", panic_timeout); 409c95dbf27SIngo Molnar 410c7ff0d9cSTAMUKI Shoichi for (i = 0; i < panic_timeout * 1000; i += PANIC_TIMER_STEP) { 4111da177e4SLinus Torvalds touch_nmi_watchdog(); 412c7ff0d9cSTAMUKI Shoichi if (i >= i_next) { 413c7ff0d9cSTAMUKI Shoichi i += panic_blink(state ^= 1); 414c7ff0d9cSTAMUKI Shoichi i_next = i + 3600 / PANIC_BLINK_SPD; 415c7ff0d9cSTAMUKI Shoichi } 416c7ff0d9cSTAMUKI Shoichi mdelay(PANIC_TIMER_STEP); 4171da177e4SLinus Torvalds } 4184302fbc8SHugh Dickins } 4194302fbc8SHugh Dickins if (panic_timeout != 0) { 420c95dbf27SIngo Molnar /* 421c95dbf27SIngo Molnar * This will not be a clean reboot, with everything 4222f048ea8SEric W. Biederman * shutting down. But if there is a chance of 4232f048ea8SEric W. Biederman * rebooting the system it will be rebooted. 4241da177e4SLinus Torvalds */ 425b287a25aSAaro Koskinen if (panic_reboot_mode != REBOOT_UNDEFINED) 426b287a25aSAaro Koskinen reboot_mode = panic_reboot_mode; 4272f048ea8SEric W. Biederman emergency_restart(); 4281da177e4SLinus Torvalds } 4291da177e4SLinus Torvalds #ifdef __sparc__ 4301da177e4SLinus Torvalds { 4311da177e4SLinus Torvalds extern int stop_a_enabled; 432a271c241STom 'spot' Callaway /* Make sure the user can actually press Stop-A (L1-A) */ 4331da177e4SLinus Torvalds stop_a_enabled = 1; 4347db60d05SVijay Kumar pr_emerg("Press Stop-A (L1-A) from sun keyboard or send break\n" 4357db60d05SVijay Kumar "twice on console to return to the boot prom\n"); 4361da177e4SLinus Torvalds } 4371da177e4SLinus Torvalds #endif 438347a8dc3SMartin Schwidefsky #if defined(CONFIG_S390) 43998587c2dSMartin Schwidefsky disabled_wait(); 4401da177e4SLinus Torvalds #endif 4415ad75105SBorislav Petkov pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf); 442c39ea0b9SFeng Tang 443c39ea0b9SFeng Tang /* Do not scroll important messages printed above */ 444c39ea0b9SFeng Tang suppress_printk = 1; 4451da177e4SLinus Torvalds local_irq_enable(); 446c7ff0d9cSTAMUKI Shoichi for (i = 0; ; i += PANIC_TIMER_STEP) { 447c22db941SJan Beulich touch_softlockup_watchdog(); 448c7ff0d9cSTAMUKI Shoichi if (i >= i_next) { 449c7ff0d9cSTAMUKI Shoichi i += panic_blink(state ^= 1); 450c7ff0d9cSTAMUKI Shoichi i_next = i + 3600 / PANIC_BLINK_SPD; 451c7ff0d9cSTAMUKI Shoichi } 452c7ff0d9cSTAMUKI Shoichi mdelay(PANIC_TIMER_STEP); 4531da177e4SLinus Torvalds } 4541da177e4SLinus Torvalds } 4551da177e4SLinus Torvalds 4561da177e4SLinus Torvalds EXPORT_SYMBOL(panic); 4571da177e4SLinus Torvalds 4587fd8329bSPetr Mladek /* 4597fd8329bSPetr Mladek * TAINT_FORCED_RMMOD could be a per-module flag but the module 4607fd8329bSPetr Mladek * is being removed anyway. 4617fd8329bSPetr Mladek */ 4627fd8329bSPetr Mladek const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = { 46347d4b263SKees Cook [ TAINT_PROPRIETARY_MODULE ] = { 'P', 'G', true }, 46447d4b263SKees Cook [ TAINT_FORCED_MODULE ] = { 'F', ' ', true }, 46547d4b263SKees Cook [ TAINT_CPU_OUT_OF_SPEC ] = { 'S', ' ', false }, 46647d4b263SKees Cook [ TAINT_FORCED_RMMOD ] = { 'R', ' ', false }, 46747d4b263SKees Cook [ TAINT_MACHINE_CHECK ] = { 'M', ' ', false }, 46847d4b263SKees Cook [ TAINT_BAD_PAGE ] = { 'B', ' ', false }, 46947d4b263SKees Cook [ TAINT_USER ] = { 'U', ' ', false }, 47047d4b263SKees Cook [ TAINT_DIE ] = { 'D', ' ', false }, 47147d4b263SKees Cook [ TAINT_OVERRIDDEN_ACPI_TABLE ] = { 'A', ' ', false }, 47247d4b263SKees Cook [ TAINT_WARN ] = { 'W', ' ', false }, 47347d4b263SKees Cook [ TAINT_CRAP ] = { 'C', ' ', true }, 47447d4b263SKees Cook [ TAINT_FIRMWARE_WORKAROUND ] = { 'I', ' ', false }, 47547d4b263SKees Cook [ TAINT_OOT_MODULE ] = { 'O', ' ', true }, 47647d4b263SKees Cook [ TAINT_UNSIGNED_MODULE ] = { 'E', ' ', true }, 47747d4b263SKees Cook [ TAINT_SOFTLOCKUP ] = { 'L', ' ', false }, 47847d4b263SKees Cook [ TAINT_LIVEPATCH ] = { 'K', ' ', true }, 47947d4b263SKees Cook [ TAINT_AUX ] = { 'X', ' ', true }, 480bc4f2f54SKees Cook [ TAINT_RANDSTRUCT ] = { 'T', ' ', true }, 4812852ca7fSDavid Gow [ TAINT_TEST ] = { 'N', ' ', true }, 48225ddbb18SAndi Kleen }; 48325ddbb18SAndi Kleen 4841da177e4SLinus Torvalds /** 4851da177e4SLinus Torvalds * print_tainted - return a string to represent the kernel taint state. 4861da177e4SLinus Torvalds * 48757043247SMauro Carvalho Chehab * For individual taint flag meanings, see Documentation/admin-guide/sysctl/kernel.rst 4881da177e4SLinus Torvalds * 4899c4560e5SKees Cook * The string is overwritten by the next call to print_tainted(), 4909c4560e5SKees Cook * but is always NULL terminated. 4911da177e4SLinus Torvalds */ 4921da177e4SLinus Torvalds const char *print_tainted(void) 4931da177e4SLinus Torvalds { 4947fd8329bSPetr Mladek static char buf[TAINT_FLAGS_COUNT + sizeof("Tainted: ")]; 49525ddbb18SAndi Kleen 49647d4b263SKees Cook BUILD_BUG_ON(ARRAY_SIZE(taint_flags) != TAINT_FLAGS_COUNT); 49747d4b263SKees Cook 49825ddbb18SAndi Kleen if (tainted_mask) { 49925ddbb18SAndi Kleen char *s; 50025ddbb18SAndi Kleen int i; 50125ddbb18SAndi Kleen 50225ddbb18SAndi Kleen s = buf + sprintf(buf, "Tainted: "); 5037fd8329bSPetr Mladek for (i = 0; i < TAINT_FLAGS_COUNT; i++) { 5047fd8329bSPetr Mladek const struct taint_flag *t = &taint_flags[i]; 5057fd8329bSPetr Mladek *s++ = test_bit(i, &tainted_mask) ? 5065eb7c0d0SLarry Finger t->c_true : t->c_false; 5071da177e4SLinus Torvalds } 50825ddbb18SAndi Kleen *s = 0; 50925ddbb18SAndi Kleen } else 5101da177e4SLinus Torvalds snprintf(buf, sizeof(buf), "Not tainted"); 511c95dbf27SIngo Molnar 512c95dbf27SIngo Molnar return buf; 5131da177e4SLinus Torvalds } 5141da177e4SLinus Torvalds 51525ddbb18SAndi Kleen int test_taint(unsigned flag) 51625ddbb18SAndi Kleen { 51725ddbb18SAndi Kleen return test_bit(flag, &tainted_mask); 51825ddbb18SAndi Kleen } 51925ddbb18SAndi Kleen EXPORT_SYMBOL(test_taint); 52025ddbb18SAndi Kleen 52125ddbb18SAndi Kleen unsigned long get_taint(void) 52225ddbb18SAndi Kleen { 52325ddbb18SAndi Kleen return tainted_mask; 52425ddbb18SAndi Kleen } 52525ddbb18SAndi Kleen 526373d4d09SRusty Russell /** 527373d4d09SRusty Russell * add_taint: add a taint flag if not already set. 528373d4d09SRusty Russell * @flag: one of the TAINT_* constants. 529373d4d09SRusty Russell * @lockdep_ok: whether lock debugging is still OK. 530373d4d09SRusty Russell * 531373d4d09SRusty Russell * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for 532373d4d09SRusty Russell * some notewortht-but-not-corrupting cases, it can be set to true. 5339eeba613SFrederic Weisbecker */ 534373d4d09SRusty Russell void add_taint(unsigned flag, enum lockdep_ok lockdep_ok) 535373d4d09SRusty Russell { 536373d4d09SRusty Russell if (lockdep_ok == LOCKDEP_NOW_UNRELIABLE && __debug_locks_off()) 537d7c0847fSFabian Frederick pr_warn("Disabling lock debugging due to kernel taint\n"); 5389eeba613SFrederic Weisbecker 53925ddbb18SAndi Kleen set_bit(flag, &tainted_mask); 540db38d5c1SRafael Aquini 541db38d5c1SRafael Aquini if (tainted_mask & panic_on_taint) { 542db38d5c1SRafael Aquini panic_on_taint = 0; 543db38d5c1SRafael Aquini panic("panic_on_taint set ..."); 544db38d5c1SRafael Aquini } 5451da177e4SLinus Torvalds } 5461da177e4SLinus Torvalds EXPORT_SYMBOL(add_taint); 547dd287796SAndrew Morton 548dd287796SAndrew Morton static void spin_msec(int msecs) 549dd287796SAndrew Morton { 550dd287796SAndrew Morton int i; 551dd287796SAndrew Morton 552dd287796SAndrew Morton for (i = 0; i < msecs; i++) { 553dd287796SAndrew Morton touch_nmi_watchdog(); 554dd287796SAndrew Morton mdelay(1); 555dd287796SAndrew Morton } 556dd287796SAndrew Morton } 557dd287796SAndrew Morton 558dd287796SAndrew Morton /* 559dd287796SAndrew Morton * It just happens that oops_enter() and oops_exit() are identically 560dd287796SAndrew Morton * implemented... 561dd287796SAndrew Morton */ 562dd287796SAndrew Morton static void do_oops_enter_exit(void) 563dd287796SAndrew Morton { 564dd287796SAndrew Morton unsigned long flags; 565dd287796SAndrew Morton static int spin_counter; 566dd287796SAndrew Morton 567dd287796SAndrew Morton if (!pause_on_oops) 568dd287796SAndrew Morton return; 569dd287796SAndrew Morton 570dd287796SAndrew Morton spin_lock_irqsave(&pause_on_oops_lock, flags); 571dd287796SAndrew Morton if (pause_on_oops_flag == 0) { 572dd287796SAndrew Morton /* This CPU may now print the oops message */ 573dd287796SAndrew Morton pause_on_oops_flag = 1; 574dd287796SAndrew Morton } else { 575dd287796SAndrew Morton /* We need to stall this CPU */ 576dd287796SAndrew Morton if (!spin_counter) { 577dd287796SAndrew Morton /* This CPU gets to do the counting */ 578dd287796SAndrew Morton spin_counter = pause_on_oops; 579dd287796SAndrew Morton do { 580dd287796SAndrew Morton spin_unlock(&pause_on_oops_lock); 581dd287796SAndrew Morton spin_msec(MSEC_PER_SEC); 582dd287796SAndrew Morton spin_lock(&pause_on_oops_lock); 583dd287796SAndrew Morton } while (--spin_counter); 584dd287796SAndrew Morton pause_on_oops_flag = 0; 585dd287796SAndrew Morton } else { 586dd287796SAndrew Morton /* This CPU waits for a different one */ 587dd287796SAndrew Morton while (spin_counter) { 588dd287796SAndrew Morton spin_unlock(&pause_on_oops_lock); 589dd287796SAndrew Morton spin_msec(1); 590dd287796SAndrew Morton spin_lock(&pause_on_oops_lock); 591dd287796SAndrew Morton } 592dd287796SAndrew Morton } 593dd287796SAndrew Morton } 594dd287796SAndrew Morton spin_unlock_irqrestore(&pause_on_oops_lock, flags); 595dd287796SAndrew Morton } 596dd287796SAndrew Morton 597dd287796SAndrew Morton /* 598c95dbf27SIngo Molnar * Return true if the calling CPU is allowed to print oops-related info. 599c95dbf27SIngo Molnar * This is a bit racy.. 600dd287796SAndrew Morton */ 60179076e12STiezhu Yang bool oops_may_print(void) 602dd287796SAndrew Morton { 603dd287796SAndrew Morton return pause_on_oops_flag == 0; 604dd287796SAndrew Morton } 605dd287796SAndrew Morton 606dd287796SAndrew Morton /* 607dd287796SAndrew Morton * Called when the architecture enters its oops handler, before it prints 608c95dbf27SIngo Molnar * anything. If this is the first CPU to oops, and it's oopsing the first 609c95dbf27SIngo Molnar * time then let it proceed. 610dd287796SAndrew Morton * 611c95dbf27SIngo Molnar * This is all enabled by the pause_on_oops kernel boot option. We do all 612c95dbf27SIngo Molnar * this to ensure that oopses don't scroll off the screen. It has the 613c95dbf27SIngo Molnar * side-effect of preventing later-oopsing CPUs from mucking up the display, 614c95dbf27SIngo Molnar * too. 615dd287796SAndrew Morton * 616c95dbf27SIngo Molnar * It turns out that the CPU which is allowed to print ends up pausing for 617c95dbf27SIngo Molnar * the right duration, whereas all the other CPUs pause for twice as long: 618c95dbf27SIngo Molnar * once in oops_enter(), once in oops_exit(). 619dd287796SAndrew Morton */ 620dd287796SAndrew Morton void oops_enter(void) 621dd287796SAndrew Morton { 622bdff7870SThomas Gleixner tracing_off(); 623c95dbf27SIngo Molnar /* can't trust the integrity of the kernel anymore: */ 624c95dbf27SIngo Molnar debug_locks_off(); 625dd287796SAndrew Morton do_oops_enter_exit(); 62660c958d8SGuilherme G. Piccoli 62760c958d8SGuilherme G. Piccoli if (sysctl_oops_all_cpu_backtrace) 62860c958d8SGuilherme G. Piccoli trigger_all_cpu_backtrace(); 629dd287796SAndrew Morton } 630dd287796SAndrew Morton 63163037f74SYue Hu static void print_oops_end_marker(void) 63271c33911SArjan van de Ven { 633e83a4472SSebastian Andrzej Siewior pr_warn("---[ end trace %016llx ]---\n", 0ULL); 63471c33911SArjan van de Ven } 63571c33911SArjan van de Ven 6362c3b20e9SArjan van de Ven /* 637dd287796SAndrew Morton * Called when the architecture exits its oops handler, after printing 638dd287796SAndrew Morton * everything. 639dd287796SAndrew Morton */ 640dd287796SAndrew Morton void oops_exit(void) 641dd287796SAndrew Morton { 642dd287796SAndrew Morton do_oops_enter_exit(); 64371c33911SArjan van de Ven print_oops_end_marker(); 644456b565cSSimon Kagstrom kmsg_dump(KMSG_DUMP_OOPS); 645dd287796SAndrew Morton } 6463162f751SArjan van de Ven 6472553b67aSJosh Poimboeuf struct warn_args { 6480f6f49a8SLinus Torvalds const char *fmt; 649a8f18b90SArjan van de Ven va_list args; 6500f6f49a8SLinus Torvalds }; 6510f6f49a8SLinus Torvalds 6522553b67aSJosh Poimboeuf void __warn(const char *file, int line, void *caller, unsigned taint, 6532553b67aSJosh Poimboeuf struct pt_regs *regs, struct warn_args *args) 6540f6f49a8SLinus Torvalds { 655de7edd31SSteven Rostedt (Red Hat) disable_trace_on_warning(); 656de7edd31SSteven Rostedt (Red Hat) 6572553b67aSJosh Poimboeuf if (file) 6582553b67aSJosh Poimboeuf pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n", 6592553b67aSJosh Poimboeuf raw_smp_processor_id(), current->pid, file, line, 6602553b67aSJosh Poimboeuf caller); 6612553b67aSJosh Poimboeuf else 6622553b67aSJosh Poimboeuf pr_warn("WARNING: CPU: %d PID: %d at %pS\n", 6632553b67aSJosh Poimboeuf raw_smp_processor_id(), current->pid, caller); 66474853dbaSArjan van de Ven 6650f6f49a8SLinus Torvalds if (args) 6660f6f49a8SLinus Torvalds vprintk(args->fmt, args->args); 667a8f18b90SArjan van de Ven 6683f388f28SAlexey Kardashevskiy print_modules(); 6693f388f28SAlexey Kardashevskiy 6703f388f28SAlexey Kardashevskiy if (regs) 6713f388f28SAlexey Kardashevskiy show_regs(regs); 6723f388f28SAlexey Kardashevskiy 67379cc1ba7SKees Cook check_panic_on_warn("kernel"); 6749e3961a0SPrarit Bhargava 6752f31ad64SChristophe Leroy if (!regs) 676a8f18b90SArjan van de Ven dump_stack(); 6772553b67aSJosh Poimboeuf 6784c281074SSteven Rostedt (VMware) print_irqtrace_events(current); 6794c281074SSteven Rostedt (VMware) 680a8f18b90SArjan van de Ven print_oops_end_marker(); 68123b36fecSMarco Elver trace_error_report_end(ERROR_DETECTOR_WARN, (unsigned long)caller); 6822553b67aSJosh Poimboeuf 683373d4d09SRusty Russell /* Just a warning, don't kill lockdep. */ 684373d4d09SRusty Russell add_taint(taint, LOCKDEP_STILL_OK); 685a8f18b90SArjan van de Ven } 6860f6f49a8SLinus Torvalds 687525bb813SArnd Bergmann #ifdef CONFIG_BUG 6882da1ead4SKees Cook #ifndef __WARN_FLAGS 689ee871133SKees Cook void warn_slowpath_fmt(const char *file, int line, unsigned taint, 690ee871133SKees Cook const char *fmt, ...) 691b2be0527SBen Hutchings { 6925a5d7e9bSPeter Zijlstra bool rcu = warn_rcu_enter(); 6932553b67aSJosh Poimboeuf struct warn_args args; 694b2be0527SBen Hutchings 695f2f84b05SKees Cook pr_warn(CUT_HERE); 696d38aba49SKees Cook 697d38aba49SKees Cook if (!fmt) { 698f2f84b05SKees Cook __warn(file, line, __builtin_return_address(0), taint, 699f2f84b05SKees Cook NULL, NULL); 700*cccd3281SLukas Wunner warn_rcu_exit(rcu); 701f2f84b05SKees Cook return; 702f2f84b05SKees Cook } 703f2f84b05SKees Cook 704b2be0527SBen Hutchings args.fmt = fmt; 705b2be0527SBen Hutchings va_start(args.args, fmt); 7062553b67aSJosh Poimboeuf __warn(file, line, __builtin_return_address(0), taint, NULL, &args); 707b2be0527SBen Hutchings va_end(args.args); 7085a5d7e9bSPeter Zijlstra warn_rcu_exit(rcu); 709b2be0527SBen Hutchings } 710ee871133SKees Cook EXPORT_SYMBOL(warn_slowpath_fmt); 711a7bed27aSKees Cook #else 712a7bed27aSKees Cook void __warn_printk(const char *fmt, ...) 713a7bed27aSKees Cook { 7145a5d7e9bSPeter Zijlstra bool rcu = warn_rcu_enter(); 715a7bed27aSKees Cook va_list args; 716a7bed27aSKees Cook 717a7bed27aSKees Cook pr_warn(CUT_HERE); 718a7bed27aSKees Cook 719a7bed27aSKees Cook va_start(args, fmt); 720a7bed27aSKees Cook vprintk(fmt, args); 721a7bed27aSKees Cook va_end(args); 7225a5d7e9bSPeter Zijlstra warn_rcu_exit(rcu); 723a7bed27aSKees Cook } 724a7bed27aSKees Cook EXPORT_SYMBOL(__warn_printk); 72579b4cc5eSArjan van de Ven #endif 72679b4cc5eSArjan van de Ven 727b1fca27dSAndi Kleen /* Support resetting WARN*_ONCE state */ 728b1fca27dSAndi Kleen 729b1fca27dSAndi Kleen static int clear_warn_once_set(void *data, u64 val) 730b1fca27dSAndi Kleen { 731aaf5dcfbSAndi Kleen generic_bug_clear_once(); 732b1fca27dSAndi Kleen memset(__start_once, 0, __end_once - __start_once); 733b1fca27dSAndi Kleen return 0; 734b1fca27dSAndi Kleen } 735b1fca27dSAndi Kleen 7364169680eSYueHaibing DEFINE_DEBUGFS_ATTRIBUTE(clear_warn_once_fops, NULL, clear_warn_once_set, 737b1fca27dSAndi Kleen "%lld\n"); 738b1fca27dSAndi Kleen 739b1fca27dSAndi Kleen static __init int register_warn_debugfs(void) 740b1fca27dSAndi Kleen { 741b1fca27dSAndi Kleen /* Don't care about failure */ 7424169680eSYueHaibing debugfs_create_file_unsafe("clear_warn_once", 0200, NULL, NULL, 7434169680eSYueHaibing &clear_warn_once_fops); 744b1fca27dSAndi Kleen return 0; 745b1fca27dSAndi Kleen } 746b1fca27dSAndi Kleen 747b1fca27dSAndi Kleen device_initcall(register_warn_debugfs); 748b1fca27dSAndi Kleen #endif 749b1fca27dSAndi Kleen 750050e9baaSLinus Torvalds #ifdef CONFIG_STACKPROTECTOR 75154371a43SArjan van de Ven 7523162f751SArjan van de Ven /* 7533162f751SArjan van de Ven * Called when gcc's -fstack-protector feature is used, and 7543162f751SArjan van de Ven * gcc detects corruption of the on-stack canary value 7553162f751SArjan van de Ven */ 7565916d5f9SThomas Gleixner __visible noinstr void __stack_chk_fail(void) 7573162f751SArjan van de Ven { 7585916d5f9SThomas Gleixner instrumentation_begin(); 75995c4fb78SBorislav Petkov panic("stack-protector: Kernel stack is corrupted in: %pB", 760517a92c4SIngo Molnar __builtin_return_address(0)); 7615916d5f9SThomas Gleixner instrumentation_end(); 7623162f751SArjan van de Ven } 7633162f751SArjan van de Ven EXPORT_SYMBOL(__stack_chk_fail); 76454371a43SArjan van de Ven 7653162f751SArjan van de Ven #endif 766f44dd164SRusty Russell 767f44dd164SRusty Russell core_param(panic, panic_timeout, int, 0644); 768d999bd93SFeng Tang core_param(panic_print, panic_print, ulong, 0644); 769f44dd164SRusty Russell core_param(pause_on_oops, pause_on_oops, int, 0644); 7709e3961a0SPrarit Bhargava core_param(panic_on_warn, panic_on_warn, int, 0644); 771b26e27ddSHidehiro Kawai core_param(crash_kexec_post_notifiers, crash_kexec_post_notifiers, bool, 0644); 772f06e5153SMasami Hiramatsu 773d404ab0aSOlaf Hering static int __init oops_setup(char *s) 774d404ab0aSOlaf Hering { 775d404ab0aSOlaf Hering if (!s) 776d404ab0aSOlaf Hering return -EINVAL; 777d404ab0aSOlaf Hering if (!strcmp(s, "panic")) 778d404ab0aSOlaf Hering panic_on_oops = 1; 779d404ab0aSOlaf Hering return 0; 780d404ab0aSOlaf Hering } 781d404ab0aSOlaf Hering early_param("oops", oops_setup); 782db38d5c1SRafael Aquini 783db38d5c1SRafael Aquini static int __init panic_on_taint_setup(char *s) 784db38d5c1SRafael Aquini { 785db38d5c1SRafael Aquini char *taint_str; 786db38d5c1SRafael Aquini 787db38d5c1SRafael Aquini if (!s) 788db38d5c1SRafael Aquini return -EINVAL; 789db38d5c1SRafael Aquini 790db38d5c1SRafael Aquini taint_str = strsep(&s, ","); 791db38d5c1SRafael Aquini if (kstrtoul(taint_str, 16, &panic_on_taint)) 792db38d5c1SRafael Aquini return -EINVAL; 793db38d5c1SRafael Aquini 794db38d5c1SRafael Aquini /* make sure panic_on_taint doesn't hold out-of-range TAINT flags */ 795db38d5c1SRafael Aquini panic_on_taint &= TAINT_FLAGS_MAX; 796db38d5c1SRafael Aquini 797db38d5c1SRafael Aquini if (!panic_on_taint) 798db38d5c1SRafael Aquini return -EINVAL; 799db38d5c1SRafael Aquini 800db38d5c1SRafael Aquini if (s && !strcmp(s, "nousertaint")) 801db38d5c1SRafael Aquini panic_on_taint_nousertaint = true; 802db38d5c1SRafael Aquini 8035d5dd3e4SAndy Shevchenko pr_info("panic_on_taint: bitmask=0x%lx nousertaint_mode=%s\n", 8045d5dd3e4SAndy Shevchenko panic_on_taint, str_enabled_disabled(panic_on_taint_nousertaint)); 805db38d5c1SRafael Aquini 806db38d5c1SRafael Aquini return 0; 807db38d5c1SRafael Aquini } 808db38d5c1SRafael Aquini early_param("panic_on_taint", panic_on_taint_setup); 809