Thread (13 messages) 13 messages, 4 authors, 2008-01-21
STALE6743d

[PATCH 7/7] percpu: Add debug detection of uninitialized usage of per_cpu variable

From: <hidden>
Date: 2008-01-18 18:32:03
Also in: lkml

Provide a means to trap usages of per_cpu variables before
the per_cpu_areas are setup.  Define CONFIG_DEBUG_PER_CPU to activate.

Signed-off-by: Mike Travis <redacted>
---
 include/asm-generic/percpu.h |   11 ++++++++++-
 lib/Kconfig.debug            |   12 ++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
--- a/include/asm-generic/percpu.h
+++ b/include/asm-generic/percpu.h
@@ -47,12 +47,21 @@ extern unsigned long __per_cpu_offset[NR
 #endif
 
 /*
- * A percpu variable may point to a discarded reghions. The following are
+ * A percpu variable may point to a discarded regions. The following are
  * established ways to produce a usable pointer from the percpu variable
  * offset.
  */
+#ifdef	CONFIG_DEBUG_PER_CPU
+#define per_cpu(var, cpu) (*({		\
+	if(!per_cpu_offset(cpu)) {	\
+		printk("KERN_NOTICE per_cpu(%s,%d): not available!\n", #var, (int)cpu); \
+		BUG();			\
+	}				\
+	SHIFT_PERCPU_PTR(&per_cpu_var(var), per_cpu_offset(cpu));}))
+#else
 #define per_cpu(var, cpu) \
 	(*SHIFT_PERCPU_PTR(&per_cpu_var(var), per_cpu_offset(cpu)))
+#endif
 #define __get_cpu_var(var) \
 	(*SHIFT_PERCPU_PTR(&per_cpu_var(var), my_cpu_offset))
 #define __raw_get_cpu_var(var) \
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -610,6 +610,18 @@ config PROVIDE_OHCI1394_DMA_INIT
 
 	  See Documentation/debugging-via-ohci1394.txt for more information.
 
+config DEBUG_PER_CPU
+	bool "Debug per_cpu usage"
+	depends on DEBUG_KERNEL
+	depends on SMP
+	default n
+	help
+	  Say Y here to add code that verifies the per_cpu area is
+	  setup before accessing a per_cpu variable.  It does add a
+	  significant amount of code to kernel memory.
+
+	  If unsure, say N.
+
 source "samples/Kconfig"
 
 source "lib/Kconfig.kgdb"
-- 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help