blob: b0282f74d60cd3f2e8c30ce2a9466c96075c751d [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/kernel/panic.c
4 *
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 */
7
8/*
9 * This function is used through-out the kernel (including mm and fs)
10 * to indicate a major problem.
11 */
12#include <linux/debug_locks.h>
13#include <linux/sched/debug.h>
14#include <linux/interrupt.h>
15#include <linux/kgdb.h>
16#include <linux/kmsg_dump.h>
17#include <linux/kallsyms.h>
18#include <linux/notifier.h>
19#include <linux/vt_kern.h>
20#include <linux/module.h>
21#include <linux/random.h>
22#include <linux/ftrace.h>
23#include <linux/reboot.h>
24#include <linux/delay.h>
25#include <linux/kexec.h>
26#include <linux/sched.h>
27#include <linux/sysrq.h>
28#include <linux/init.h>
29#include <linux/nmi.h>
30#include <linux/console.h>
31#include <linux/bug.h>
32#include <linux/ratelimit.h>
33#include <linux/debugfs.h>
34#include <linux/sysfs.h>
35#include <asm/sections.h>
36
37#ifdef CONFIG_PXA_RAMDUMP
38#include <linux/ramdump.h>
39#endif
40
41#define PANIC_TIMER_STEP 100
42#define PANIC_BLINK_SPD 18
43
44int panic_on_oops = CONFIG_PANIC_ON_OOPS_VALUE;
45static unsigned long tainted_mask =
46 IS_ENABLED(CONFIG_GCC_PLUGIN_RANDSTRUCT) ? (1 << TAINT_RANDSTRUCT) : 0;
47static int pause_on_oops;
48static int pause_on_oops_flag;
49static DEFINE_SPINLOCK(pause_on_oops_lock);
50bool crash_kexec_post_notifiers;
51int panic_on_warn __read_mostly;
52static unsigned int warn_limit __read_mostly;
53
54int panic_timeout = CONFIG_PANIC_TIMEOUT;
55EXPORT_SYMBOL_GPL(panic_timeout);
56
57#define PANIC_PRINT_TASK_INFO 0x00000001
58#define PANIC_PRINT_MEM_INFO 0x00000002
59#define PANIC_PRINT_TIMER_INFO 0x00000004
60#define PANIC_PRINT_LOCK_INFO 0x00000008
61#define PANIC_PRINT_FTRACE_INFO 0x00000010
62#define PANIC_PRINT_ALL_PRINTK_MSG 0x00000020
63unsigned long panic_print;
64
65ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
66
67EXPORT_SYMBOL(panic_notifier_list);
68
69#ifdef CONFIG_SYSCTL
70static struct ctl_table kern_panic_table[] = {
71 {
72 .procname = "warn_limit",
73 .data = &warn_limit,
74 .maxlen = sizeof(warn_limit),
75 .mode = 0644,
76 .proc_handler = proc_douintvec,
77 },
78 { }
79};
80
81static __init int kernel_panic_sysctls_init(void)
82{
83 register_sysctl_init("kernel", kern_panic_table);
84 return 0;
85}
86late_initcall(kernel_panic_sysctls_init);
87#endif
88
89static atomic_t warn_count = ATOMIC_INIT(0);
90
91#ifdef CONFIG_SYSFS
92static ssize_t warn_count_show(struct kobject *kobj, struct kobj_attribute *attr,
93 char *page)
94{
95 return sysfs_emit(page, "%d\n", atomic_read(&warn_count));
96}
97
98static struct kobj_attribute warn_count_attr = __ATTR_RO(warn_count);
99
100static __init int kernel_panic_sysfs_init(void)
101{
102 sysfs_add_file_to_group(kernel_kobj, &warn_count_attr.attr, NULL);
103 return 0;
104}
105late_initcall(kernel_panic_sysfs_init);
106#endif
107
108static long no_blink(int state)
109{
110 return 0;
111}
112
113/* Returns how long it waited in ms */
114long (*panic_blink)(int state);
115EXPORT_SYMBOL(panic_blink);
116
117/*
118 * Stop ourself in panic -- architecture code may override this
119 */
120void __weak panic_smp_self_stop(void)
121{
122 while (1)
123 cpu_relax();
124}
125
126/*
127 * Stop ourselves in NMI context if another CPU has already panicked. Arch code
128 * may override this to prepare for crash dumping, e.g. save regs info.
129 */
130void __weak nmi_panic_self_stop(struct pt_regs *regs)
131{
132 panic_smp_self_stop();
133}
134
135/*
136 * Stop other CPUs in panic. Architecture dependent code may override this
137 * with more suitable version. For example, if the architecture supports
138 * crash dump, it should save registers of each stopped CPU and disable
139 * per-CPU features such as virtualization extensions.
140 */
141void __weak crash_smp_send_stop(void)
142{
143 static int cpus_stopped;
144
145 /*
146 * This function can be called twice in panic path, but obviously
147 * we execute this only once.
148 */
149 if (cpus_stopped)
150 return;
151
152 /*
153 * Note smp_send_stop is the usual smp shutdown function, which
154 * unfortunately means it may not be hardened to work in a panic
155 * situation.
156 */
157 smp_send_stop();
158 cpus_stopped = 1;
159}
160
161atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID);
162
163/*
164 * A variant of panic() called from NMI context. We return if we've already
165 * panicked on this CPU. If another CPU already panicked, loop in
166 * nmi_panic_self_stop() which can provide architecture dependent code such
167 * as saving register state for crash dump.
168 */
169void nmi_panic(struct pt_regs *regs, const char *msg)
170{
171 int old_cpu, cpu;
172
173 cpu = raw_smp_processor_id();
174 old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, cpu);
175
176 if (old_cpu == PANIC_CPU_INVALID)
177 panic("%s", msg);
178 else if (old_cpu != cpu)
179 nmi_panic_self_stop(regs);
180}
181EXPORT_SYMBOL(nmi_panic);
182
183static void panic_print_sys_info(void)
184{
185 if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG)
186 console_flush_on_panic(CONSOLE_REPLAY_ALL);
187
188 if (panic_print & PANIC_PRINT_TASK_INFO)
189 show_state();
190
191 if (panic_print & PANIC_PRINT_MEM_INFO)
192 show_mem(0, NULL);
193
194 if (panic_print & PANIC_PRINT_TIMER_INFO)
195 sysrq_timer_list_show();
196
197 if (panic_print & PANIC_PRINT_LOCK_INFO)
198 debug_show_all_locks();
199
200 if (panic_print & PANIC_PRINT_FTRACE_INFO)
201 ftrace_dump(DUMP_ALL);
202}
203
204void check_panic_on_warn(const char *origin)
205{
206 unsigned int limit;
207
208 if (panic_on_warn)
209 panic("%s: panic_on_warn set ...\n", origin);
210
211 limit = READ_ONCE(warn_limit);
212 if (atomic_inc_return(&warn_count) >= limit && limit)
213 panic("%s: system warned too often (kernel.warn_limit is %d)",
214 origin, limit);
215}
216
217/**
218 * panic - halt the system
219 * @fmt: The text string to print
220 *
221 * Display a message, then perform cleanups.
222 *
223 * This function never returns.
224 */
225void panic(const char *fmt, ...)
226{
227 static char buf[1024];
228 va_list args;
229 long i, i_next = 0, len;
230 int state = 0;
231 int old_cpu, this_cpu;
232 bool _crash_kexec_post_notifiers = crash_kexec_post_notifiers;
233
b.liub17525e2025-05-14 17:22:29 +0800234 //mbtk wyq for reboot reason
235 int ret = MBTK_REBOOT_RESULT_FAIL;
236 //mbtk wyq for reboot reason
237
b.liue9582032025-04-17 19:18:16 +0800238 if (panic_on_warn) {
239 /*
240 * This thread may hit another WARN() in the panic path.
241 * Resetting this prevents additional WARN() from panicking the
242 * system on this thread. Other threads are blocked by the
243 * panic_mutex in panic().
244 */
245 panic_on_warn = 0;
246 }
247
248 /*
249 * Disable local interrupts. This will prevent panic_smp_self_stop
250 * from deadlocking the first cpu that invokes the panic, since
251 * there is nothing to prevent an interrupt handler (that runs
252 * after setting panic_cpu) from invoking panic() again.
253 */
254 local_irq_disable();
255 preempt_disable_notrace();
256
257 /*
258 * It's possible to come here directly from a panic-assertion and
259 * not have preempt disabled. Some functions called from here want
260 * preempt to be disabled. No point enabling it later though...
261 *
262 * Only one CPU is allowed to execute the panic code from here. For
263 * multiple parallel invocations of panic, all other CPUs either
264 * stop themself or will wait until they are stopped by the 1st CPU
265 * with smp_send_stop().
266 *
267 * `old_cpu == PANIC_CPU_INVALID' means this is the 1st CPU which
268 * comes here, so go ahead.
269 * `old_cpu == this_cpu' means we came from nmi_panic() which sets
270 * panic_cpu to this CPU. In this case, this is also the 1st CPU.
271 */
272 this_cpu = raw_smp_processor_id();
273 old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, this_cpu);
274
275 if (old_cpu != PANIC_CPU_INVALID && old_cpu != this_cpu)
276 panic_smp_self_stop();
277
278 console_verbose();
279 bust_spinlocks(1);
280 va_start(args, fmt);
281 len = vscnprintf(buf, sizeof(buf), fmt, args);
282 va_end(args);
283
284 if (len && buf[len - 1] == '\n')
285 buf[len - 1] = '\0';
286
287 pr_emerg("Kernel panic - not syncing: %s\n", buf);
b.liub17525e2025-05-14 17:22:29 +0800288
289//mbtk wyq for reboot reason
290 ret = mbtk_reboot_reason_save(MBTK_DEV_INFO_NAME, MBTK_REBOOT_FLAG_ABNORMAL);
291 if(ret) {
292 pr_emerg("mbtk_reboot_reason_save err\n");
293 }
294//mbtk wyq for reboot reason
295
b.liue9582032025-04-17 19:18:16 +0800296#ifdef CONFIG_DEBUG_BUGVERBOSE
297 /*
298 * Avoid nested stack-dumping if a panic occurs during oops processing
299 */
300 if (!test_taint(TAINT_DIE) && oops_in_progress <= 1)
301 dump_stack();
302#endif
303
304#ifdef CONFIG_PXA_RAMDUMP
305 /*
306 * Panic text is not available otherwise, at least
307 * not via kexec, so save it now.
308 */
309 ramdump_save_panic_text(buf);
310#endif
311
312 /*
313 * If kgdb is enabled, give it a chance to run before we stop all
314 * the other CPUs or else we won't be able to debug processes left
315 * running on them.
316 */
317 kgdb_panic(buf);
318
319 /*
320 * If we have crashed and we have a crash kernel loaded let it handle
321 * everything else.
322 * If we want to run this after calling panic_notifiers, pass
323 * the "crash_kexec_post_notifiers" option to the kernel.
324 *
325 * Bypass the panic_cpu check and call __crash_kexec directly.
326 */
327 if (!_crash_kexec_post_notifiers) {
328 printk_safe_flush_on_panic();
329 __crash_kexec(NULL);
330
331 /*
332 * Note smp_send_stop is the usual smp shutdown function, which
333 * unfortunately means it may not be hardened to work in a
334 * panic situation.
335 */
336 smp_send_stop();
337 } else {
338 /*
339 * If we want to do crash dump after notifier calls and
340 * kmsg_dump, we will need architecture dependent extra
341 * works in addition to stopping other CPUs.
342 */
343 crash_smp_send_stop();
344 }
345
346 /*
347 * Run any panic handlers, including those that might need to
348 * add information to the kmsg dump output.
349 */
350 atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
351
352 /* Call flush even twice. It tries harder with a single online CPU */
353 printk_safe_flush_on_panic();
354 kmsg_dump(KMSG_DUMP_PANIC);
355
356 /*
357 * If you doubt kdump always works fine in any situation,
358 * "crash_kexec_post_notifiers" offers you a chance to run
359 * panic_notifiers and dumping kmsg before kdump.
360 * Note: since some panic_notifiers can make crashed kernel
361 * more unstable, it can increase risks of the kdump failure too.
362 *
363 * Bypass the panic_cpu check and call __crash_kexec directly.
364 */
365 if (_crash_kexec_post_notifiers)
366 __crash_kexec(NULL);
367
368#ifdef CONFIG_VT
369 unblank_screen();
370#endif
371 console_unblank();
372
373 /*
374 * We may have ended up stopping the CPU holding the lock (in
375 * smp_send_stop()) while still having some valuable data in the console
376 * buffer. Try to acquire the lock then release it regardless of the
377 * result. The release will also print the buffers out. Locks debug
378 * should be disabled to avoid reporting bad unlock balance when
379 * panic() is not being callled from OOPS.
380 */
381 debug_locks_off();
382 console_flush_on_panic(CONSOLE_FLUSH_PENDING);
383
384 panic_print_sys_info();
385
386 if (!panic_blink)
387 panic_blink = no_blink;
388
389 if (panic_timeout > 0) {
390 /*
391 * Delay timeout seconds before rebooting the machine.
392 * We can't use the "normal" timers since we just panicked.
393 */
394 pr_emerg("Rebooting in %d seconds..\n", panic_timeout);
395
396 for (i = 0; i < panic_timeout * 1000; i += PANIC_TIMER_STEP) {
397 touch_nmi_watchdog();
398 if (i >= i_next) {
399 i += panic_blink(state ^= 1);
400 i_next = i + 3600 / PANIC_BLINK_SPD;
401 }
402 mdelay(PANIC_TIMER_STEP);
403 }
404 }
405 if (panic_timeout != 0) {
406 /*
407 * This will not be a clean reboot, with everything
408 * shutting down. But if there is a chance of
409 * rebooting the system it will be rebooted.
410 */
411 if (panic_reboot_mode != REBOOT_UNDEFINED)
412 reboot_mode = panic_reboot_mode;
413 emergency_restart();
414 }
415#ifdef __sparc__
416 {
417 extern int stop_a_enabled;
418 /* Make sure the user can actually press Stop-A (L1-A) */
419 stop_a_enabled = 1;
420 pr_emerg("Press Stop-A (L1-A) from sun keyboard or send break\n"
421 "twice on console to return to the boot prom\n");
422 }
423#endif
424#if defined(CONFIG_S390)
425 disabled_wait();
426#endif
427 pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf);
428
429 /* Do not scroll important messages printed above */
430 suppress_printk = 1;
431
432 /*
433 * The final messages may not have been printed if in a context that
434 * defers printing (such as NMI) and irq_work is not available.
435 * Explicitly flush the kernel log buffer one last time.
436 */
437 console_flush_on_panic(CONSOLE_FLUSH_PENDING);
438
439 local_irq_enable();
440 for (i = 0; ; i += PANIC_TIMER_STEP) {
441 touch_softlockup_watchdog();
442 if (i >= i_next) {
443 i += panic_blink(state ^= 1);
444 i_next = i + 3600 / PANIC_BLINK_SPD;
445 }
446 mdelay(PANIC_TIMER_STEP);
447 }
448}
449
450EXPORT_SYMBOL(panic);
451
452/*
453 * TAINT_FORCED_RMMOD could be a per-module flag but the module
454 * is being removed anyway.
455 */
456const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = {
457 [ TAINT_PROPRIETARY_MODULE ] = { 'P', 'G', true },
458 [ TAINT_FORCED_MODULE ] = { 'F', ' ', true },
459 [ TAINT_CPU_OUT_OF_SPEC ] = { 'S', ' ', false },
460 [ TAINT_FORCED_RMMOD ] = { 'R', ' ', false },
461 [ TAINT_MACHINE_CHECK ] = { 'M', ' ', false },
462 [ TAINT_BAD_PAGE ] = { 'B', ' ', false },
463 [ TAINT_USER ] = { 'U', ' ', false },
464 [ TAINT_DIE ] = { 'D', ' ', false },
465 [ TAINT_OVERRIDDEN_ACPI_TABLE ] = { 'A', ' ', false },
466 [ TAINT_WARN ] = { 'W', ' ', false },
467 [ TAINT_CRAP ] = { 'C', ' ', true },
468 [ TAINT_FIRMWARE_WORKAROUND ] = { 'I', ' ', false },
469 [ TAINT_OOT_MODULE ] = { 'O', ' ', true },
470 [ TAINT_UNSIGNED_MODULE ] = { 'E', ' ', true },
471 [ TAINT_SOFTLOCKUP ] = { 'L', ' ', false },
472 [ TAINT_LIVEPATCH ] = { 'K', ' ', true },
473 [ TAINT_AUX ] = { 'X', ' ', true },
474 [ TAINT_RANDSTRUCT ] = { 'T', ' ', true },
475};
476
477/**
478 * print_tainted - return a string to represent the kernel taint state.
479 *
480 * For individual taint flag meanings, see Documentation/admin-guide/sysctl/kernel.rst
481 *
482 * The string is overwritten by the next call to print_tainted(),
483 * but is always NULL terminated.
484 */
485const char *print_tainted(void)
486{
487 static char buf[TAINT_FLAGS_COUNT + sizeof("Tainted: ")];
488
489 BUILD_BUG_ON(ARRAY_SIZE(taint_flags) != TAINT_FLAGS_COUNT);
490
491 if (tainted_mask) {
492 char *s;
493 int i;
494
495 s = buf + sprintf(buf, "Tainted: ");
496 for (i = 0; i < TAINT_FLAGS_COUNT; i++) {
497 const struct taint_flag *t = &taint_flags[i];
498 *s++ = test_bit(i, &tainted_mask) ?
499 t->c_true : t->c_false;
500 }
501 *s = 0;
502 } else
503 snprintf(buf, sizeof(buf), "Not tainted");
504
505 return buf;
506}
507
508int test_taint(unsigned flag)
509{
510 return test_bit(flag, &tainted_mask);
511}
512EXPORT_SYMBOL(test_taint);
513
514unsigned long get_taint(void)
515{
516 return tainted_mask;
517}
518
519/**
520 * add_taint: add a taint flag if not already set.
521 * @flag: one of the TAINT_* constants.
522 * @lockdep_ok: whether lock debugging is still OK.
523 *
524 * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for
525 * some notewortht-but-not-corrupting cases, it can be set to true.
526 */
527void add_taint(unsigned flag, enum lockdep_ok lockdep_ok)
528{
529 if (lockdep_ok == LOCKDEP_NOW_UNRELIABLE && __debug_locks_off())
530 pr_warn("Disabling lock debugging due to kernel taint\n");
531
532 set_bit(flag, &tainted_mask);
533}
534EXPORT_SYMBOL(add_taint);
535
536static void spin_msec(int msecs)
537{
538 int i;
539
540 for (i = 0; i < msecs; i++) {
541 touch_nmi_watchdog();
542 mdelay(1);
543 }
544}
545
546/*
547 * It just happens that oops_enter() and oops_exit() are identically
548 * implemented...
549 */
550static void do_oops_enter_exit(void)
551{
552 unsigned long flags;
553 static int spin_counter;
554
555 if (!pause_on_oops)
556 return;
557
558 spin_lock_irqsave(&pause_on_oops_lock, flags);
559 if (pause_on_oops_flag == 0) {
560 /* This CPU may now print the oops message */
561 pause_on_oops_flag = 1;
562 } else {
563 /* We need to stall this CPU */
564 if (!spin_counter) {
565 /* This CPU gets to do the counting */
566 spin_counter = pause_on_oops;
567 do {
568 spin_unlock(&pause_on_oops_lock);
569 spin_msec(MSEC_PER_SEC);
570 spin_lock(&pause_on_oops_lock);
571 } while (--spin_counter);
572 pause_on_oops_flag = 0;
573 } else {
574 /* This CPU waits for a different one */
575 while (spin_counter) {
576 spin_unlock(&pause_on_oops_lock);
577 spin_msec(1);
578 spin_lock(&pause_on_oops_lock);
579 }
580 }
581 }
582 spin_unlock_irqrestore(&pause_on_oops_lock, flags);
583}
584
585/*
586 * Return true if the calling CPU is allowed to print oops-related info.
587 * This is a bit racy..
588 */
589int oops_may_print(void)
590{
591 return pause_on_oops_flag == 0;
592}
593
594/*
595 * Called when the architecture enters its oops handler, before it prints
596 * anything. If this is the first CPU to oops, and it's oopsing the first
597 * time then let it proceed.
598 *
599 * This is all enabled by the pause_on_oops kernel boot option. We do all
600 * this to ensure that oopses don't scroll off the screen. It has the
601 * side-effect of preventing later-oopsing CPUs from mucking up the display,
602 * too.
603 *
604 * It turns out that the CPU which is allowed to print ends up pausing for
605 * the right duration, whereas all the other CPUs pause for twice as long:
606 * once in oops_enter(), once in oops_exit().
607 */
608void oops_enter(void)
609{
610 tracing_off();
611 /* can't trust the integrity of the kernel anymore: */
612 debug_locks_off();
613 do_oops_enter_exit();
614}
615
616/*
617 * 64-bit random ID for oopses:
618 */
619static u64 oops_id;
620
621static int init_oops_id(void)
622{
623 if (!oops_id)
624 get_random_bytes(&oops_id, sizeof(oops_id));
625 else
626 oops_id++;
627
628 return 0;
629}
630late_initcall(init_oops_id);
631
632void print_oops_end_marker(void)
633{
634 init_oops_id();
635 pr_warn("---[ end trace %016llx ]---\n", (unsigned long long)oops_id);
636}
637
638/*
639 * Called when the architecture exits its oops handler, after printing
640 * everything.
641 */
642void oops_exit(void)
643{
644 do_oops_enter_exit();
645 print_oops_end_marker();
646 kmsg_dump(KMSG_DUMP_OOPS);
647}
648
649struct warn_args {
650 const char *fmt;
651 va_list args;
652};
653
654void __warn(const char *file, int line, void *caller, unsigned taint,
655 struct pt_regs *regs, struct warn_args *args)
656{
657 disable_trace_on_warning();
658
659 if (file)
660 pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n",
661 raw_smp_processor_id(), current->pid, file, line,
662 caller);
663 else
664 pr_warn("WARNING: CPU: %d PID: %d at %pS\n",
665 raw_smp_processor_id(), current->pid, caller);
666
667 if (args)
668 vprintk(args->fmt, args->args);
669
670 check_panic_on_warn("kernel");
671
672 print_modules();
673
674 if (regs)
675 show_regs(regs);
676 else
677 dump_stack();
678
679 print_irqtrace_events(current);
680
681 print_oops_end_marker();
682
683 /* Just a warning, don't kill lockdep. */
684 add_taint(taint, LOCKDEP_STILL_OK);
685}
686
687#ifndef __WARN_FLAGS
688void warn_slowpath_fmt(const char *file, int line, unsigned taint,
689 const char *fmt, ...)
690{
691 struct warn_args args;
692
693 pr_warn(CUT_HERE);
694
695 if (!fmt) {
696 __warn(file, line, __builtin_return_address(0), taint,
697 NULL, NULL);
698 return;
699 }
700
701 args.fmt = fmt;
702 va_start(args.args, fmt);
703 __warn(file, line, __builtin_return_address(0), taint, NULL, &args);
704 va_end(args.args);
705}
706EXPORT_SYMBOL(warn_slowpath_fmt);
707#else
708void __warn_printk(const char *fmt, ...)
709{
710 va_list args;
711
712 pr_warn(CUT_HERE);
713
714 va_start(args, fmt);
715 vprintk(fmt, args);
716 va_end(args);
717}
718EXPORT_SYMBOL(__warn_printk);
719#endif
720
721#ifdef CONFIG_BUG
722
723/* Support resetting WARN*_ONCE state */
724
725static int clear_warn_once_set(void *data, u64 val)
726{
727 generic_bug_clear_once();
728 memset(__start_once, 0, __end_once - __start_once);
729 return 0;
730}
731
732DEFINE_DEBUGFS_ATTRIBUTE(clear_warn_once_fops, NULL, clear_warn_once_set,
733 "%lld\n");
734
735static __init int register_warn_debugfs(void)
736{
737 /* Don't care about failure */
738 debugfs_create_file_unsafe("clear_warn_once", 0200, NULL, NULL,
739 &clear_warn_once_fops);
740 return 0;
741}
742
743device_initcall(register_warn_debugfs);
744#endif
745
746#ifdef CONFIG_STACKPROTECTOR
747
748/*
749 * Called when gcc's -fstack-protector feature is used, and
750 * gcc detects corruption of the on-stack canary value
751 */
752__visible void __stack_chk_fail(void)
753{
754 panic("stack-protector: Kernel stack is corrupted in: %pB",
755 __builtin_return_address(0));
756}
757EXPORT_SYMBOL(__stack_chk_fail);
758
759#endif
760
761#ifdef CONFIG_ARCH_HAS_REFCOUNT
762void refcount_error_report(struct pt_regs *regs, const char *err)
763{
764 WARN_RATELIMIT(1, "refcount_t %s at %pB in %s[%d], uid/euid: %u/%u\n",
765 err, (void *)instruction_pointer(regs),
766 current->comm, task_pid_nr(current),
767 from_kuid_munged(&init_user_ns, current_uid()),
768 from_kuid_munged(&init_user_ns, current_euid()));
769}
770#endif
771
772core_param(panic, panic_timeout, int, 0644);
773core_param(panic_print, panic_print, ulong, 0644);
774core_param(pause_on_oops, pause_on_oops, int, 0644);
775core_param(panic_on_warn, panic_on_warn, int, 0644);
776core_param(crash_kexec_post_notifiers, crash_kexec_post_notifiers, bool, 0644);
777
778static int __init oops_setup(char *s)
779{
780 if (!s)
781 return -EINVAL;
782 if (!strcmp(s, "panic"))
783 panic_on_oops = 1;
784 return 0;
785}
786early_param("oops", oops_setup);