xref: /linux-6.15/kernel/panic.c (revision 2852ca7f)
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>
28c95dbf27SIngo Molnar #include <linux/sysrq.h>
29c95dbf27SIngo Molnar #include <linux/init.h>
30c95dbf27SIngo Molnar #include <linux/nmi.h>
3108d78658SVitaly Kuznetsov #include <linux/console.h>
322553b67aSJosh Poimboeuf #include <linux/bug.h>
337a46ec0eSKees Cook #include <linux/ratelimit.h>
34b1fca27dSAndi Kleen #include <linux/debugfs.h>
3523b36fecSMarco Elver #include <trace/events/error_report.h>
36b1fca27dSAndi Kleen #include <asm/sections.h>
371da177e4SLinus Torvalds 
38c7ff0d9cSTAMUKI Shoichi #define PANIC_TIMER_STEP 100
39c7ff0d9cSTAMUKI Shoichi #define PANIC_BLINK_SPD 18
40c7ff0d9cSTAMUKI Shoichi 
4160c958d8SGuilherme G. Piccoli #ifdef CONFIG_SMP
4260c958d8SGuilherme G. Piccoli /*
4360c958d8SGuilherme G. Piccoli  * Should we dump all CPUs backtraces in an oops event?
4460c958d8SGuilherme G. Piccoli  * Defaults to 0, can be changed via sysctl.
4560c958d8SGuilherme G. Piccoli  */
469df91869Stangmeng static unsigned int __read_mostly sysctl_oops_all_cpu_backtrace;
479df91869Stangmeng #else
489df91869Stangmeng #define sysctl_oops_all_cpu_backtrace 0
4960c958d8SGuilherme G. Piccoli #endif /* CONFIG_SMP */
5060c958d8SGuilherme G. Piccoli 
512a01bb38SKyle McMartin int panic_on_oops = CONFIG_PANIC_ON_OOPS_VALUE;
52bc4f2f54SKees Cook static unsigned long tainted_mask =
53595b893eSKees Cook 	IS_ENABLED(CONFIG_RANDSTRUCT) ? (1 << TAINT_RANDSTRUCT) : 0;
54dd287796SAndrew Morton static int pause_on_oops;
55dd287796SAndrew Morton static int pause_on_oops_flag;
56dd287796SAndrew Morton static DEFINE_SPINLOCK(pause_on_oops_lock);
575375b708SHATAYAMA Daisuke bool crash_kexec_post_notifiers;
589e3961a0SPrarit Bhargava int panic_on_warn __read_mostly;
59db38d5c1SRafael Aquini unsigned long panic_on_taint;
60db38d5c1SRafael Aquini bool panic_on_taint_nousertaint = false;
611da177e4SLinus Torvalds 
625800dc3cSJason Baron int panic_timeout = CONFIG_PANIC_TIMEOUT;
6381e88fdcSHuang Ying EXPORT_SYMBOL_GPL(panic_timeout);
641da177e4SLinus Torvalds 
65d999bd93SFeng Tang #define PANIC_PRINT_TASK_INFO		0x00000001
66d999bd93SFeng Tang #define PANIC_PRINT_MEM_INFO		0x00000002
67d999bd93SFeng Tang #define PANIC_PRINT_TIMER_INFO		0x00000004
68d999bd93SFeng Tang #define PANIC_PRINT_LOCK_INFO		0x00000008
69d999bd93SFeng Tang #define PANIC_PRINT_FTRACE_INFO		0x00000010
70de6da1e8SFeng Tang #define PANIC_PRINT_ALL_PRINTK_MSG	0x00000020
718d470a45SGuilherme G. Piccoli #define PANIC_PRINT_ALL_CPU_BT		0x00000040
7281c9d43fSFeng Tang unsigned long panic_print;
73d999bd93SFeng Tang 
74e041c683SAlan Stern ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
751da177e4SLinus Torvalds 
761da177e4SLinus Torvalds EXPORT_SYMBOL(panic_notifier_list);
771da177e4SLinus Torvalds 
789df91869Stangmeng #if defined(CONFIG_SMP) && defined(CONFIG_SYSCTL)
799df91869Stangmeng static struct ctl_table kern_panic_table[] = {
809df91869Stangmeng 	{
819df91869Stangmeng 		.procname       = "oops_all_cpu_backtrace",
829df91869Stangmeng 		.data           = &sysctl_oops_all_cpu_backtrace,
839df91869Stangmeng 		.maxlen         = sizeof(int),
849df91869Stangmeng 		.mode           = 0644,
859df91869Stangmeng 		.proc_handler   = proc_dointvec_minmax,
869df91869Stangmeng 		.extra1         = SYSCTL_ZERO,
879df91869Stangmeng 		.extra2         = SYSCTL_ONE,
889df91869Stangmeng 	},
899df91869Stangmeng 	{ }
909df91869Stangmeng };
919df91869Stangmeng 
929df91869Stangmeng static __init int kernel_panic_sysctls_init(void)
939df91869Stangmeng {
949df91869Stangmeng 	register_sysctl_init("kernel", kern_panic_table);
959df91869Stangmeng 	return 0;
969df91869Stangmeng }
979df91869Stangmeng late_initcall(kernel_panic_sysctls_init);
989df91869Stangmeng #endif
999df91869Stangmeng 
100c7ff0d9cSTAMUKI Shoichi static long no_blink(int state)
1018aeee85aSAnton Blanchard {
102c7ff0d9cSTAMUKI Shoichi 	return 0;
103c7ff0d9cSTAMUKI Shoichi }
1048aeee85aSAnton Blanchard 
105c7ff0d9cSTAMUKI Shoichi /* Returns how long it waited in ms */
106c7ff0d9cSTAMUKI Shoichi long (*panic_blink)(int state);
107c7ff0d9cSTAMUKI Shoichi EXPORT_SYMBOL(panic_blink);
1088aeee85aSAnton Blanchard 
10993e13a36SMichael Holzheu /*
11093e13a36SMichael Holzheu  * Stop ourself in panic -- architecture code may override this
11193e13a36SMichael Holzheu  */
11293e13a36SMichael Holzheu void __weak panic_smp_self_stop(void)
11393e13a36SMichael Holzheu {
11493e13a36SMichael Holzheu 	while (1)
11593e13a36SMichael Holzheu 		cpu_relax();
11693e13a36SMichael Holzheu }
11793e13a36SMichael Holzheu 
11858c5661fSHidehiro Kawai /*
11958c5661fSHidehiro Kawai  * Stop ourselves in NMI context if another CPU has already panicked. Arch code
12058c5661fSHidehiro Kawai  * may override this to prepare for crash dumping, e.g. save regs info.
12158c5661fSHidehiro Kawai  */
12258c5661fSHidehiro Kawai void __weak nmi_panic_self_stop(struct pt_regs *regs)
12358c5661fSHidehiro Kawai {
12458c5661fSHidehiro Kawai 	panic_smp_self_stop();
12558c5661fSHidehiro Kawai }
12658c5661fSHidehiro Kawai 
1270ee59413SHidehiro Kawai /*
1280ee59413SHidehiro Kawai  * Stop other CPUs in panic.  Architecture dependent code may override this
1290ee59413SHidehiro Kawai  * with more suitable version.  For example, if the architecture supports
1300ee59413SHidehiro Kawai  * crash dump, it should save registers of each stopped CPU and disable
1310ee59413SHidehiro Kawai  * per-CPU features such as virtualization extensions.
1320ee59413SHidehiro Kawai  */
1330ee59413SHidehiro Kawai void __weak crash_smp_send_stop(void)
1340ee59413SHidehiro Kawai {
1350ee59413SHidehiro Kawai 	static int cpus_stopped;
1360ee59413SHidehiro Kawai 
1370ee59413SHidehiro Kawai 	/*
1380ee59413SHidehiro Kawai 	 * This function can be called twice in panic path, but obviously
1390ee59413SHidehiro Kawai 	 * we execute this only once.
1400ee59413SHidehiro Kawai 	 */
1410ee59413SHidehiro Kawai 	if (cpus_stopped)
1420ee59413SHidehiro Kawai 		return;
1430ee59413SHidehiro Kawai 
1440ee59413SHidehiro Kawai 	/*
1450ee59413SHidehiro Kawai 	 * Note smp_send_stop is the usual smp shutdown function, which
1460ee59413SHidehiro Kawai 	 * unfortunately means it may not be hardened to work in a panic
1470ee59413SHidehiro Kawai 	 * situation.
1480ee59413SHidehiro Kawai 	 */
1490ee59413SHidehiro Kawai 	smp_send_stop();
1500ee59413SHidehiro Kawai 	cpus_stopped = 1;
1510ee59413SHidehiro Kawai }
1520ee59413SHidehiro Kawai 
1531717f209SHidehiro Kawai atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID);
1541717f209SHidehiro Kawai 
155ebc41f20SHidehiro Kawai /*
156ebc41f20SHidehiro Kawai  * A variant of panic() called from NMI context. We return if we've already
157ebc41f20SHidehiro Kawai  * panicked on this CPU. If another CPU already panicked, loop in
158ebc41f20SHidehiro Kawai  * nmi_panic_self_stop() which can provide architecture dependent code such
159ebc41f20SHidehiro Kawai  * as saving register state for crash dump.
160ebc41f20SHidehiro Kawai  */
161ebc41f20SHidehiro Kawai void nmi_panic(struct pt_regs *regs, const char *msg)
162ebc41f20SHidehiro Kawai {
163ebc41f20SHidehiro Kawai 	int old_cpu, cpu;
164ebc41f20SHidehiro Kawai 
165ebc41f20SHidehiro Kawai 	cpu = raw_smp_processor_id();
166ebc41f20SHidehiro Kawai 	old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, cpu);
167ebc41f20SHidehiro Kawai 
168ebc41f20SHidehiro Kawai 	if (old_cpu == PANIC_CPU_INVALID)
169ebc41f20SHidehiro Kawai 		panic("%s", msg);
170ebc41f20SHidehiro Kawai 	else if (old_cpu != cpu)
171ebc41f20SHidehiro Kawai 		nmi_panic_self_stop(regs);
172ebc41f20SHidehiro Kawai }
173ebc41f20SHidehiro Kawai EXPORT_SYMBOL(nmi_panic);
174ebc41f20SHidehiro Kawai 
175f953f140SGuilherme G. Piccoli static void panic_print_sys_info(bool console_flush)
176d999bd93SFeng Tang {
177f953f140SGuilherme G. Piccoli 	if (console_flush) {
178de6da1e8SFeng Tang 		if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG)
179de6da1e8SFeng Tang 			console_flush_on_panic(CONSOLE_REPLAY_ALL);
180f953f140SGuilherme G. Piccoli 		return;
181f953f140SGuilherme G. Piccoli 	}
182de6da1e8SFeng Tang 
1838d470a45SGuilherme G. Piccoli 	if (panic_print & PANIC_PRINT_ALL_CPU_BT)
1848d470a45SGuilherme G. Piccoli 		trigger_all_cpu_backtrace();
1858d470a45SGuilherme G. Piccoli 
186d999bd93SFeng Tang 	if (panic_print & PANIC_PRINT_TASK_INFO)
187d999bd93SFeng Tang 		show_state();
188d999bd93SFeng Tang 
189d999bd93SFeng Tang 	if (panic_print & PANIC_PRINT_MEM_INFO)
190d999bd93SFeng Tang 		show_mem(0, NULL);
191d999bd93SFeng Tang 
192d999bd93SFeng Tang 	if (panic_print & PANIC_PRINT_TIMER_INFO)
193d999bd93SFeng Tang 		sysrq_timer_list_show();
194d999bd93SFeng Tang 
195d999bd93SFeng Tang 	if (panic_print & PANIC_PRINT_LOCK_INFO)
196d999bd93SFeng Tang 		debug_show_all_locks();
197d999bd93SFeng Tang 
198d999bd93SFeng Tang 	if (panic_print & PANIC_PRINT_FTRACE_INFO)
199d999bd93SFeng Tang 		ftrace_dump(DUMP_ALL);
200d999bd93SFeng Tang }
201d999bd93SFeng Tang 
2021da177e4SLinus Torvalds /**
2031da177e4SLinus Torvalds  *	panic - halt the system
2041da177e4SLinus Torvalds  *	@fmt: The text string to print
2051da177e4SLinus Torvalds  *
2061da177e4SLinus Torvalds  *	Display a message, then perform cleanups.
2071da177e4SLinus Torvalds  *
2081da177e4SLinus Torvalds  *	This function never returns.
2091da177e4SLinus Torvalds  */
2109402c95fSJoe Perches void panic(const char *fmt, ...)
2111da177e4SLinus Torvalds {
2121da177e4SLinus Torvalds 	static char buf[1024];
2131da177e4SLinus Torvalds 	va_list args;
214b49dec1cSBorislav Petkov 	long i, i_next = 0, len;
215c7ff0d9cSTAMUKI Shoichi 	int state = 0;
2161717f209SHidehiro Kawai 	int old_cpu, this_cpu;
217b26e27ddSHidehiro Kawai 	bool _crash_kexec_post_notifiers = crash_kexec_post_notifiers;
2181da177e4SLinus Torvalds 
2191a2383e8STiezhu Yang 	if (panic_on_warn) {
2201a2383e8STiezhu Yang 		/*
2211a2383e8STiezhu Yang 		 * This thread may hit another WARN() in the panic path.
2221a2383e8STiezhu Yang 		 * Resetting this prevents additional WARN() from panicking the
2231a2383e8STiezhu Yang 		 * system on this thread.  Other threads are blocked by the
2241a2383e8STiezhu Yang 		 * panic_mutex in panic().
2251a2383e8STiezhu Yang 		 */
2261a2383e8STiezhu Yang 		panic_on_warn = 0;
2271a2383e8STiezhu Yang 	}
2281a2383e8STiezhu Yang 
229dc009d92SEric W. Biederman 	/*
230190320c3SVikram Mulukutla 	 * Disable local interrupts. This will prevent panic_smp_self_stop
231190320c3SVikram Mulukutla 	 * from deadlocking the first cpu that invokes the panic, since
232190320c3SVikram Mulukutla 	 * there is nothing to prevent an interrupt handler (that runs
2331717f209SHidehiro Kawai 	 * after setting panic_cpu) from invoking panic() again.
234190320c3SVikram Mulukutla 	 */
235190320c3SVikram Mulukutla 	local_irq_disable();
23620bb759aSWill Deacon 	preempt_disable_notrace();
237190320c3SVikram Mulukutla 
238190320c3SVikram Mulukutla 	/*
239c95dbf27SIngo Molnar 	 * It's possible to come here directly from a panic-assertion and
240c95dbf27SIngo Molnar 	 * not have preempt disabled. Some functions called from here want
241dc009d92SEric W. Biederman 	 * preempt to be disabled. No point enabling it later though...
24293e13a36SMichael Holzheu 	 *
24393e13a36SMichael Holzheu 	 * Only one CPU is allowed to execute the panic code from here. For
24493e13a36SMichael Holzheu 	 * multiple parallel invocations of panic, all other CPUs either
24593e13a36SMichael Holzheu 	 * stop themself or will wait until they are stopped by the 1st CPU
24693e13a36SMichael Holzheu 	 * with smp_send_stop().
2471717f209SHidehiro Kawai 	 *
2481717f209SHidehiro Kawai 	 * `old_cpu == PANIC_CPU_INVALID' means this is the 1st CPU which
2491717f209SHidehiro Kawai 	 * comes here, so go ahead.
2501717f209SHidehiro Kawai 	 * `old_cpu == this_cpu' means we came from nmi_panic() which sets
2511717f209SHidehiro Kawai 	 * panic_cpu to this CPU.  In this case, this is also the 1st CPU.
252dc009d92SEric W. Biederman 	 */
2531717f209SHidehiro Kawai 	this_cpu = raw_smp_processor_id();
2541717f209SHidehiro Kawai 	old_cpu  = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, this_cpu);
2551717f209SHidehiro Kawai 
2561717f209SHidehiro Kawai 	if (old_cpu != PANIC_CPU_INVALID && old_cpu != this_cpu)
25793e13a36SMichael Holzheu 		panic_smp_self_stop();
258dc009d92SEric W. Biederman 
2595b530fc1SAnton Blanchard 	console_verbose();
2601da177e4SLinus Torvalds 	bust_spinlocks(1);
2611da177e4SLinus Torvalds 	va_start(args, fmt);
262b49dec1cSBorislav Petkov 	len = vscnprintf(buf, sizeof(buf), fmt, args);
2631da177e4SLinus Torvalds 	va_end(args);
264b49dec1cSBorislav Petkov 
265b49dec1cSBorislav Petkov 	if (len && buf[len - 1] == '\n')
266b49dec1cSBorislav Petkov 		buf[len - 1] = '\0';
267b49dec1cSBorislav Petkov 
268d7c0847fSFabian Frederick 	pr_emerg("Kernel panic - not syncing: %s\n", buf);
2695cb27301SIngo Molnar #ifdef CONFIG_DEBUG_BUGVERBOSE
2706e6f0a1fSAndi Kleen 	/*
2716e6f0a1fSAndi Kleen 	 * Avoid nested stack-dumping if a panic occurs during oops processing
2726e6f0a1fSAndi Kleen 	 */
273026ee1f6SJason Wessel 	if (!test_taint(TAINT_DIE) && oops_in_progress <= 1)
2745cb27301SIngo Molnar 		dump_stack();
2755cb27301SIngo Molnar #endif
2761da177e4SLinus Torvalds 
277dc009d92SEric W. Biederman 	/*
2787d92bda2SDouglas Anderson 	 * If kgdb is enabled, give it a chance to run before we stop all
2797d92bda2SDouglas Anderson 	 * the other CPUs or else we won't be able to debug processes left
2807d92bda2SDouglas Anderson 	 * running on them.
2817d92bda2SDouglas Anderson 	 */
2827d92bda2SDouglas Anderson 	kgdb_panic(buf);
2837d92bda2SDouglas Anderson 
2847d92bda2SDouglas Anderson 	/*
285dc009d92SEric W. Biederman 	 * If we have crashed and we have a crash kernel loaded let it handle
286dc009d92SEric W. Biederman 	 * everything else.
287f06e5153SMasami Hiramatsu 	 * If we want to run this after calling panic_notifiers, pass
288f06e5153SMasami Hiramatsu 	 * the "crash_kexec_post_notifiers" option to the kernel.
2897bbee5caSHidehiro Kawai 	 *
2907bbee5caSHidehiro Kawai 	 * Bypass the panic_cpu check and call __crash_kexec directly.
291dc009d92SEric W. Biederman 	 */
292b26e27ddSHidehiro Kawai 	if (!_crash_kexec_post_notifiers) {
2937bbee5caSHidehiro Kawai 		__crash_kexec(NULL);
294dc009d92SEric W. Biederman 
295dc009d92SEric W. Biederman 		/*
296dc009d92SEric W. Biederman 		 * Note smp_send_stop is the usual smp shutdown function, which
2970ee59413SHidehiro Kawai 		 * unfortunately means it may not be hardened to work in a
2980ee59413SHidehiro Kawai 		 * panic situation.
299dc009d92SEric W. Biederman 		 */
3001da177e4SLinus Torvalds 		smp_send_stop();
3010ee59413SHidehiro Kawai 	} else {
3020ee59413SHidehiro Kawai 		/*
3030ee59413SHidehiro Kawai 		 * If we want to do crash dump after notifier calls and
3040ee59413SHidehiro Kawai 		 * kmsg_dump, we will need architecture dependent extra
3050ee59413SHidehiro Kawai 		 * works in addition to stopping other CPUs.
3060ee59413SHidehiro Kawai 		 */
3070ee59413SHidehiro Kawai 		crash_smp_send_stop();
3080ee59413SHidehiro Kawai 	}
3091da177e4SLinus Torvalds 
3106723734cSKees Cook 	/*
3116723734cSKees Cook 	 * Run any panic handlers, including those that might need to
3126723734cSKees Cook 	 * add information to the kmsg dump output.
3136723734cSKees Cook 	 */
314e041c683SAlan Stern 	atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
3151da177e4SLinus Torvalds 
316f953f140SGuilherme G. Piccoli 	panic_print_sys_info(false);
317f953f140SGuilherme G. Piccoli 
3186723734cSKees Cook 	kmsg_dump(KMSG_DUMP_PANIC);
3196723734cSKees Cook 
320f06e5153SMasami Hiramatsu 	/*
321f06e5153SMasami Hiramatsu 	 * If you doubt kdump always works fine in any situation,
322f06e5153SMasami Hiramatsu 	 * "crash_kexec_post_notifiers" offers you a chance to run
323f06e5153SMasami Hiramatsu 	 * panic_notifiers and dumping kmsg before kdump.
324f06e5153SMasami Hiramatsu 	 * Note: since some panic_notifiers can make crashed kernel
325f06e5153SMasami Hiramatsu 	 * more unstable, it can increase risks of the kdump failure too.
3267bbee5caSHidehiro Kawai 	 *
3277bbee5caSHidehiro Kawai 	 * Bypass the panic_cpu check and call __crash_kexec directly.
328f06e5153SMasami Hiramatsu 	 */
329b26e27ddSHidehiro Kawai 	if (_crash_kexec_post_notifiers)
3307bbee5caSHidehiro Kawai 		__crash_kexec(NULL);
331f06e5153SMasami Hiramatsu 
332c7c3f05eSSergey Senozhatsky #ifdef CONFIG_VT
333c7c3f05eSSergey Senozhatsky 	unblank_screen();
334c7c3f05eSSergey Senozhatsky #endif
335c7c3f05eSSergey Senozhatsky 	console_unblank();
336d014e889SAaro Koskinen 
33708d78658SVitaly Kuznetsov 	/*
33808d78658SVitaly Kuznetsov 	 * We may have ended up stopping the CPU holding the lock (in
33908d78658SVitaly Kuznetsov 	 * smp_send_stop()) while still having some valuable data in the console
34008d78658SVitaly Kuznetsov 	 * buffer.  Try to acquire the lock then release it regardless of the
3417625b3a0SVitaly Kuznetsov 	 * result.  The release will also print the buffers out.  Locks debug
3427625b3a0SVitaly Kuznetsov 	 * should be disabled to avoid reporting bad unlock balance when
3437625b3a0SVitaly Kuznetsov 	 * panic() is not being callled from OOPS.
34408d78658SVitaly Kuznetsov 	 */
3457625b3a0SVitaly Kuznetsov 	debug_locks_off();
346de6da1e8SFeng Tang 	console_flush_on_panic(CONSOLE_FLUSH_PENDING);
34708d78658SVitaly Kuznetsov 
348f953f140SGuilherme G. Piccoli 	panic_print_sys_info(true);
349d999bd93SFeng Tang 
350c7ff0d9cSTAMUKI Shoichi 	if (!panic_blink)
351c7ff0d9cSTAMUKI Shoichi 		panic_blink = no_blink;
352c7ff0d9cSTAMUKI Shoichi 
353dc009d92SEric W. Biederman 	if (panic_timeout > 0) {
3541da177e4SLinus Torvalds 		/*
3551da177e4SLinus Torvalds 		 * Delay timeout seconds before rebooting the machine.
356c95dbf27SIngo Molnar 		 * We can't use the "normal" timers since we just panicked.
3571da177e4SLinus Torvalds 		 */
358ff7a28a0SJiri Slaby 		pr_emerg("Rebooting in %d seconds..\n", panic_timeout);
359c95dbf27SIngo Molnar 
360c7ff0d9cSTAMUKI Shoichi 		for (i = 0; i < panic_timeout * 1000; i += PANIC_TIMER_STEP) {
3611da177e4SLinus Torvalds 			touch_nmi_watchdog();
362c7ff0d9cSTAMUKI Shoichi 			if (i >= i_next) {
363c7ff0d9cSTAMUKI Shoichi 				i += panic_blink(state ^= 1);
364c7ff0d9cSTAMUKI Shoichi 				i_next = i + 3600 / PANIC_BLINK_SPD;
365c7ff0d9cSTAMUKI Shoichi 			}
366c7ff0d9cSTAMUKI Shoichi 			mdelay(PANIC_TIMER_STEP);
3671da177e4SLinus Torvalds 		}
3684302fbc8SHugh Dickins 	}
3694302fbc8SHugh Dickins 	if (panic_timeout != 0) {
370c95dbf27SIngo Molnar 		/*
371c95dbf27SIngo Molnar 		 * This will not be a clean reboot, with everything
3722f048ea8SEric W. Biederman 		 * shutting down.  But if there is a chance of
3732f048ea8SEric W. Biederman 		 * rebooting the system it will be rebooted.
3741da177e4SLinus Torvalds 		 */
375b287a25aSAaro Koskinen 		if (panic_reboot_mode != REBOOT_UNDEFINED)
376b287a25aSAaro Koskinen 			reboot_mode = panic_reboot_mode;
3772f048ea8SEric W. Biederman 		emergency_restart();
3781da177e4SLinus Torvalds 	}
3791da177e4SLinus Torvalds #ifdef __sparc__
3801da177e4SLinus Torvalds 	{
3811da177e4SLinus Torvalds 		extern int stop_a_enabled;
382a271c241STom 'spot' Callaway 		/* Make sure the user can actually press Stop-A (L1-A) */
3831da177e4SLinus Torvalds 		stop_a_enabled = 1;
3847db60d05SVijay Kumar 		pr_emerg("Press Stop-A (L1-A) from sun keyboard or send break\n"
3857db60d05SVijay Kumar 			 "twice on console to return to the boot prom\n");
3861da177e4SLinus Torvalds 	}
3871da177e4SLinus Torvalds #endif
388347a8dc3SMartin Schwidefsky #if defined(CONFIG_S390)
38998587c2dSMartin Schwidefsky 	disabled_wait();
3901da177e4SLinus Torvalds #endif
3915ad75105SBorislav Petkov 	pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf);
392c39ea0b9SFeng Tang 
393c39ea0b9SFeng Tang 	/* Do not scroll important messages printed above */
394c39ea0b9SFeng Tang 	suppress_printk = 1;
3951da177e4SLinus Torvalds 	local_irq_enable();
396c7ff0d9cSTAMUKI Shoichi 	for (i = 0; ; i += PANIC_TIMER_STEP) {
397c22db941SJan Beulich 		touch_softlockup_watchdog();
398c7ff0d9cSTAMUKI Shoichi 		if (i >= i_next) {
399c7ff0d9cSTAMUKI Shoichi 			i += panic_blink(state ^= 1);
400c7ff0d9cSTAMUKI Shoichi 			i_next = i + 3600 / PANIC_BLINK_SPD;
401c7ff0d9cSTAMUKI Shoichi 		}
402c7ff0d9cSTAMUKI Shoichi 		mdelay(PANIC_TIMER_STEP);
4031da177e4SLinus Torvalds 	}
4041da177e4SLinus Torvalds }
4051da177e4SLinus Torvalds 
4061da177e4SLinus Torvalds EXPORT_SYMBOL(panic);
4071da177e4SLinus Torvalds 
4087fd8329bSPetr Mladek /*
4097fd8329bSPetr Mladek  * TAINT_FORCED_RMMOD could be a per-module flag but the module
4107fd8329bSPetr Mladek  * is being removed anyway.
4117fd8329bSPetr Mladek  */
4127fd8329bSPetr Mladek const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = {
41347d4b263SKees Cook 	[ TAINT_PROPRIETARY_MODULE ]	= { 'P', 'G', true },
41447d4b263SKees Cook 	[ TAINT_FORCED_MODULE ]		= { 'F', ' ', true },
41547d4b263SKees Cook 	[ TAINT_CPU_OUT_OF_SPEC ]	= { 'S', ' ', false },
41647d4b263SKees Cook 	[ TAINT_FORCED_RMMOD ]		= { 'R', ' ', false },
41747d4b263SKees Cook 	[ TAINT_MACHINE_CHECK ]		= { 'M', ' ', false },
41847d4b263SKees Cook 	[ TAINT_BAD_PAGE ]		= { 'B', ' ', false },
41947d4b263SKees Cook 	[ TAINT_USER ]			= { 'U', ' ', false },
42047d4b263SKees Cook 	[ TAINT_DIE ]			= { 'D', ' ', false },
42147d4b263SKees Cook 	[ TAINT_OVERRIDDEN_ACPI_TABLE ]	= { 'A', ' ', false },
42247d4b263SKees Cook 	[ TAINT_WARN ]			= { 'W', ' ', false },
42347d4b263SKees Cook 	[ TAINT_CRAP ]			= { 'C', ' ', true },
42447d4b263SKees Cook 	[ TAINT_FIRMWARE_WORKAROUND ]	= { 'I', ' ', false },
42547d4b263SKees Cook 	[ TAINT_OOT_MODULE ]		= { 'O', ' ', true },
42647d4b263SKees Cook 	[ TAINT_UNSIGNED_MODULE ]	= { 'E', ' ', true },
42747d4b263SKees Cook 	[ TAINT_SOFTLOCKUP ]		= { 'L', ' ', false },
42847d4b263SKees Cook 	[ TAINT_LIVEPATCH ]		= { 'K', ' ', true },
42947d4b263SKees Cook 	[ TAINT_AUX ]			= { 'X', ' ', true },
430bc4f2f54SKees Cook 	[ TAINT_RANDSTRUCT ]		= { 'T', ' ', true },
431*2852ca7fSDavid Gow 	[ TAINT_TEST ]			= { 'N', ' ', true },
43225ddbb18SAndi Kleen };
43325ddbb18SAndi Kleen 
4341da177e4SLinus Torvalds /**
4351da177e4SLinus Torvalds  * print_tainted - return a string to represent the kernel taint state.
4361da177e4SLinus Torvalds  *
43757043247SMauro Carvalho Chehab  * For individual taint flag meanings, see Documentation/admin-guide/sysctl/kernel.rst
4381da177e4SLinus Torvalds  *
4399c4560e5SKees Cook  * The string is overwritten by the next call to print_tainted(),
4409c4560e5SKees Cook  * but is always NULL terminated.
4411da177e4SLinus Torvalds  */
4421da177e4SLinus Torvalds const char *print_tainted(void)
4431da177e4SLinus Torvalds {
4447fd8329bSPetr Mladek 	static char buf[TAINT_FLAGS_COUNT + sizeof("Tainted: ")];
44525ddbb18SAndi Kleen 
44647d4b263SKees Cook 	BUILD_BUG_ON(ARRAY_SIZE(taint_flags) != TAINT_FLAGS_COUNT);
44747d4b263SKees Cook 
44825ddbb18SAndi Kleen 	if (tainted_mask) {
44925ddbb18SAndi Kleen 		char *s;
45025ddbb18SAndi Kleen 		int i;
45125ddbb18SAndi Kleen 
45225ddbb18SAndi Kleen 		s = buf + sprintf(buf, "Tainted: ");
4537fd8329bSPetr Mladek 		for (i = 0; i < TAINT_FLAGS_COUNT; i++) {
4547fd8329bSPetr Mladek 			const struct taint_flag *t = &taint_flags[i];
4557fd8329bSPetr Mladek 			*s++ = test_bit(i, &tainted_mask) ?
4565eb7c0d0SLarry Finger 					t->c_true : t->c_false;
4571da177e4SLinus Torvalds 		}
45825ddbb18SAndi Kleen 		*s = 0;
45925ddbb18SAndi Kleen 	} else
4601da177e4SLinus Torvalds 		snprintf(buf, sizeof(buf), "Not tainted");
461c95dbf27SIngo Molnar 
462c95dbf27SIngo Molnar 	return buf;
4631da177e4SLinus Torvalds }
4641da177e4SLinus Torvalds 
46525ddbb18SAndi Kleen int test_taint(unsigned flag)
46625ddbb18SAndi Kleen {
46725ddbb18SAndi Kleen 	return test_bit(flag, &tainted_mask);
46825ddbb18SAndi Kleen }
46925ddbb18SAndi Kleen EXPORT_SYMBOL(test_taint);
47025ddbb18SAndi Kleen 
47125ddbb18SAndi Kleen unsigned long get_taint(void)
47225ddbb18SAndi Kleen {
47325ddbb18SAndi Kleen 	return tainted_mask;
47425ddbb18SAndi Kleen }
47525ddbb18SAndi Kleen 
476373d4d09SRusty Russell /**
477373d4d09SRusty Russell  * add_taint: add a taint flag if not already set.
478373d4d09SRusty Russell  * @flag: one of the TAINT_* constants.
479373d4d09SRusty Russell  * @lockdep_ok: whether lock debugging is still OK.
480373d4d09SRusty Russell  *
481373d4d09SRusty Russell  * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for
482373d4d09SRusty Russell  * some notewortht-but-not-corrupting cases, it can be set to true.
4839eeba613SFrederic Weisbecker  */
484373d4d09SRusty Russell void add_taint(unsigned flag, enum lockdep_ok lockdep_ok)
485373d4d09SRusty Russell {
486373d4d09SRusty Russell 	if (lockdep_ok == LOCKDEP_NOW_UNRELIABLE && __debug_locks_off())
487d7c0847fSFabian Frederick 		pr_warn("Disabling lock debugging due to kernel taint\n");
4889eeba613SFrederic Weisbecker 
48925ddbb18SAndi Kleen 	set_bit(flag, &tainted_mask);
490db38d5c1SRafael Aquini 
491db38d5c1SRafael Aquini 	if (tainted_mask & panic_on_taint) {
492db38d5c1SRafael Aquini 		panic_on_taint = 0;
493db38d5c1SRafael Aquini 		panic("panic_on_taint set ...");
494db38d5c1SRafael Aquini 	}
4951da177e4SLinus Torvalds }
4961da177e4SLinus Torvalds EXPORT_SYMBOL(add_taint);
497dd287796SAndrew Morton 
498dd287796SAndrew Morton static void spin_msec(int msecs)
499dd287796SAndrew Morton {
500dd287796SAndrew Morton 	int i;
501dd287796SAndrew Morton 
502dd287796SAndrew Morton 	for (i = 0; i < msecs; i++) {
503dd287796SAndrew Morton 		touch_nmi_watchdog();
504dd287796SAndrew Morton 		mdelay(1);
505dd287796SAndrew Morton 	}
506dd287796SAndrew Morton }
507dd287796SAndrew Morton 
508dd287796SAndrew Morton /*
509dd287796SAndrew Morton  * It just happens that oops_enter() and oops_exit() are identically
510dd287796SAndrew Morton  * implemented...
511dd287796SAndrew Morton  */
512dd287796SAndrew Morton static void do_oops_enter_exit(void)
513dd287796SAndrew Morton {
514dd287796SAndrew Morton 	unsigned long flags;
515dd287796SAndrew Morton 	static int spin_counter;
516dd287796SAndrew Morton 
517dd287796SAndrew Morton 	if (!pause_on_oops)
518dd287796SAndrew Morton 		return;
519dd287796SAndrew Morton 
520dd287796SAndrew Morton 	spin_lock_irqsave(&pause_on_oops_lock, flags);
521dd287796SAndrew Morton 	if (pause_on_oops_flag == 0) {
522dd287796SAndrew Morton 		/* This CPU may now print the oops message */
523dd287796SAndrew Morton 		pause_on_oops_flag = 1;
524dd287796SAndrew Morton 	} else {
525dd287796SAndrew Morton 		/* We need to stall this CPU */
526dd287796SAndrew Morton 		if (!spin_counter) {
527dd287796SAndrew Morton 			/* This CPU gets to do the counting */
528dd287796SAndrew Morton 			spin_counter = pause_on_oops;
529dd287796SAndrew Morton 			do {
530dd287796SAndrew Morton 				spin_unlock(&pause_on_oops_lock);
531dd287796SAndrew Morton 				spin_msec(MSEC_PER_SEC);
532dd287796SAndrew Morton 				spin_lock(&pause_on_oops_lock);
533dd287796SAndrew Morton 			} while (--spin_counter);
534dd287796SAndrew Morton 			pause_on_oops_flag = 0;
535dd287796SAndrew Morton 		} else {
536dd287796SAndrew Morton 			/* This CPU waits for a different one */
537dd287796SAndrew Morton 			while (spin_counter) {
538dd287796SAndrew Morton 				spin_unlock(&pause_on_oops_lock);
539dd287796SAndrew Morton 				spin_msec(1);
540dd287796SAndrew Morton 				spin_lock(&pause_on_oops_lock);
541dd287796SAndrew Morton 			}
542dd287796SAndrew Morton 		}
543dd287796SAndrew Morton 	}
544dd287796SAndrew Morton 	spin_unlock_irqrestore(&pause_on_oops_lock, flags);
545dd287796SAndrew Morton }
546dd287796SAndrew Morton 
547dd287796SAndrew Morton /*
548c95dbf27SIngo Molnar  * Return true if the calling CPU is allowed to print oops-related info.
549c95dbf27SIngo Molnar  * This is a bit racy..
550dd287796SAndrew Morton  */
55179076e12STiezhu Yang bool oops_may_print(void)
552dd287796SAndrew Morton {
553dd287796SAndrew Morton 	return pause_on_oops_flag == 0;
554dd287796SAndrew Morton }
555dd287796SAndrew Morton 
556dd287796SAndrew Morton /*
557dd287796SAndrew Morton  * Called when the architecture enters its oops handler, before it prints
558c95dbf27SIngo Molnar  * anything.  If this is the first CPU to oops, and it's oopsing the first
559c95dbf27SIngo Molnar  * time then let it proceed.
560dd287796SAndrew Morton  *
561c95dbf27SIngo Molnar  * This is all enabled by the pause_on_oops kernel boot option.  We do all
562c95dbf27SIngo Molnar  * this to ensure that oopses don't scroll off the screen.  It has the
563c95dbf27SIngo Molnar  * side-effect of preventing later-oopsing CPUs from mucking up the display,
564c95dbf27SIngo Molnar  * too.
565dd287796SAndrew Morton  *
566c95dbf27SIngo Molnar  * It turns out that the CPU which is allowed to print ends up pausing for
567c95dbf27SIngo Molnar  * the right duration, whereas all the other CPUs pause for twice as long:
568c95dbf27SIngo Molnar  * once in oops_enter(), once in oops_exit().
569dd287796SAndrew Morton  */
570dd287796SAndrew Morton void oops_enter(void)
571dd287796SAndrew Morton {
572bdff7870SThomas Gleixner 	tracing_off();
573c95dbf27SIngo Molnar 	/* can't trust the integrity of the kernel anymore: */
574c95dbf27SIngo Molnar 	debug_locks_off();
575dd287796SAndrew Morton 	do_oops_enter_exit();
57660c958d8SGuilherme G. Piccoli 
57760c958d8SGuilherme G. Piccoli 	if (sysctl_oops_all_cpu_backtrace)
57860c958d8SGuilherme G. Piccoli 		trigger_all_cpu_backtrace();
579dd287796SAndrew Morton }
580dd287796SAndrew Morton 
58163037f74SYue Hu static void print_oops_end_marker(void)
58271c33911SArjan van de Ven {
583e83a4472SSebastian Andrzej Siewior 	pr_warn("---[ end trace %016llx ]---\n", 0ULL);
58471c33911SArjan van de Ven }
58571c33911SArjan van de Ven 
5862c3b20e9SArjan van de Ven /*
587dd287796SAndrew Morton  * Called when the architecture exits its oops handler, after printing
588dd287796SAndrew Morton  * everything.
589dd287796SAndrew Morton  */
590dd287796SAndrew Morton void oops_exit(void)
591dd287796SAndrew Morton {
592dd287796SAndrew Morton 	do_oops_enter_exit();
59371c33911SArjan van de Ven 	print_oops_end_marker();
594456b565cSSimon Kagstrom 	kmsg_dump(KMSG_DUMP_OOPS);
595dd287796SAndrew Morton }
5963162f751SArjan van de Ven 
5972553b67aSJosh Poimboeuf struct warn_args {
5980f6f49a8SLinus Torvalds 	const char *fmt;
599a8f18b90SArjan van de Ven 	va_list args;
6000f6f49a8SLinus Torvalds };
6010f6f49a8SLinus Torvalds 
6022553b67aSJosh Poimboeuf void __warn(const char *file, int line, void *caller, unsigned taint,
6032553b67aSJosh Poimboeuf 	    struct pt_regs *regs, struct warn_args *args)
6040f6f49a8SLinus Torvalds {
605de7edd31SSteven Rostedt (Red Hat) 	disable_trace_on_warning();
606de7edd31SSteven Rostedt (Red Hat) 
6072bb2b7b5SJohn Ogness 	printk_prefer_direct_enter();
6082bb2b7b5SJohn Ogness 
6092553b67aSJosh Poimboeuf 	if (file)
6102553b67aSJosh Poimboeuf 		pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n",
6112553b67aSJosh Poimboeuf 			raw_smp_processor_id(), current->pid, file, line,
6122553b67aSJosh Poimboeuf 			caller);
6132553b67aSJosh Poimboeuf 	else
6142553b67aSJosh Poimboeuf 		pr_warn("WARNING: CPU: %d PID: %d at %pS\n",
6152553b67aSJosh Poimboeuf 			raw_smp_processor_id(), current->pid, caller);
61674853dbaSArjan van de Ven 
6170f6f49a8SLinus Torvalds 	if (args)
6180f6f49a8SLinus Torvalds 		vprintk(args->fmt, args->args);
619a8f18b90SArjan van de Ven 
6203f388f28SAlexey Kardashevskiy 	print_modules();
6213f388f28SAlexey Kardashevskiy 
6223f388f28SAlexey Kardashevskiy 	if (regs)
6233f388f28SAlexey Kardashevskiy 		show_regs(regs);
6243f388f28SAlexey Kardashevskiy 
6251a2383e8STiezhu Yang 	if (panic_on_warn)
6269e3961a0SPrarit Bhargava 		panic("panic_on_warn set ...\n");
6279e3961a0SPrarit Bhargava 
6282f31ad64SChristophe Leroy 	if (!regs)
629a8f18b90SArjan van de Ven 		dump_stack();
6302553b67aSJosh Poimboeuf 
6314c281074SSteven Rostedt (VMware) 	print_irqtrace_events(current);
6324c281074SSteven Rostedt (VMware) 
633a8f18b90SArjan van de Ven 	print_oops_end_marker();
63423b36fecSMarco Elver 	trace_error_report_end(ERROR_DETECTOR_WARN, (unsigned long)caller);
6352553b67aSJosh Poimboeuf 
636373d4d09SRusty Russell 	/* Just a warning, don't kill lockdep. */
637373d4d09SRusty Russell 	add_taint(taint, LOCKDEP_STILL_OK);
6382bb2b7b5SJohn Ogness 
6392bb2b7b5SJohn Ogness 	printk_prefer_direct_exit();
640a8f18b90SArjan van de Ven }
6410f6f49a8SLinus Torvalds 
6422da1ead4SKees Cook #ifndef __WARN_FLAGS
643ee871133SKees Cook void warn_slowpath_fmt(const char *file, int line, unsigned taint,
644ee871133SKees Cook 		       const char *fmt, ...)
645b2be0527SBen Hutchings {
6462553b67aSJosh Poimboeuf 	struct warn_args args;
647b2be0527SBen Hutchings 
648f2f84b05SKees Cook 	pr_warn(CUT_HERE);
649d38aba49SKees Cook 
650d38aba49SKees Cook 	if (!fmt) {
651f2f84b05SKees Cook 		__warn(file, line, __builtin_return_address(0), taint,
652f2f84b05SKees Cook 		       NULL, NULL);
653f2f84b05SKees Cook 		return;
654f2f84b05SKees Cook 	}
655f2f84b05SKees Cook 
656b2be0527SBen Hutchings 	args.fmt = fmt;
657b2be0527SBen Hutchings 	va_start(args.args, fmt);
6582553b67aSJosh Poimboeuf 	__warn(file, line, __builtin_return_address(0), taint, NULL, &args);
659b2be0527SBen Hutchings 	va_end(args.args);
660b2be0527SBen Hutchings }
661ee871133SKees Cook EXPORT_SYMBOL(warn_slowpath_fmt);
662a7bed27aSKees Cook #else
663a7bed27aSKees Cook void __warn_printk(const char *fmt, ...)
664a7bed27aSKees Cook {
665a7bed27aSKees Cook 	va_list args;
666a7bed27aSKees Cook 
667a7bed27aSKees Cook 	pr_warn(CUT_HERE);
668a7bed27aSKees Cook 
669a7bed27aSKees Cook 	va_start(args, fmt);
670a7bed27aSKees Cook 	vprintk(fmt, args);
671a7bed27aSKees Cook 	va_end(args);
672a7bed27aSKees Cook }
673a7bed27aSKees Cook EXPORT_SYMBOL(__warn_printk);
67479b4cc5eSArjan van de Ven #endif
67579b4cc5eSArjan van de Ven 
676b1fca27dSAndi Kleen #ifdef CONFIG_BUG
677b1fca27dSAndi Kleen 
678b1fca27dSAndi Kleen /* Support resetting WARN*_ONCE state */
679b1fca27dSAndi Kleen 
680b1fca27dSAndi Kleen static int clear_warn_once_set(void *data, u64 val)
681b1fca27dSAndi Kleen {
682aaf5dcfbSAndi Kleen 	generic_bug_clear_once();
683b1fca27dSAndi Kleen 	memset(__start_once, 0, __end_once - __start_once);
684b1fca27dSAndi Kleen 	return 0;
685b1fca27dSAndi Kleen }
686b1fca27dSAndi Kleen 
6874169680eSYueHaibing DEFINE_DEBUGFS_ATTRIBUTE(clear_warn_once_fops, NULL, clear_warn_once_set,
688b1fca27dSAndi Kleen 			 "%lld\n");
689b1fca27dSAndi Kleen 
690b1fca27dSAndi Kleen static __init int register_warn_debugfs(void)
691b1fca27dSAndi Kleen {
692b1fca27dSAndi Kleen 	/* Don't care about failure */
6934169680eSYueHaibing 	debugfs_create_file_unsafe("clear_warn_once", 0200, NULL, NULL,
6944169680eSYueHaibing 				   &clear_warn_once_fops);
695b1fca27dSAndi Kleen 	return 0;
696b1fca27dSAndi Kleen }
697b1fca27dSAndi Kleen 
698b1fca27dSAndi Kleen device_initcall(register_warn_debugfs);
699b1fca27dSAndi Kleen #endif
700b1fca27dSAndi Kleen 
701050e9baaSLinus Torvalds #ifdef CONFIG_STACKPROTECTOR
70254371a43SArjan van de Ven 
7033162f751SArjan van de Ven /*
7043162f751SArjan van de Ven  * Called when gcc's -fstack-protector feature is used, and
7053162f751SArjan van de Ven  * gcc detects corruption of the on-stack canary value
7063162f751SArjan van de Ven  */
7075916d5f9SThomas Gleixner __visible noinstr void __stack_chk_fail(void)
7083162f751SArjan van de Ven {
7095916d5f9SThomas Gleixner 	instrumentation_begin();
71095c4fb78SBorislav Petkov 	panic("stack-protector: Kernel stack is corrupted in: %pB",
711517a92c4SIngo Molnar 		__builtin_return_address(0));
7125916d5f9SThomas Gleixner 	instrumentation_end();
7133162f751SArjan van de Ven }
7143162f751SArjan van de Ven EXPORT_SYMBOL(__stack_chk_fail);
71554371a43SArjan van de Ven 
7163162f751SArjan van de Ven #endif
717f44dd164SRusty Russell 
718f44dd164SRusty Russell core_param(panic, panic_timeout, int, 0644);
719d999bd93SFeng Tang core_param(panic_print, panic_print, ulong, 0644);
720f44dd164SRusty Russell core_param(pause_on_oops, pause_on_oops, int, 0644);
7219e3961a0SPrarit Bhargava core_param(panic_on_warn, panic_on_warn, int, 0644);
722b26e27ddSHidehiro Kawai core_param(crash_kexec_post_notifiers, crash_kexec_post_notifiers, bool, 0644);
723f06e5153SMasami Hiramatsu 
724d404ab0aSOlaf Hering static int __init oops_setup(char *s)
725d404ab0aSOlaf Hering {
726d404ab0aSOlaf Hering 	if (!s)
727d404ab0aSOlaf Hering 		return -EINVAL;
728d404ab0aSOlaf Hering 	if (!strcmp(s, "panic"))
729d404ab0aSOlaf Hering 		panic_on_oops = 1;
730d404ab0aSOlaf Hering 	return 0;
731d404ab0aSOlaf Hering }
732d404ab0aSOlaf Hering early_param("oops", oops_setup);
733db38d5c1SRafael Aquini 
734db38d5c1SRafael Aquini static int __init panic_on_taint_setup(char *s)
735db38d5c1SRafael Aquini {
736db38d5c1SRafael Aquini 	char *taint_str;
737db38d5c1SRafael Aquini 
738db38d5c1SRafael Aquini 	if (!s)
739db38d5c1SRafael Aquini 		return -EINVAL;
740db38d5c1SRafael Aquini 
741db38d5c1SRafael Aquini 	taint_str = strsep(&s, ",");
742db38d5c1SRafael Aquini 	if (kstrtoul(taint_str, 16, &panic_on_taint))
743db38d5c1SRafael Aquini 		return -EINVAL;
744db38d5c1SRafael Aquini 
745db38d5c1SRafael Aquini 	/* make sure panic_on_taint doesn't hold out-of-range TAINT flags */
746db38d5c1SRafael Aquini 	panic_on_taint &= TAINT_FLAGS_MAX;
747db38d5c1SRafael Aquini 
748db38d5c1SRafael Aquini 	if (!panic_on_taint)
749db38d5c1SRafael Aquini 		return -EINVAL;
750db38d5c1SRafael Aquini 
751db38d5c1SRafael Aquini 	if (s && !strcmp(s, "nousertaint"))
752db38d5c1SRafael Aquini 		panic_on_taint_nousertaint = true;
753db38d5c1SRafael Aquini 
754db38d5c1SRafael Aquini 	pr_info("panic_on_taint: bitmask=0x%lx nousertaint_mode=%sabled\n",
755db38d5c1SRafael Aquini 		panic_on_taint, panic_on_taint_nousertaint ? "en" : "dis");
756db38d5c1SRafael Aquini 
757db38d5c1SRafael Aquini 	return 0;
758db38d5c1SRafael Aquini }
759db38d5c1SRafael Aquini early_param("panic_on_taint", panic_on_taint_setup);
760