aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2010-04-03 14:34:56 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2010-05-19 03:36:48 -0400
commitb2be05273a1744d175bf4b67f6665637bb9ac7a8 (patch)
treec0b6333fbc7a1834bfc0eec86dd204b1daacf1b4
parent8954da1f82a468deeeae3683252b5440e7f4ccbe (diff)
panic: Allow warnings to set different taint flags
WARN() is used in some places to report firmware or hardware bugs that are then worked-around. These bugs do not affect the stability of the kernel and should not set the flag for TAINT_WARN. To allow for this, add WARN_TAINT() and WARN_TAINT_ONCE() macros that take a taint number as argument. Architectures that implement warnings using trap instructions instead of calls to warn_slowpath_*() now implement __WARN_TAINT(taint) instead of __WARN(). Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Acked-by: Helge Deller <deller@gmx.de> Tested-by: Paul Mundt <lethal@linux-sh.org> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
-rw-r--r--Documentation/oops-tracing.txt1
-rw-r--r--arch/parisc/include/asm/bug.h8
-rw-r--r--arch/powerpc/include/asm/bug.h6
-rw-r--r--arch/s390/include/asm/bug.h8
-rw-r--r--arch/sh/include/asm/bug.h4
-rw-r--r--include/asm-generic/bug.h34
-rw-r--r--kernel/panic.c24
-rw-r--r--lib/bug.c2
8 files changed, 67 insertions, 20 deletions
diff --git a/Documentation/oops-tracing.txt b/Documentation/oops-tracing.txt
index c10c022b911c..069fab3ea4d6 100644
--- a/Documentation/oops-tracing.txt
+++ b/Documentation/oops-tracing.txt
@@ -256,6 +256,7 @@ characters, each representing a particular tainted value.
256 9: 'A' if the ACPI table has been overridden. 256 9: 'A' if the ACPI table has been overridden.
257 257
258 10: 'W' if a warning has previously been issued by the kernel. 258 10: 'W' if a warning has previously been issued by the kernel.
259 (Though some warnings may set more specific taint flags.)
259 260
260 11: 'C' if a staging driver has been loaded. 261 11: 'C' if a staging driver has been loaded.
261 262
diff --git a/arch/parisc/include/asm/bug.h b/arch/parisc/include/asm/bug.h
index 75e46c557a16..72cfdb0cfdd1 100644
--- a/arch/parisc/include/asm/bug.h
+++ b/arch/parisc/include/asm/bug.h
@@ -44,7 +44,7 @@
44#endif 44#endif
45 45
46#ifdef CONFIG_DEBUG_BUGVERBOSE 46#ifdef CONFIG_DEBUG_BUGVERBOSE
47#define __WARN() \ 47#define __WARN_TAINT(taint) \
48 do { \ 48 do { \
49 asm volatile("\n" \ 49 asm volatile("\n" \
50 "1:\t" PARISC_BUG_BREAK_ASM "\n" \ 50 "1:\t" PARISC_BUG_BREAK_ASM "\n" \
@@ -54,11 +54,11 @@
54 "\t.org 2b+%c3\n" \ 54 "\t.org 2b+%c3\n" \
55 "\t.popsection" \ 55 "\t.popsection" \
56 : : "i" (__FILE__), "i" (__LINE__), \ 56 : : "i" (__FILE__), "i" (__LINE__), \
57 "i" (BUGFLAG_WARNING), \ 57 "i" (BUGFLAG_TAINT(taint)), \
58 "i" (sizeof(struct bug_entry)) ); \ 58 "i" (sizeof(struct bug_entry)) ); \
59 } while(0) 59 } while(0)
60#else 60#else
61#define __WARN() \ 61#define __WARN_TAINT(taint) \
62 do { \ 62 do { \
63 asm volatile("\n" \ 63 asm volatile("\n" \
64 "1:\t" PARISC_BUG_BREAK_ASM "\n" \ 64 "1:\t" PARISC_BUG_BREAK_ASM "\n" \
@@ -67,7 +67,7 @@
67 "\t.short %c0\n" \ 67 "\t.short %c0\n" \
68 "\t.org 2b+%c1\n" \ 68 "\t.org 2b+%c1\n" \
69 "\t.popsection" \ 69 "\t.popsection" \
70 : : "i" (BUGFLAG_WARNING), \ 70 : : "i" (BUGFLAG_TAINT(taint)), \
71 "i" (sizeof(struct bug_entry)) ); \ 71 "i" (sizeof(struct bug_entry)) ); \
72 } while(0) 72 } while(0)
73#endif 73#endif
diff --git a/arch/powerpc/include/asm/bug.h b/arch/powerpc/include/asm/bug.h
index 2c15212e1700..065c590c991d 100644
--- a/arch/powerpc/include/asm/bug.h
+++ b/arch/powerpc/include/asm/bug.h
@@ -85,12 +85,12 @@
85 } \ 85 } \
86} while (0) 86} while (0)
87 87
88#define __WARN() do { \ 88#define __WARN_TAINT(taint) do { \
89 __asm__ __volatile__( \ 89 __asm__ __volatile__( \
90 "1: twi 31,0,0\n" \ 90 "1: twi 31,0,0\n" \
91 _EMIT_BUG_ENTRY \ 91 _EMIT_BUG_ENTRY \
92 : : "i" (__FILE__), "i" (__LINE__), \ 92 : : "i" (__FILE__), "i" (__LINE__), \
93 "i" (BUGFLAG_WARNING), \ 93 "i" (BUGFLAG_TAINT(taint)), \
94 "i" (sizeof(struct bug_entry))); \ 94 "i" (sizeof(struct bug_entry))); \
95} while (0) 95} while (0)
96 96
@@ -104,7 +104,7 @@
104 "1: "PPC_TLNEI" %4,0\n" \ 104 "1: "PPC_TLNEI" %4,0\n" \
105 _EMIT_BUG_ENTRY \ 105 _EMIT_BUG_ENTRY \
106 : : "i" (__FILE__), "i" (__LINE__), \ 106 : : "i" (__FILE__), "i" (__LINE__), \
107 "i" (BUGFLAG_WARNING), \ 107 "i" (BUGFLAG_TAINT(TAINT_WARN)), \
108 "i" (sizeof(struct bug_entry)), \ 108 "i" (sizeof(struct bug_entry)), \
109 "r" (__ret_warn_on)); \ 109 "r" (__ret_warn_on)); \
110 } \ 110 } \
diff --git a/arch/s390/include/asm/bug.h b/arch/s390/include/asm/bug.h
index 9beeb9db9b23..bf90d1fd97a5 100644
--- a/arch/s390/include/asm/bug.h
+++ b/arch/s390/include/asm/bug.h
@@ -46,18 +46,18 @@
46 unreachable(); \ 46 unreachable(); \
47} while (0) 47} while (0)
48 48
49#define __WARN() do { \ 49#define __WARN_TAINT(taint) do { \
50 __EMIT_BUG(BUGFLAG_WARNING); \ 50 __EMIT_BUG(BUGFLAG_TAINT(taint)); \
51} while (0) 51} while (0)
52 52
53#define WARN_ON(x) ({ \ 53#define WARN_ON(x) ({ \
54 int __ret_warn_on = !!(x); \ 54 int __ret_warn_on = !!(x); \
55 if (__builtin_constant_p(__ret_warn_on)) { \ 55 if (__builtin_constant_p(__ret_warn_on)) { \
56 if (__ret_warn_on) \ 56 if (__ret_warn_on) \
57 __EMIT_BUG(BUGFLAG_WARNING); \ 57 __WARN(); \
58 } else { \ 58 } else { \
59 if (unlikely(__ret_warn_on)) \ 59 if (unlikely(__ret_warn_on)) \
60 __EMIT_BUG(BUGFLAG_WARNING); \ 60 __WARN(); \
61 } \ 61 } \
62 unlikely(__ret_warn_on); \ 62 unlikely(__ret_warn_on); \
63}) 63})
diff --git a/arch/sh/include/asm/bug.h b/arch/sh/include/asm/bug.h
index d02c01b3e6b9..6323f864d111 100644
--- a/arch/sh/include/asm/bug.h
+++ b/arch/sh/include/asm/bug.h
@@ -48,7 +48,7 @@ do { \
48 "i" (sizeof(struct bug_entry))); \ 48 "i" (sizeof(struct bug_entry))); \
49} while (0) 49} while (0)
50 50
51#define __WARN() \ 51#define __WARN_TAINT(taint) \
52do { \ 52do { \
53 __asm__ __volatile__ ( \ 53 __asm__ __volatile__ ( \
54 "1:\t.short %O0\n" \ 54 "1:\t.short %O0\n" \
@@ -57,7 +57,7 @@ do { \
57 : "n" (TRAPA_BUG_OPCODE), \ 57 : "n" (TRAPA_BUG_OPCODE), \
58 "i" (__FILE__), \ 58 "i" (__FILE__), \
59 "i" (__LINE__), \ 59 "i" (__LINE__), \
60 "i" (BUGFLAG_WARNING), \ 60 "i" (BUGFLAG_TAINT(taint)), \
61 "i" (sizeof(struct bug_entry))); \ 61 "i" (sizeof(struct bug_entry))); \
62} while (0) 62} while (0)
63 63
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 18c435d7c082..c2c9ba032d46 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -25,7 +25,10 @@ struct bug_entry {
25}; 25};
26#endif /* __ASSEMBLY__ */ 26#endif /* __ASSEMBLY__ */
27 27
28#define BUGFLAG_WARNING (1<<0) 28#define BUGFLAG_WARNING (1 << 0)
29#define BUGFLAG_TAINT(taint) (BUGFLAG_WARNING | ((taint) << 8))
30#define BUG_GET_TAINT(bug) ((bug)->flags >> 8)
31
29#endif /* CONFIG_GENERIC_BUG */ 32#endif /* CONFIG_GENERIC_BUG */
30 33
31/* 34/*
@@ -56,17 +59,25 @@ struct bug_entry {
56 * appear at runtime. Use the versions with printk format strings 59 * appear at runtime. Use the versions with printk format strings
57 * to provide better diagnostics. 60 * to provide better diagnostics.
58 */ 61 */
59#ifndef __WARN 62#ifndef __WARN_TAINT
60#ifndef __ASSEMBLY__ 63#ifndef __ASSEMBLY__
61extern void warn_slowpath_fmt(const char *file, const int line, 64extern void warn_slowpath_fmt(const char *file, const int line,
62 const char *fmt, ...) __attribute__((format(printf, 3, 4))); 65 const char *fmt, ...) __attribute__((format(printf, 3, 4)));
66extern void warn_slowpath_fmt_taint(const char *file, const int line,
67 unsigned taint, const char *fmt, ...)
68 __attribute__((format(printf, 4, 5)));
63extern void warn_slowpath_null(const char *file, const int line); 69extern void warn_slowpath_null(const char *file, const int line);
64#define WANT_WARN_ON_SLOWPATH 70#define WANT_WARN_ON_SLOWPATH
65#endif 71#endif
66#define __WARN() warn_slowpath_null(__FILE__, __LINE__) 72#define __WARN() warn_slowpath_null(__FILE__, __LINE__)
67#define __WARN_printf(arg...) warn_slowpath_fmt(__FILE__, __LINE__, arg) 73#define __WARN_printf(arg...) warn_slowpath_fmt(__FILE__, __LINE__, arg)
74#define __WARN_printf_taint(taint, arg...) \
75 warn_slowpath_fmt_taint(__FILE__, __LINE__, taint, arg)
68#else 76#else
77#define __WARN() __WARN_TAINT(TAINT_WARN)
69#define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0) 78#define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0)
79#define __WARN_printf_taint(taint, arg...) \
80 do { printk(arg); __WARN_TAINT(taint); } while (0)
70#endif 81#endif
71 82
72#ifndef WARN_ON 83#ifndef WARN_ON
@@ -87,6 +98,13 @@ extern void warn_slowpath_null(const char *file, const int line);
87}) 98})
88#endif 99#endif
89 100
101#define WARN_TAINT(condition, taint, format...) ({ \
102 int __ret_warn_on = !!(condition); \
103 if (unlikely(__ret_warn_on)) \
104 __WARN_printf_taint(taint, format); \
105 unlikely(__ret_warn_on); \
106})
107
90#else /* !CONFIG_BUG */ 108#else /* !CONFIG_BUG */
91#ifndef HAVE_ARCH_BUG 109#ifndef HAVE_ARCH_BUG
92#define BUG() do {} while(0) 110#define BUG() do {} while(0)
@@ -110,6 +128,8 @@ extern void warn_slowpath_null(const char *file, const int line);
110}) 128})
111#endif 129#endif
112 130
131#define WARN_TAINT(condition, taint, format...) WARN_ON(condition)
132
113#endif 133#endif
114 134
115#define WARN_ON_ONCE(condition) ({ \ 135#define WARN_ON_ONCE(condition) ({ \
@@ -132,6 +152,16 @@ extern void warn_slowpath_null(const char *file, const int line);
132 unlikely(__ret_warn_once); \ 152 unlikely(__ret_warn_once); \
133}) 153})
134 154
155#define WARN_TAINT_ONCE(condition, taint, format...) ({ \
156 static bool __warned; \
157 int __ret_warn_once = !!(condition); \
158 \
159 if (unlikely(__ret_warn_once)) \
160 if (WARN_TAINT(!__warned, taint, format)) \
161 __warned = true; \
162 unlikely(__ret_warn_once); \
163})
164
135#define WARN_ON_RATELIMIT(condition, state) \ 165#define WARN_ON_RATELIMIT(condition, state) \
136 WARN_ON((condition) && __ratelimit(state)) 166 WARN_ON((condition) && __ratelimit(state))
137 167
diff --git a/kernel/panic.c b/kernel/panic.c
index 13d966b4c14a..8b821bce66e6 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -365,7 +365,8 @@ struct slowpath_args {
365 va_list args; 365 va_list args;
366}; 366};
367 367
368static void warn_slowpath_common(const char *file, int line, void *caller, struct slowpath_args *args) 368static void warn_slowpath_common(const char *file, int line, void *caller,
369 unsigned taint, struct slowpath_args *args)
369{ 370{
370 const char *board; 371 const char *board;
371 372
@@ -381,7 +382,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller, struc
381 print_modules(); 382 print_modules();
382 dump_stack(); 383 dump_stack();
383 print_oops_end_marker(); 384 print_oops_end_marker();
384 add_taint(TAINT_WARN); 385 add_taint(taint);
385} 386}
386 387
387void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...) 388void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...)
@@ -390,14 +391,29 @@ void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...)
390 391
391 args.fmt = fmt; 392 args.fmt = fmt;
392 va_start(args.args, fmt); 393 va_start(args.args, fmt);
393 warn_slowpath_common(file, line, __builtin_return_address(0), &args); 394 warn_slowpath_common(file, line, __builtin_return_address(0),
395 TAINT_WARN, &args);
394 va_end(args.args); 396 va_end(args.args);
395} 397}
396EXPORT_SYMBOL(warn_slowpath_fmt); 398EXPORT_SYMBOL(warn_slowpath_fmt);
397 399
400void warn_slowpath_fmt_taint(const char *file, int line,
401 unsigned taint, const char *fmt, ...)
402{
403 struct slowpath_args args;
404
405 args.fmt = fmt;
406 va_start(args.args, fmt);
407 warn_slowpath_common(file, line, __builtin_return_address(0),
408 taint, &args);
409 va_end(args.args);
410}
411EXPORT_SYMBOL(warn_slowpath_fmt_taint);
412
398void warn_slowpath_null(const char *file, int line) 413void warn_slowpath_null(const char *file, int line)
399{ 414{
400 warn_slowpath_common(file, line, __builtin_return_address(0), NULL); 415 warn_slowpath_common(file, line, __builtin_return_address(0),
416 TAINT_WARN, NULL);
401} 417}
402EXPORT_SYMBOL(warn_slowpath_null); 418EXPORT_SYMBOL(warn_slowpath_null);
403#endif 419#endif
diff --git a/lib/bug.c b/lib/bug.c
index 300e41afbf97..f13daf435211 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -165,7 +165,7 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
165 (void *)bugaddr); 165 (void *)bugaddr);
166 166
167 show_regs(regs); 167 show_regs(regs);
168 add_taint(TAINT_WARN); 168 add_taint(BUG_GET_TAINT(bug));
169 return BUG_TRAP_TYPE_WARN; 169 return BUG_TRAP_TYPE_WARN;
170 } 170 }
171 171