LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 1/1] Taint kernel after WARN_ON(condition)
@ 2008-02-11 19:52 Nur Hussein
  2008-02-11 20:20 ` Josef 'Jeff' Sipek
  2008-02-11 20:28 ` Randy Dunlap
  0 siblings, 2 replies; 3+ messages in thread
From: Nur Hussein @ 2008-02-11 19:52 UTC (permalink / raw)
  To: linux-kernel; +Cc: mingo, akpm, a.p.zijlstra

This patch will taint the kernel with a new flag, 'W', whenever a
warning is issued with WARN_ON(condition). Whenever a warning occurs, it
is helpful to record this within the kernel state as a taint. When a BUG
happens, it'd be useful to know if it was also preceded by a WARN.

This patch applies to Linus's git tree.

Signed-off-by: Nur Hussein (nurhussein@gmail.com)
---

diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 2632328..0633e96 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -42,8 +42,10 @@ extern void warn_on_slowpath(const char *file, const int line);
 #ifndef WARN_ON
 #define WARN_ON(condition) ({						\
 	int __ret_warn_on = !!(condition);				\
-	if (unlikely(__ret_warn_on))					\
+	if (unlikely(__ret_warn_on)) {					\
 		__WARN();						\
+		add_taint(TAINT_WARN);					\
+	}								\
 	unlikely(__ret_warn_on);					\
 })
 #endif
@@ -60,6 +62,8 @@ extern void warn_on_slowpath(const char *file, const int line);
 #ifndef HAVE_ARCH_WARN_ON
 #define WARN_ON(condition) ({						\
 	int __ret_warn_on = !!(condition);				\
+	if (unlikely(__ret_warn_on)) 					\
+		add_taint(TAINT_WARN);					\
 	unlikely(__ret_warn_on);					\
 })
 #endif
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 2df44e7..d90c1a4 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -255,6 +255,7 @@ extern enum system_states {
 #define TAINT_USER			(1<<6)
 #define TAINT_DIE			(1<<7)
 #define TAINT_OVERRIDDEN_ACPI_TABLE	(1<<8)
+#define TAINT_WARN			(1<<9)
 
 extern void dump_stack(void) __cold;
 
diff --git a/kernel/panic.c b/kernel/panic.c
index 24af9f8..e113a85 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -153,6 +153,8 @@ EXPORT_SYMBOL(panic);
  *  'M' - System experienced a machine check exception.
  *  'B' - System has hit bad_page.
  *  'U' - Userspace-defined naughtiness.
+ *  'A' - ACPI table overridden.
+ *  'W' - Taint on warning.
  *
  *	The string is overwritten by the next call to print_taint().
  */
@@ -161,7 +163,7 @@ const char *print_tainted(void)
 {
 	static char buf[20];
 	if (tainted) {
-		snprintf(buf, sizeof(buf), "Tainted: %c%c%c%c%c%c%c%c%c",
+		snprintf(buf, sizeof(buf), "Tainted: %c%c%c%c%c%c%c%c%c%c",
 			tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
 			tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
 			tainted & TAINT_UNSAFE_SMP ? 'S' : ' ',
@@ -170,7 +172,8 @@ const char *print_tainted(void)
 			tainted & TAINT_BAD_PAGE ? 'B' : ' ',
 			tainted & TAINT_USER ? 'U' : ' ',
 			tainted & TAINT_DIE ? 'D' : ' ',
-			tainted & TAINT_OVERRIDDEN_ACPI_TABLE ? 'A' : ' ');
+			tainted & TAINT_OVERRIDDEN_ACPI_TABLE ? 'A' : ' ',
+			tainted & TAINT_WARN ? 'W' : ' ');
 	}
 	else
 		snprintf(buf, sizeof(buf), "Not tainted");

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] Taint kernel after WARN_ON(condition)
  2008-02-11 19:52 [PATCH 1/1] Taint kernel after WARN_ON(condition) Nur Hussein
@ 2008-02-11 20:20 ` Josef 'Jeff' Sipek
  2008-02-11 20:28 ` Randy Dunlap
  1 sibling, 0 replies; 3+ messages in thread
From: Josef 'Jeff' Sipek @ 2008-02-11 20:20 UTC (permalink / raw)
  To: Nur Hussein; +Cc: linux-kernel, mingo, akpm, a.p.zijlstra, gregkh

On Tue, Feb 12, 2008 at 03:52:22AM +0800, Nur Hussein wrote:
> This patch will taint the kernel with a new flag, 'W', whenever a
> warning is issued with WARN_ON(condition). Whenever a warning occurs, it
> is helpful to record this within the kernel state as a taint. When a BUG
> happens, it'd be useful to know if it was also preceded by a WARN.

Any architecture that has it's own WARN_ON will not taint the kernel.

Speaking of WARN_ON...

$ git-grep "[^A-Za-z_0-9]WARN_ON(1)" | wc -l
180

Maybe making a WARN() (similar to BUG) that does an unconditional warning
(and sets the taint flag) and having a simple wrapper around it for the
conditional WARN_ON would be worth it? Hm...looks like some of the USB folks
have a #define'd WARN to something quite a bit more complex (format string,
etc.)

Josef 'Jeff' Sipek.

-- 
Linux, n.:
  Generous programmers from around the world all join forces to help
  you shoot yourself in the foot for free. 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] Taint kernel after WARN_ON(condition)
  2008-02-11 19:52 [PATCH 1/1] Taint kernel after WARN_ON(condition) Nur Hussein
  2008-02-11 20:20 ` Josef 'Jeff' Sipek
@ 2008-02-11 20:28 ` Randy Dunlap
  1 sibling, 0 replies; 3+ messages in thread
From: Randy Dunlap @ 2008-02-11 20:28 UTC (permalink / raw)
  To: Nur Hussein; +Cc: linux-kernel, mingo, akpm, a.p.zijlstra

On Tue, 12 Feb 2008 03:52:22 +0800 Nur Hussein wrote:

> This patch will taint the kernel with a new flag, 'W', whenever a
> warning is issued with WARN_ON(condition). Whenever a warning occurs, it
> is helpful to record this within the kernel state as a taint. When a BUG
> happens, it'd be useful to know if it was also preceded by a WARN.
> 
> This patch applies to Linus's git tree.
> 
> Signed-off-by: Nur Hussein (nurhussein@gmail.com)
> ---
> 
> diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
> index 2632328..0633e96 100644
> --- a/include/asm-generic/bug.h
> +++ b/include/asm-generic/bug.h
> @@ -42,8 +42,10 @@ extern void warn_on_slowpath(const char *file, const int line);
>  #ifndef WARN_ON
>  #define WARN_ON(condition) ({						\
>  	int __ret_warn_on = !!(condition);				\
> -	if (unlikely(__ret_warn_on))					\
> +	if (unlikely(__ret_warn_on)) {					\
>  		__WARN();						\
> +		add_taint(TAINT_WARN);					\
> +	}								\
>  	unlikely(__ret_warn_on);					\
>  })
>  #endif
> @@ -60,6 +62,8 @@ extern void warn_on_slowpath(const char *file, const int line);
>  #ifndef HAVE_ARCH_WARN_ON
>  #define WARN_ON(condition) ({						\
>  	int __ret_warn_on = !!(condition);				\
> +	if (unlikely(__ret_warn_on)) 					\
> +		add_taint(TAINT_WARN);					\
>  	unlikely(__ret_warn_on);					\
>  })
>  #endif
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index 2df44e7..d90c1a4 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -255,6 +255,7 @@ extern enum system_states {
>  #define TAINT_USER			(1<<6)
>  #define TAINT_DIE			(1<<7)
>  #define TAINT_OVERRIDDEN_ACPI_TABLE	(1<<8)
> +#define TAINT_WARN			(1<<9)
>  
>  extern void dump_stack(void) __cold;
>  
> diff --git a/kernel/panic.c b/kernel/panic.c
> index 24af9f8..e113a85 100644
> --- a/kernel/panic.c
> +++ b/kernel/panic.c
> @@ -153,6 +153,8 @@ EXPORT_SYMBOL(panic);
>   *  'M' - System experienced a machine check exception.
>   *  'B' - System has hit bad_page.
>   *  'U' - Userspace-defined naughtiness.
> + *  'A' - ACPI table overridden.
> + *  'W' - Taint on warning.
>   *

Oops.  Both 'A' and 'W' also need to be added to
Documentation/oops-tracing.txt, please.


>   *	The string is overwritten by the next call to print_taint().
>   */
> @@ -161,7 +163,7 @@ const char *print_tainted(void)
>  {
>  	static char buf[20];
>  	if (tainted) {
> -		snprintf(buf, sizeof(buf), "Tainted: %c%c%c%c%c%c%c%c%c",
> +		snprintf(buf, sizeof(buf), "Tainted: %c%c%c%c%c%c%c%c%c%c",
>  			tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
>  			tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
>  			tainted & TAINT_UNSAFE_SMP ? 'S' : ' ',
> @@ -170,7 +172,8 @@ const char *print_tainted(void)
>  			tainted & TAINT_BAD_PAGE ? 'B' : ' ',
>  			tainted & TAINT_USER ? 'U' : ' ',
>  			tainted & TAINT_DIE ? 'D' : ' ',
> -			tainted & TAINT_OVERRIDDEN_ACPI_TABLE ? 'A' : ' ');
> +			tainted & TAINT_OVERRIDDEN_ACPI_TABLE ? 'A' : ' ',
> +			tainted & TAINT_WARN ? 'W' : ' ');
>  	}
>  	else
>  		snprintf(buf, sizeof(buf), "Not tainted");
> --

---
~Randy

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-02-11 20:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-11 19:52 [PATCH 1/1] Taint kernel after WARN_ON(condition) Nur Hussein
2008-02-11 20:20 ` Josef 'Jeff' Sipek
2008-02-11 20:28 ` Randy Dunlap

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).