* [PATCH] lib/bug.c: use common WARN helper
@ 2016-02-23 3:54 Josh Poimboeuf
2016-02-23 12:14 ` Heiko Carstens
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Josh Poimboeuf @ 2016-02-23 3:54 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, Steven Rostedt, Heiko Carstens, Prarit Bhargava
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: Chunyu Hu <chuhu@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
Based on linux-next/master.
include/asm-generic/bug.h | 7 +++++++
kernel/panic.c | 44 +++++++++++++++++++++++++-------------------
lib/bug.c | 27 +++------------------------
3 files changed, 35 insertions(+), 43 deletions(-)
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 630dd23..b67a0f9 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -81,6 +81,13 @@ extern void warn_slowpath_null(const char *file, const int line);
do { printk(arg); __WARN_TAINT(taint); } while (0)
#endif
+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);
+
#ifndef WARN_ON
#define WARN_ON(condition) ({ \
int __ret_warn_on = !!(condition); \
diff --git a/kernel/panic.c b/kernel/panic.c
index d96469d..10f7d94 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -24,6 +24,7 @@
#include <linux/init.h>
#include <linux/nmi.h>
#include <linux/console.h>
+#include <linux/bug.h>
#define PANIC_TIMER_STEP 100
#define PANIC_BLINK_SPD 18
@@ -449,20 +450,20 @@ void oops_exit(void)
kmsg_dump(KMSG_DUMP_OOPS);
}
-#ifdef WANT_WARN_ON_SLOWPATH
-struct slowpath_args {
- const char *fmt;
- va_list args;
-};
-
-static void warn_slowpath_common(const char *file, int line, void *caller,
- unsigned taint, struct slowpath_args *args)
+void __warn(const char *file, int line, void *caller, unsigned taint,
+ struct pt_regs *regs, struct warn_args *args)
{
disable_trace_on_warning();
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)
vprintk(args->fmt, args->args);
@@ -479,20 +480,27 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
}
print_modules();
- dump_stack();
+
+ if (regs)
+ show_regs(regs);
+ else
+ dump_stack();
+
print_oops_end_marker();
+
/* Just a warning, don't kill lockdep. */
add_taint(taint, LOCKDEP_STILL_OK);
}
+#ifdef WANT_WARN_ON_SLOWPATH
void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...)
{
- struct slowpath_args args;
+ struct warn_args args;
args.fmt = fmt;
va_start(args.args, fmt);
- warn_slowpath_common(file, line, __builtin_return_address(0),
- TAINT_WARN, &args);
+ __warn(file, line, __builtin_return_address(0), TAINT_WARN, NULL,
+ &args);
va_end(args.args);
}
EXPORT_SYMBOL(warn_slowpath_fmt);
@@ -500,20 +508,18 @@ EXPORT_SYMBOL(warn_slowpath_fmt);
void warn_slowpath_fmt_taint(const char *file, int line,
unsigned taint, const char *fmt, ...)
{
- struct slowpath_args args;
+ struct warn_args args;
args.fmt = fmt;
va_start(args.args, fmt);
- warn_slowpath_common(file, line, __builtin_return_address(0),
- taint, &args);
+ __warn(file, line, __builtin_return_address(0), taint, NULL, &args);
va_end(args.args);
}
EXPORT_SYMBOL(warn_slowpath_fmt_taint);
void warn_slowpath_null(const char *file, int line)
{
- warn_slowpath_common(file, line, __builtin_return_address(0),
- TAINT_WARN, NULL);
+ __warn(file, line, __builtin_return_address(0), TAINT_WARN, NULL, NULL);
}
EXPORT_SYMBOL(warn_slowpath_null);
#endif
diff --git a/lib/bug.c b/lib/bug.c
index 6cde380..2af139f 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -167,30 +167,9 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
if (warning) {
/* this is a WARN_ON rather than BUG/BUG_ON */
- pr_warn("------------[ cut here ]------------\n");
-
- 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);
+ __warn(file, line, (void *)bugaddr, BUG_GET_TAINT(bug), regs,
+ NULL);
+
return BUG_TRAP_TYPE_WARN;
}
--
2.4.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] lib/bug.c: use common WARN helper
2016-02-23 3:54 [PATCH] lib/bug.c: use common WARN helper Josh Poimboeuf
@ 2016-02-23 12:14 ` Heiko Carstens
2016-02-23 13:13 ` Prarit Bhargava
2016-02-23 13:35 ` Steven Rostedt
2 siblings, 0 replies; 4+ messages in thread
From: Heiko Carstens @ 2016-02-23 12:14 UTC (permalink / raw)
To: Josh Poimboeuf
Cc: Andrew Morton, linux-kernel, Steven Rostedt, Prarit Bhargava
On Mon, Feb 22, 2016 at 09:54:17PM -0600, Josh Poimboeuf wrote:
> 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: Chunyu Hu <chuhu@redhat.com>
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
> Based on linux-next/master.
>
> include/asm-generic/bug.h | 7 +++++++
> kernel/panic.c | 44 +++++++++++++++++++++++++-------------------
> lib/bug.c | 27 +++------------------------
> 3 files changed, 35 insertions(+), 43 deletions(-)
Nice! Just tested this on s390.
Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lib/bug.c: use common WARN helper
2016-02-23 3:54 [PATCH] lib/bug.c: use common WARN helper Josh Poimboeuf
2016-02-23 12:14 ` Heiko Carstens
@ 2016-02-23 13:13 ` Prarit Bhargava
2016-02-23 13:35 ` Steven Rostedt
2 siblings, 0 replies; 4+ messages in thread
From: Prarit Bhargava @ 2016-02-23 13:13 UTC (permalink / raw)
To: Josh Poimboeuf, Andrew Morton
Cc: linux-kernel, Steven Rostedt, Heiko Carstens
On 02/22/2016 10:54 PM, Josh Poimboeuf wrote:
> 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: Chunyu Hu <chuhu@redhat.com>
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
<snip>
> -
> - 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);
> + __warn(file, line, (void *)bugaddr, BUG_GET_TAINT(bug), regs,
> + NULL);
> +
^^^ minor minor minor nit: extra line here. Not a big deal but change it if
anyone else complains.
Other than that ...
Acked-and-tested-by: Prarit Bhargava <prarit@redhat.com>
P.
> return BUG_TRAP_TYPE_WARN;
> }
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lib/bug.c: use common WARN helper
2016-02-23 3:54 [PATCH] lib/bug.c: use common WARN helper Josh Poimboeuf
2016-02-23 12:14 ` Heiko Carstens
2016-02-23 13:13 ` Prarit Bhargava
@ 2016-02-23 13:35 ` Steven Rostedt
2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2016-02-23 13:35 UTC (permalink / raw)
To: Josh Poimboeuf
Cc: Andrew Morton, linux-kernel, Heiko Carstens, Prarit Bhargava
On Mon, 22 Feb 2016 21:54:17 -0600
Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> 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]()
Note, the "()" were to denote that it's a function. But as it is a "pS"
and not a "ps" which adds the offset, it does make it look funky.
>
> Reported-by: Chunyu Hu <chuhu@redhat.com>
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
> Based on linux-next/master.
>
> include/asm-generic/bug.h | 7 +++++++
> kernel/panic.c | 44 +++++++++++++++++++++++++-------------------
> lib/bug.c | 27 +++------------------------
> 3 files changed, 35 insertions(+), 43 deletions(-)
>
> diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
> index 630dd23..b67a0f9 100644
> --- a/include/asm-generic/bug.h
> +++ b/include/asm-generic/bug.h
> @@ -81,6 +81,13 @@ extern void warn_slowpath_null(const char *file, const int line);
> do { printk(arg); __WARN_TAINT(taint); } while (0)
> #endif
>
> +struct warn_args {
> + const char *fmt;
> + va_list args;
> +};
Just a nit. Nothing using warn_args outside of panic.c, thus you don't
need to declare it here. Either add a comment about what these args are
for, or simply do:
/* Used internally by panic */
struct warn_args;
Other than that, the rest looks fine to me.
-- Steve
> +void __warn(const char *file, int line, void *caller, unsigned taint,
> + struct pt_regs *regs, struct warn_args *args);
> +
> #ifndef WARN_ON
> #define WARN_ON(condition) ({ \
> int __ret_warn_on = !!(condition); \
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-02-23 13:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-23 3:54 [PATCH] lib/bug.c: use common WARN helper Josh Poimboeuf
2016-02-23 12:14 ` Heiko Carstens
2016-02-23 13:13 ` Prarit Bhargava
2016-02-23 13:35 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).