Skip to contentSkip to conversation

Fix uninitialized spinlock of printk_ratelimited()

PATCH In review OGAWA Hirofumi 2 participants 3 messages May 16, 2010 – May 19, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix uninitialized spinlock of printk_ratelimited()

ratelimit_state initialization of printk_ratelimited() seems broken. This fixes it by using DEFINE_RATELIMIT_STATE() to initialize spinlock properly.

---

 include/linux/kernel.h |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
include/linux/kernel.h renamed from include/linux/kernel.h~printk_ratelimited-fix +7 -8
diff -puN include/linux/kernel.h~printk_ratelimited-fix include/linux/kernel.h
@@ -420,14 +420,13 @@ static inline char *pack_hex_byte(char *
  * no local ratelimit_state used in the !PRINTK case
  */
 #ifdef CONFIG_PRINTK
-#define printk_ratelimited(fmt, ...)  ({		\
-	static struct ratelimit_state _rs = {		\
-		.interval = DEFAULT_RATELIMIT_INTERVAL, \
-		.burst = DEFAULT_RATELIMIT_BURST,       \
-	};                                              \
-							\
-	if (__ratelimit(&_rs))                          \
-		printk(fmt, ##__VA_ARGS__);		\
+#define printk_ratelimited(fmt, ...)  ({				\
+	static DEFINE_RATELIMIT_STATE(_rs,				\
+				      DEFAULT_RATELIMIT_INTERVAL,	\
+				      DEFAULT_RATELIMIT_BURST);		\
+									\
+	if (__ratelimit(&_rs))						\
+		printk(fmt, ##__VA_ARGS__);				\
 })
 #else
 /* No effect, but we still get type checking even in the !PRINTK case: */

_

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#1 lore raw
Quoted 23 lines · On Mon, 17 May 2010 08:57:38 +0900 OGAWA Hirofumi…

ratelimit_state initialization of printk_ratelimited() seems broken. This fixes it by using DEFINE_RATELIMIT_STATE() to initialize spinlock properly.

---

 include/linux/kernel.h |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff -puN include/linux/kernel.h~printk_ratelimited-fix include/linux/kernel.h

include/linux/kernel.h renamed from include/linux/kernel.h~printk_ratelimited-fix +0 -6
@@ -420,14 +420,13 @@ static inline char *pack_hex_byte(char *
  * no local ratelimit_state used in the !PRINTK case
  */
 #ifdef CONFIG_PRINTK
-#define printk_ratelimited(fmt, ...)  ({		\
-	static struct ratelimit_state _rs = {		\
-		.interval = DEFAULT_RATELIMIT_INTERVAL, \
-		.burst = DEFAULT_RATELIMIT_BURST,       \
-	};                                              \
-							\

include/linux/kernel.h static inline char *pack_hex_byte(char * · line 430

Quoted 10 lines
include/linux/kernel.h renamed from include/linux/kernel.h~printk_ratelimited-fix +7 -2
-	if (__ratelimit(&_rs))                          \
-		printk(fmt, ##__VA_ARGS__);		\
+#define printk_ratelimited(fmt, ...)  ({				\
+	static DEFINE_RATELIMIT_STATE(_rs,				\
+				      DEFAULT_RATELIMIT_INTERVAL,	\
+				      DEFAULT_RATELIMIT_BURST);		\
+									\
+	if (__ratelimit(&_rs))						\
+		printk(fmt, ##__VA_ARGS__);				\
 })

hm, yes, that spinlock will get the all-zeroes pattern.

It's been like this since December 2009. I'm a bit surprised that none of our spinlock-debugging goodies picked this up. All the CONFIG_DEBUG_SPINLOCK spinlock fields end up zeroed out also.

#2 lore raw
Quoted 20 lines · Andrew Morton
Quoted 7 lines

#ifdef CONFIG_PRINTK

include/linux/kernel.h renamed from include/linux/kernel.h~printk_ratelimited-fix +0 -6
-#define printk_ratelimited(fmt, ...)  ({		\
-	static struct ratelimit_state _rs = {		\
-		.interval = DEFAULT_RATELIMIT_INTERVAL, \
-		.burst = DEFAULT_RATELIMIT_BURST,       \
-	};                                              \
-							\

include/linux/kernel.h static inline char *pack_hex_byte(char * · line 430

Quoted 10 lines
include/linux/kernel.h renamed from include/linux/kernel.h~printk_ratelimited-fix +7 -2
-	if (__ratelimit(&_rs))                          \
-		printk(fmt, ##__VA_ARGS__);		\
+#define printk_ratelimited(fmt, ...)  ({				\
+	static DEFINE_RATELIMIT_STATE(_rs,				\
+				      DEFAULT_RATELIMIT_INTERVAL,	\
+				      DEFAULT_RATELIMIT_BURST);		\
+									\
+	if (__ratelimit(&_rs))						\
+		printk(fmt, ##__VA_ARGS__);				\
 })

hm, yes, that spinlock will get the all-zeroes pattern.

Quoted 3 lines

It's been like this since December 2009. I'm a bit surprised that none of our spinlock-debugging goodies picked this up. All the CONFIG_DEBUG_SPINLOCK spinlock fields end up zeroed out also.

The reason that dynamic analysis didn't pick up is simple - nobody is using this for now :)

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>