Commit 2553b67a authored by Josh Poimboeuf's avatar Josh Poimboeuf Committed by Linus Torvalds

lib/bug.c: use common WARN helper

The traceoff_on_warning option doesn't have any effect on s390, powerpc,
arm64, parisc, and sh because there are two different types of WARN
implementations:

1) The above mentioned architectures treat WARN() as a special case of a
   BUG() exception.  They handle warnings in report_bug() in lib/bug.c.

2) All other architectures just call warn_slowpath_*() directly.  Their
   warnings are handled in warn_slowpath_common() in kernel/panic.c.

Support traceoff_on_warning on all architectures and prevent any future
divergence by using a single common function to emit the warning.

Also remove the '()' from '%pS()', because the parentheses look funky:

  [   45.607629] WARNING: at /root/warn_mod/warn_mod.c:17 .init_dummy+0x20/0x40 [warn_mod]()
Reported-by: default avatarChunyu Hu <chuhu@redhat.com>
Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Acked-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Tested-by: default avatarPrarit Bhargava <prarit@redhat.com>
Acked-by: default avatarPrarit Bhargava <prarit@redhat.com>
Acked-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4cc7ecb7
...@@ -81,6 +81,12 @@ extern void warn_slowpath_null(const char *file, const int line); ...@@ -81,6 +81,12 @@ extern void warn_slowpath_null(const char *file, const int line);
do { printk(arg); __WARN_TAINT(taint); } while (0) do { printk(arg); __WARN_TAINT(taint); } while (0)
#endif #endif
/* used internally by panic.c */
struct warn_args;
void __warn(const char *file, int line, void *caller, unsigned taint,
struct pt_regs *regs, struct warn_args *args);
#ifndef WARN_ON #ifndef WARN_ON
#define WARN_ON(condition) ({ \ #define WARN_ON(condition) ({ \
int __ret_warn_on = !!(condition); \ int __ret_warn_on = !!(condition); \
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/nmi.h> #include <linux/nmi.h>
#include <linux/console.h> #include <linux/console.h>
#include <linux/bug.h>
#define PANIC_TIMER_STEP 100 #define PANIC_TIMER_STEP 100
#define PANIC_BLINK_SPD 18 #define PANIC_BLINK_SPD 18
...@@ -449,20 +450,25 @@ void oops_exit(void) ...@@ -449,20 +450,25 @@ void oops_exit(void)
kmsg_dump(KMSG_DUMP_OOPS); kmsg_dump(KMSG_DUMP_OOPS);
} }
#ifdef WANT_WARN_ON_SLOWPATH struct warn_args {
struct slowpath_args {
const char *fmt; const char *fmt;
va_list args; va_list args;
}; };
static void warn_slowpath_common(const char *file, int line, void *caller, void __warn(const char *file, int line, void *caller, unsigned taint,
unsigned taint, struct slowpath_args *args) struct pt_regs *regs, struct warn_args *args)
{ {
disable_trace_on_warning(); disable_trace_on_warning();
pr_warn("------------[ cut here ]------------\n"); pr_warn("------------[ cut here ]------------\n");
pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
raw_smp_processor_id(), current->pid, file, line, caller); 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) if (args)
vprintk(args->fmt, args->args); vprintk(args->fmt, args->args);
...@@ -479,20 +485,27 @@ static void warn_slowpath_common(const char *file, int line, void *caller, ...@@ -479,20 +485,27 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
} }
print_modules(); print_modules();
dump_stack();
if (regs)
show_regs(regs);
else
dump_stack();
print_oops_end_marker(); print_oops_end_marker();
/* Just a warning, don't kill lockdep. */ /* Just a warning, don't kill lockdep. */
add_taint(taint, LOCKDEP_STILL_OK); add_taint(taint, LOCKDEP_STILL_OK);
} }
#ifdef WANT_WARN_ON_SLOWPATH
void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...) void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...)
{ {
struct slowpath_args args; struct warn_args args;
args.fmt = fmt; args.fmt = fmt;
va_start(args.args, fmt); va_start(args.args, fmt);
warn_slowpath_common(file, line, __builtin_return_address(0), __warn(file, line, __builtin_return_address(0), TAINT_WARN, NULL,
TAINT_WARN, &args); &args);
va_end(args.args); va_end(args.args);
} }
EXPORT_SYMBOL(warn_slowpath_fmt); EXPORT_SYMBOL(warn_slowpath_fmt);
...@@ -500,20 +513,18 @@ EXPORT_SYMBOL(warn_slowpath_fmt); ...@@ -500,20 +513,18 @@ EXPORT_SYMBOL(warn_slowpath_fmt);
void warn_slowpath_fmt_taint(const char *file, int line, void warn_slowpath_fmt_taint(const char *file, int line,
unsigned taint, const char *fmt, ...) unsigned taint, const char *fmt, ...)
{ {
struct slowpath_args args; struct warn_args args;
args.fmt = fmt; args.fmt = fmt;
va_start(args.args, fmt); va_start(args.args, fmt);
warn_slowpath_common(file, line, __builtin_return_address(0), __warn(file, line, __builtin_return_address(0), taint, NULL, &args);
taint, &args);
va_end(args.args); va_end(args.args);
} }
EXPORT_SYMBOL(warn_slowpath_fmt_taint); EXPORT_SYMBOL(warn_slowpath_fmt_taint);
void warn_slowpath_null(const char *file, int line) void warn_slowpath_null(const char *file, int line)
{ {
warn_slowpath_common(file, line, __builtin_return_address(0), __warn(file, line, __builtin_return_address(0), TAINT_WARN, NULL, NULL);
TAINT_WARN, NULL);
} }
EXPORT_SYMBOL(warn_slowpath_null); EXPORT_SYMBOL(warn_slowpath_null);
#endif #endif
......
...@@ -167,30 +167,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs) ...@@ -167,30 +167,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
if (warning) { if (warning) {
/* this is a WARN_ON rather than BUG/BUG_ON */ /* this is a WARN_ON rather than BUG/BUG_ON */
pr_warn("------------[ cut here ]------------\n"); __warn(file, line, (void *)bugaddr, BUG_GET_TAINT(bug), regs,
NULL);
if (file)
pr_warn("WARNING: at %s:%u\n", file, line);
else
pr_warn("WARNING: at %p [verbose debug info unavailable]\n",
(void *)bugaddr);
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();
show_regs(regs);
print_oops_end_marker();
/* Just a warning, don't kill lockdep. */
add_taint(BUG_GET_TAINT(bug), LOCKDEP_STILL_OK);
return BUG_TRAP_TYPE_WARN; return BUG_TRAP_TYPE_WARN;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment