Skip to content

Commit 2553b67

Browse files
jpoimboetorvalds
authored andcommitted
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: Chunyu Hu <chuhu@redhat.com> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com> Tested-by: Prarit Bhargava <prarit@redhat.com> Acked-by: Prarit Bhargava <prarit@redhat.com> Acked-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 4cc7ecb commit 2553b67

File tree

3 files changed

+34
-39
lines changed

3 files changed

+34
-39
lines changed

include/asm-generic/bug.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ extern void warn_slowpath_null(const char *file, const int line);
8181
do { printk(arg); __WARN_TAINT(taint); } while (0)
8282
#endif
8383

84+
/* used internally by panic.c */
85+
struct warn_args;
86+
87+
void __warn(const char *file, int line, void *caller, unsigned taint,
88+
struct pt_regs *regs, struct warn_args *args);
89+
8490
#ifndef WARN_ON
8591
#define WARN_ON(condition) ({ \
8692
int __ret_warn_on = !!(condition); \

kernel/panic.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/init.h>
2525
#include <linux/nmi.h>
2626
#include <linux/console.h>
27+
#include <linux/bug.h>
2728

2829
#define PANIC_TIMER_STEP 100
2930
#define PANIC_BLINK_SPD 18
@@ -449,20 +450,25 @@ void oops_exit(void)
449450
kmsg_dump(KMSG_DUMP_OOPS);
450451
}
451452

452-
#ifdef WANT_WARN_ON_SLOWPATH
453-
struct slowpath_args {
453+
struct warn_args {
454454
const char *fmt;
455455
va_list args;
456456
};
457457

458-
static void warn_slowpath_common(const char *file, int line, void *caller,
459-
unsigned taint, struct slowpath_args *args)
458+
void __warn(const char *file, int line, void *caller, unsigned taint,
459+
struct pt_regs *regs, struct warn_args *args)
460460
{
461461
disable_trace_on_warning();
462462

463463
pr_warn("------------[ cut here ]------------\n");
464-
pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
465-
raw_smp_processor_id(), current->pid, file, line, caller);
464+
465+
if (file)
466+
pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n",
467+
raw_smp_processor_id(), current->pid, file, line,
468+
caller);
469+
else
470+
pr_warn("WARNING: CPU: %d PID: %d at %pS\n",
471+
raw_smp_processor_id(), current->pid, caller);
466472

467473
if (args)
468474
vprintk(args->fmt, args->args);
@@ -479,41 +485,46 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
479485
}
480486

481487
print_modules();
482-
dump_stack();
488+
489+
if (regs)
490+
show_regs(regs);
491+
else
492+
dump_stack();
493+
483494
print_oops_end_marker();
495+
484496
/* Just a warning, don't kill lockdep. */
485497
add_taint(taint, LOCKDEP_STILL_OK);
486498
}
487499

500+
#ifdef WANT_WARN_ON_SLOWPATH
488501
void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...)
489502
{
490-
struct slowpath_args args;
503+
struct warn_args args;
491504

492505
args.fmt = fmt;
493506
va_start(args.args, fmt);
494-
warn_slowpath_common(file, line, __builtin_return_address(0),
495-
TAINT_WARN, &args);
507+
__warn(file, line, __builtin_return_address(0), TAINT_WARN, NULL,
508+
&args);
496509
va_end(args.args);
497510
}
498511
EXPORT_SYMBOL(warn_slowpath_fmt);
499512

500513
void warn_slowpath_fmt_taint(const char *file, int line,
501514
unsigned taint, const char *fmt, ...)
502515
{
503-
struct slowpath_args args;
516+
struct warn_args args;
504517

505518
args.fmt = fmt;
506519
va_start(args.args, fmt);
507-
warn_slowpath_common(file, line, __builtin_return_address(0),
508-
taint, &args);
520+
__warn(file, line, __builtin_return_address(0), taint, NULL, &args);
509521
va_end(args.args);
510522
}
511523
EXPORT_SYMBOL(warn_slowpath_fmt_taint);
512524

513525
void warn_slowpath_null(const char *file, int line)
514526
{
515-
warn_slowpath_common(file, line, __builtin_return_address(0),
516-
TAINT_WARN, NULL);
527+
__warn(file, line, __builtin_return_address(0), TAINT_WARN, NULL, NULL);
517528
}
518529
EXPORT_SYMBOL(warn_slowpath_null);
519530
#endif

lib/bug.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -167,30 +167,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
167167

168168
if (warning) {
169169
/* this is a WARN_ON rather than BUG/BUG_ON */
170-
pr_warn("------------[ cut here ]------------\n");
171-
172-
if (file)
173-
pr_warn("WARNING: at %s:%u\n", file, line);
174-
else
175-
pr_warn("WARNING: at %p [verbose debug info unavailable]\n",
176-
(void *)bugaddr);
177-
178-
if (panic_on_warn) {
179-
/*
180-
* This thread may hit another WARN() in the panic path.
181-
* Resetting this prevents additional WARN() from
182-
* panicking the system on this thread. Other threads
183-
* are blocked by the panic_mutex in panic().
184-
*/
185-
panic_on_warn = 0;
186-
panic("panic_on_warn set ...\n");
187-
}
188-
189-
print_modules();
190-
show_regs(regs);
191-
print_oops_end_marker();
192-
/* Just a warning, don't kill lockdep. */
193-
add_taint(BUG_GET_TAINT(bug), LOCKDEP_STILL_OK);
170+
__warn(file, line, (void *)bugaddr, BUG_GET_TAINT(bug), regs,
171+
NULL);
194172
return BUG_TRAP_TYPE_WARN;
195173
}
196174

0 commit comments

Comments
 (0)