735 lines · 18.3 KB · C
RawDownload
	spin_unlock_irqrestore(&pause_on_oops_lock, flags);} /* * Return true if the calling CPU is allowed to print oops-related info. * This is a bit racy.. */bool oops_may_print(void){	return pause_on_oops_flag == 0;} /* * Called when the architecture enters its oops handler, before it prints * anything.  If this is the first CPU to oops, and it's oopsing the first * time then let it proceed. * * This is all enabled by the pause_on_oops kernel boot option.  We do all * this to ensure that oopses don't scroll off the screen.  It has the * side-effect of preventing later-oopsing CPUs from mucking up the display, * too. * * It turns out that the CPU which is allowed to print ends up pausing for * the right duration, whereas all the other CPUs pause for twice as long: * once in oops_enter(), once in oops_exit(). */void oops_enter(void){	tracing_off();	/* can't trust the integrity of the kernel anymore: */	debug_locks_off();	do_oops_enter_exit(); 	if (sysctl_oops_all_cpu_backtrace)		trigger_all_cpu_backtrace();} /* * 64-bit random ID for oopses: */static u64 oops_id; static int init_oops_id(void){	if (!oops_id)		get_random_bytes(&oops_id, sizeof(oops_id));	else		oops_id++; 	return 0;}late_initcall(init_oops_id); static void print_oops_end_marker(void){	init_oops_id();	pr_warn("---[ end trace %016llx ]---\n", (unsigned long long)oops_id);} /* * Called when the architecture exits its oops handler, after printing * everything. */void oops_exit(void){	do_oops_enter_exit();	print_oops_end_marker();	kmsg_dump(KMSG_DUMP_OOPS);} struct warn_args {	const char *fmt;	va_list args;}; void __warn(const char *file, int line, void *caller, unsigned taint,	    struct pt_regs *regs, struct warn_args *args){	disable_trace_on_warning(); 	if (file)		pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n",			raw_smp_processor_id(), current->pid, file, line,			caller);	else		pr_warn("WARNING: CPU: %d PID: %d at %pS\n",			raw_smp_processor_id(), current->pid, caller); 	if (args)		vprintk(args->fmt, args->args); 	if (panic_on_warn) {		/*		 * This thread may hit another WARN() in the panic path.		 * Resetting this prevents additional WARN() from panicking the		 * system on this thread.  Other threads are blocked by the		 * panic_mutex in panic().		 */		panic_on_warn = 0;		panic("panic_on_warn set ...\n");	} 	print_modules(); 	if (regs)		show_regs(regs);	else		dump_stack(); 	print_irqtrace_events(current); 	print_oops_end_marker(); 	/* Just a warning, don't kill lockdep. */	add_taint(taint, LOCKDEP_STILL_OK);} #ifndef __WARN_FLAGSvoid warn_slowpath_fmt(const char *file, int line, unsigned taint,		       const char *fmt, ...){	struct warn_args args; 	pr_warn(CUT_HERE); 	if (!fmt) {		__warn(file, line, __builtin_return_address(0), taint,		       NULL, NULL);		return;	} 	args.fmt = fmt;	va_start(args.args, fmt);	__warn(file, line, __builtin_return_address(0), taint, NULL, &args);	va_end(args.args);}EXPORT_SYMBOL(warn_slowpath_fmt);#elsevoid __warn_printk(const char *fmt, ...){	va_list args; 	pr_warn(CUT_HERE); 	va_start(args, fmt);	vprintk(fmt, args);	va_end(args);}EXPORT_SYMBOL(__warn_printk);#endif #ifdef CONFIG_BUG /* Support resetting WARN*_ONCE state */ static int clear_warn_once_set(void *data, u64 val){	generic_bug_clear_once();	memset(__start_once, 0, __end_once - __start_once);	return 0;} DEFINE_DEBUGFS_ATTRIBUTE(clear_warn_once_fops, NULL, clear_warn_once_set,			 "%lld\n"); static __init int register_warn_debugfs(void){	/* Don't care about failure */	debugfs_create_file_unsafe("clear_warn_once", 0200, NULL, NULL,				   &clear_warn_once_fops);	return 0;} device_initcall(register_warn_debugfs);#endif #ifdef CONFIG_STACKPROTECTOR /* * Called when gcc's -fstack-protector feature is used, and * gcc detects corruption of the on-stack canary value */__visible noinstr void __stack_chk_fail(void){	instrumentation_begin();	panic("stack-protector: Kernel stack is corrupted in: %pB",		__builtin_return_address(0));	instrumentation_end();}EXPORT_SYMBOL(__stack_chk_fail); #endif core_param(panic, panic_timeout, int, 0644);core_param(panic_print, panic_print, ulong, 0644);core_param(pause_on_oops, pause_on_oops, int, 0644);core_param(panic_on_warn, panic_on_warn, int, 0644);core_param(crash_kexec_post_notifiers, crash_kexec_post_notifiers, bool, 0644); static int __init oops_setup(char *s){	if (!s)		return -EINVAL;	if (!strcmp(s, "panic"))		panic_on_oops = 1;	return 0;}early_param("oops", oops_setup); static int __init panic_on_taint_setup(char *s){	char *taint_str; 	if (!s)		return -EINVAL; 	taint_str = strsep(&s, ",");	if (kstrtoul(taint_str, 16, &panic_on_taint))		return -EINVAL; 	/* make sure panic_on_taint doesn't hold out-of-range TAINT flags */	panic_on_taint &= TAINT_FLAGS_MAX; 	if (!panic_on_taint)		return -EINVAL; 	if (s && !strcmp(s, "nousertaint"))		panic_on_taint_nousertaint = true; 	pr_info("panic_on_taint: bitmask=0x%lx nousertaint_mode=%sabled\n",		panic_on_taint, panic_on_taint_nousertaint ? "en" : "dis"); 	return 0;}early_param("panic_on_taint", panic_on_taint_setup);

Lines 501–735 of 735. Previous lines