panic.c 18 KB

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