Skip to contentSkip to conversation

lockdep: fix seqlock_init()

PATCH In review Ingo Molnar 2 participants 5 messages Dec 12, 2006 – Dec 13, 2006 Locking primitives

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lockdep: fix seqlock_init()

Subject: [patch] lockdep: fix seqlock_init()
From: Ingo Molnar <[email protected]>

seqlock_init() needs to use spin_lock_init() for dynamic locks, so that lockdep is notified about the presence of a new lock.

(this is a fallout of the recent networking merge, which started using the so-far unused seqlock_init() API.)

This fix solves the following lockdep-internal warning on current -git:

INFO: trying to register non-static key.
the code is fine but needs lockdep annotation.
turning off the locking correctness validator.

  [<c0104fd9>] dump_trace+0x63/0x1e8
  [<c0105177>] show_trace_log_lvl+0x19/0x2e
  [<c010557e>] show_trace+0x12/0x14
  [<c0105594>] dump_stack+0x14/0x16
  [<c0142992>] __lock_acquire+0x10c/0x9f9
  [<c0143564>] lock_acquire+0x56/0x72
  [<c03c514f>] _spin_lock+0x35/0x42
  [<c0369875>] neigh_destroy+0x9d/0x12e
  [<c036a1d5>] neigh_periodic_timer+0x10a/0x15c
  [<c01302a5>] run_timer_softirq+0x126/0x18e
  [<c012c530>] __do_softirq+0x6b/0xe6
  [<c0106404>] do_softirq+0x64/0xd2
  [<c012c249>] ksoftirqd+0x82/0x138
  [<c01398f1>] kthread+0xb2/0xd7
  [<c0104c1b>] kernel_thread_helper+0x7/0x10
---
 include/linux/seqlock.h |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
include/linux/seqlock.h +5 -2
Index: linux-hres-timers.q/include/linux/seqlock.h
===================================================================
@@ -44,8 +44,11 @@ typedef struct {
 #define SEQLOCK_UNLOCKED \
 		 __SEQLOCK_UNLOCKED(old_style_seqlock_init)
 
-#define seqlock_init(x) \
-		do { *(x) = (seqlock_t) __SEQLOCK_UNLOCKED(x); } while (0)
+#define seqlock_init(x)					\
+	do {						\
+		(x)->sequence = 0;			\
+		spin_lock_init(&(x)->lock);		\
+	} while (0)
 
 #define DEFINE_SEQLOCK(x) \
 		seqlock_t x = __SEQLOCK_UNLOCKED(x)
#1 lore raw

include/linux/seqlock.h typedef struct { · line 51

Quoted 5 lines · On Tue, 12 Dec 2006 12:10:28 +0100 Ingo Molnar <[email protected]> wrote:
include/linux/seqlock.h +5 -0
+#define seqlock_init(x)					\
+	do {						\
+		(x)->sequence = 0;			\
+		spin_lock_init(&(x)->lock);		\
+	} while (0)

This does not have to be a macro, does it?

#2 lore raw
Quoted 10 lines · Andrew Morton

include/linux/seqlock.h typedef struct { · line 51

Quoted 5 lines · On Tue, 12 Dec 2006 12:10:28 +0100 Ingo Molnar <[email protected]> wrote:
include/linux/seqlock.h +5 -0
+#define seqlock_init(x)					\
+	do {						\
+		(x)->sequence = 0;			\
+		spin_lock_init(&(x)->lock);		\
+	} while (0)

This does not have to be a macro, does it?

Maybe it could be an __always_inline inline function (it has to be inlined to get the callsite based lock class key right) - but i'm not sure about the include file dependencies. Will probably work out fine as seqlock.h is supposed to be a late one in the order of inclusion - but i didnt want to make a blind bet.

Ingo

#3 lore raw
Quoted 14 lines · On Tue, 12 Dec 2006 21:50:01 +0100 Ingo Molnar <[email protected]> wrote:
Quoted 10 lines · Andrew Morton

include/linux/seqlock.h typedef struct { · line 51

Quoted 5 lines · On Tue, 12 Dec 2006 12:10:28 +0100 Ingo Molnar <[email protected]> wrote:
include/linux/seqlock.h +5 -0
+#define seqlock_init(x)					\
+	do {						\
+		(x)->sequence = 0;			\
+		spin_lock_init(&(x)->lock);		\
+	} while (0)

This does not have to be a macro, does it?

Quoted 2 lines

Maybe it could be an __always_inline inline function (it has to be inlined to get the callsite based lock class key right)

the compiler darn better inline it, else we'll have an out-of-line copy of everything in everywhere.

Quoted 4 lines

- but i'm not
sure about the include file dependencies. Will probably work out fine as seqlock.h is supposed to be a late one in the order of inclusion - but i didnt want to make a blind bet.

seqlock.h already includes spinlock.h.

#4 lore raw
Quoted 8 lines · Andrew Morton
Quoted 8 lines
Quoted 7 lines

include/linux/seqlock.h typedef struct { · line 51

Quoted 5 lines
include/linux/seqlock.h +5 -0
+#define seqlock_init(x)					\
+	do {						\
+		(x)->sequence = 0;			\
+		spin_lock_init(&(x)->lock);		\
+	} while (0)

This does not have to be a macro, does it?

Quoted 5 lines
Quoted 2 lines

Maybe it could be an __always_inline inline function (it has to be inlined to get the callsite based lock class key right)

the compiler darn better inline it, else we'll have an out-of-line copy of everything in everywhere.

the compiler will do the uninlining happily if it sees a size advantage (when a single .c module calls the function several times), and creates a private per-object-file uninlined function. So an __always_inline would definitely be needed.

Quoted 6 lines
Quoted 4 lines

- but i'm not
sure about the include file dependencies. Will probably work out fine as seqlock.h is supposed to be a late one in the order of inclusion - but i didnt want to make a blind bet.

seqlock.h already includes spinlock.h.

yes ... i just preserved the status quo.

Ingo