Skip to content

Commit b2be052

Browse files
bwhacksDavid Woodhouse
authored andcommitted
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>
1 parent 8954da1 commit b2be052

8 files changed

Lines changed: 67 additions & 20 deletions

File tree

‎Documentation/oops-tracing.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ characters, each representing a particular tainted value.
256256
9: 'A' if the ACPI table has been overridden.
257257

258258
10: 'W' if a warning has previously been issued by the kernel.
259+
(Though some warnings may set more specific taint flags.)
259260

260261
11: 'C' if a staging driver has been loaded.
261262

‎arch/parisc/include/asm/bug.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#endif
4545

4646
#ifdef CONFIG_DEBUG_BUGVERBOSE
47-
#define __WARN() \
47+
#define __WARN_TAINT(taint) \
4848
do { \
4949
asm volatile("\n" \
5050
"1:\t" PARISC_BUG_BREAK_ASM "\n" \
@@ -54,11 +54,11 @@
5454
"\t.org 2b+%c3\n" \
5555
"\t.popsection" \
5656
: : "i" (__FILE__), "i" (__LINE__), \
57-
"i" (BUGFLAG_WARNING), \
57+
"i" (BUGFLAG_TAINT(taint)), \
5858
"i" (sizeof(struct bug_entry)) ); \
5959
} while(0)
6060
#else
61-
#define __WARN() \
61+
#define __WARN_TAINT(taint) \
6262
do { \
6363
asm volatile("\n" \
6464
"1:\t" PARISC_BUG_BREAK_ASM "\n" \
@@ -67,7 +67,7 @@
6767
"\t.short %c0\n" \
6868
"\t.org 2b+%c1\n" \
6969
"\t.popsection" \
70-
: : "i" (BUGFLAG_WARNING), \
70+
: : "i" (BUGFLAG_TAINT(taint)), \
7171
"i" (sizeof(struct bug_entry)) ); \
7272
} while(0)
7373
#endif

‎arch/powerpc/include/asm/bug.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@
8585
} \
8686
} while (0)
8787

88-
#define __WARN() do { \
88+
#define __WARN_TAINT(taint) do { \
8989
__asm__ __volatile__( \
9090
"1: twi 31,0,0\n" \
9191
_EMIT_BUG_ENTRY \
9292
: : "i" (__FILE__), "i" (__LINE__), \
93-
"i" (BUGFLAG_WARNING), \
93+
"i" (BUGFLAG_TAINT(taint)), \
9494
"i" (sizeof(struct bug_entry))); \
9595
} while (0)
9696

@@ -104,7 +104,7 @@
104104
"1: "PPC_TLNEI" %4,0\n" \
105105
_EMIT_BUG_ENTRY \
106106
: : "i" (__FILE__), "i" (__LINE__), \
107-
"i" (BUGFLAG_WARNING), \
107+
"i" (BUGFLAG_TAINT(TAINT_WARN)), \
108108
"i" (sizeof(struct bug_entry)), \
109109
"r" (__ret_warn_on)); \
110110
} \

‎arch/s390/include/asm/bug.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@
4646
unreachable(); \
4747
} while (0)
4848

49-
#define __WARN() do { \
50-
__EMIT_BUG(BUGFLAG_WARNING); \
49+
#define __WARN_TAINT(taint) do { \
50+
__EMIT_BUG(BUGFLAG_TAINT(taint)); \
5151
} while (0)
5252

5353
#define WARN_ON(x) ({ \
5454
int __ret_warn_on = !!(x); \
5555
if (__builtin_constant_p(__ret_warn_on)) { \
5656
if (__ret_warn_on) \
57-
__EMIT_BUG(BUGFLAG_WARNING); \
57+
__WARN(); \
5858
} else { \
5959
if (unlikely(__ret_warn_on)) \
60-
__EMIT_BUG(BUGFLAG_WARNING); \
60+
__WARN(); \
6161
} \
6262
unlikely(__ret_warn_on); \
6363
})

‎arch/sh/include/asm/bug.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ do { \
4848
"i" (sizeof(struct bug_entry))); \
4949
} while (0)
5050

51-
#define __WARN() \
51+
#define __WARN_TAINT(taint) \
5252
do { \
5353
__asm__ __volatile__ ( \
5454
"1:\t.short %O0\n" \
@@ -57,7 +57,7 @@ do { \
5757
: "n" (TRAPA_BUG_OPCODE), \
5858
"i" (__FILE__), \
5959
"i" (__LINE__), \
60-
"i" (BUGFLAG_WARNING), \
60+
"i" (BUGFLAG_TAINT(taint)), \
6161
"i" (sizeof(struct bug_entry))); \
6262
} while (0)
6363

‎include/asm-generic/bug.h‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ struct bug_entry {
2525
};
2626
#endif /* __ASSEMBLY__ */
2727

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+
2932
#endif /* CONFIG_GENERIC_BUG */
3033

3134
/*
@@ -56,17 +59,25 @@ struct bug_entry {
5659
* appear at runtime. Use the versions with printk format strings
5760
* to provide better diagnostics.
5861
*/
59-
#ifndef __WARN
62+
#ifndef __WARN_TAINT
6063
#ifndef __ASSEMBLY__
6164
extern void warn_slowpath_fmt(const char *file, const int line,
6265
const char *fmt, ...) __attribute__((format(printf, 3, 4)));
66+
extern void warn_slowpath_fmt_taint(const char *file, const int line,
67+
unsigned taint, const char *fmt, ...)
68+
__attribute__((format(printf, 4, 5)));
6369
extern void warn_slowpath_null(const char *file, const int line);
6470
#define WANT_WARN_ON_SLOWPATH
6571
#endif
6672
#define __WARN() warn_slowpath_null(__FILE__, __LINE__)
6773
#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)
6876
#else
77+
#define __WARN() __WARN_TAINT(TAINT_WARN)
6978
#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)
7081
#endif
7182

7283
#ifndef WARN_ON
@@ -87,6 +98,13 @@ extern void warn_slowpath_null(const char *file, const int line);
8798
})
8899
#endif
89100

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+
90108
#else /* !CONFIG_BUG */
91109
#ifndef HAVE_ARCH_BUG
92110
#define BUG() do {} while(0)
@@ -110,6 +128,8 @@ extern void warn_slowpath_null(const char *file, const int line);
110128
})
111129
#endif
112130

131+
#define WARN_TAINT(condition, taint, format...) WARN_ON(condition)
132+
113133
#endif
114134

115135
#define WARN_ON_ONCE(condition) ({ \
@@ -132,6 +152,16 @@ extern void warn_slowpath_null(const char *file, const int line);
132152
unlikely(__ret_warn_once); \
133153
})
134154

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+
135165
#define WARN_ON_RATELIMIT(condition, state) \
136166
WARN_ON((condition) && __ratelimit(state))
137167

‎kernel/panic.c‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ struct slowpath_args {
365365
va_list args;
366366
};
367367

368-
static void warn_slowpath_common(const char *file, int line, void *caller, struct slowpath_args *args)
368+
static void warn_slowpath_common(const char *file, int line, void *caller,
369+
unsigned taint, struct slowpath_args *args)
369370
{
370371
const char *board;
371372

@@ -381,7 +382,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller, struc
381382
print_modules();
382383
dump_stack();
383384
print_oops_end_marker();
384-
add_taint(TAINT_WARN);
385+
add_taint(taint);
385386
}
386387

387388
void 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, ...)
390391

391392
args.fmt = fmt;
392393
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);
394396
va_end(args.args);
395397
}
396398
EXPORT_SYMBOL(warn_slowpath_fmt);
397399

400+
void 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+
}
411+
EXPORT_SYMBOL(warn_slowpath_fmt_taint);
412+
398413
void warn_slowpath_null(const char *file, int line)
399414
{
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);
401417
}
402418
EXPORT_SYMBOL(warn_slowpath_null);
403419
#endif

‎lib/bug.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
165165
(void *)bugaddr);
166166

167167
show_regs(regs);
168-
add_taint(TAINT_WARN);
168+
add_taint(BUG_GET_TAINT(bug));
169169
return BUG_TRAP_TYPE_WARN;
170170
}
171171

0 commit comments

Comments
 (0)