Skip to contentSkip to conversation

lock validator: -V3

PATCH In review Ingo Molnar 2 participants 3 messages Jun 6, 2006

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lock validator: -V3

Subject: lock validator: -V3
From: Ingo Molnar <[email protected]>

this patch contains items that had to be done in one go, so i guess i'll call this lock validator -V3, for lack of better name. (This goes to the tail of the current lock validator queue in -mm)

Changes:

added 'detect if freed' (or if reinitialized/destroyed when held) feature for all the lock types covered by the validator: spinlocks, rwlocks, mutexes and rwsems - using the same central lock debugging code. This feature was available for mutexes before, now it's in the generic 'lock debugging' code and hence extended to all lock types.

Accordingly, new lock debugging options are now available:

CONFIG_DEBUG_SPINLOCK_ALLOC=y
CONFIG_DEBUG_RWLOCK_ALLOC=y
CONFIG_DEBUG_MUTEX_ALLOC=y
CONFIG_DEBUG_RWSEM_ALLOC=y

Added 12 new testcases to the locking selftest, to make sure the new features are working.

I unified all the lock debugging options, they are now all structured
as: 'basic', 'free/exit checking' and 'full validation', and are dependent on each other. The lock types can be debugged independenty of each other.

I also resurrected SysRq-D (print all locks) support.

All in one, the structure of the lock debugging code is alot more consistent now, and all the lock debugging features are available across the spectrum.

I have tested this on x86 and x86_64, using various combinations of the new (and old) lock debugging options. Works fine here.

---
 drivers/char/sysrq.c              |    1 
 include/asm-i386/rwsem.h          |    4 
 include/linux/debug_locks.h       |   19 ++-
 include/linux/lockdep.h           |   73 +++++++++----
 include/linux/mutex.h             |    6 -
 include/linux/rwsem-spinlock.h    |    4 
 include/linux/rwsem.h             |    4 
 include/linux/sched.h             |    1 
 include/linux/spinlock.h          |   16 --
 include/linux/spinlock_types.h    |    8 -
 include/linux/spinlock_types_up.h |    8 -
 include/linux/spinlock_up.h       |    5 
 kernel/lockdep.c                  |  211 ++++++++++++++++++++++++++++++++------
 kernel/mutex-debug.c              |    6 -
 kernel/mutex-debug.h              |    3 
 kernel/mutex-lockdep.h            |   40 -------
 kernel/mutex.c                    |   17 ---
 kernel/mutex.h                    |    2 
 kernel/spinlock.c                 |   38 ------
 lib/Kconfig.debug                 |   98 ++++++++++++-----
 lib/locking-selftest-mutex.h      |    6 +
 lib/locking-selftest-rlock.h      |    9 +
 lib/locking-selftest-rsem.h       |    9 +
 lib/locking-selftest-spin.h       |    6 +
 lib/locking-selftest-wlock.h      |    9 +
 lib/locking-selftest-wsem.h       |    9 +
 lib/locking-selftest.c            |  107 +++++++++++++++++--
 lib/rwsem-spinlock.c              |   10 +
 lib/rwsem.c                       |   10 +
 lib/spinlock_debug.c              |   36 ++++++
 30 files changed, 545 insertions(+), 230 deletions(-)
drivers/char/sysrq.c +0 -1
Index: linux/drivers/char/sysrq.c
===================================================================
@@ -153,7 +153,6 @@ static void sysrq_handle_showlocks(int k
 				struct tty_struct *tty)
 {
 	debug_show_all_locks();
-	print_lock_types();
 }
 
 static struct sysrq_key_op sysrq_showlocks_op = {
include/asm-i386/rwsem.h +2 -2
Index: linux/include/asm-i386/rwsem.h
===================================================================
@@ -65,7 +65,7 @@ struct rw_semaphore {
 #if RWSEM_DEBUG
 	int			debug;
 #endif
-#ifdef CONFIG_PROVE_RWSEM_LOCKING
+#ifdef CONFIG_DEBUG_RWSEM_ALLOC
 	struct lockdep_map dep_map;
 #endif
 };
@@ -79,7 +79,7 @@ struct rw_semaphore {
 #define __RWSEM_DEBUG_INIT	/* */
 #endif
 
-#ifdef CONFIG_PROVE_RWSEM_LOCKING
+#ifdef CONFIG_DEBUG_RWSEM_ALLOC
 # define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
 #else
 # define __RWSEM_DEP_MAP_INIT(lockname)
include/linux/debug_locks.h +13 -6
Index: linux/include/linux/debug_locks.h
===================================================================
@@ -41,22 +41,29 @@ extern int debug_locks_off(void);
 # define locking_selftest()	do { } while (0)
 #endif
 
-static inline void
-debug_check_no_locks_freed(const void *from, unsigned long len)
+#ifdef CONFIG_LOCKDEP
+extern void debug_show_all_locks(void);
+extern void debug_show_held_locks(struct task_struct *task);
+extern void debug_check_no_locks_freed(const void *from, unsigned long len);
+extern void debug_check_no_locks_held(struct task_struct *task);
+#else
+static inline void debug_show_all_locks(void)
 {
 }
 
-static inline void
-debug_check_no_locks_held(struct task_struct *task)
+static inline void debug_show_held_locks(struct task_struct *task)
 {
 }
 
-static inline void debug_show_all_locks(void)
+static inline void
+debug_check_no_locks_freed(const void *from, unsigned long len)
 {
 }
 
-static inline void debug_show_held_locks(struct task_struct *task)
+static inline void
+debug_check_no_locks_held(struct task_struct *task)
 {
 }
+#endif
 
 #endif
include/linux/lockdep.h +55 -18

112 lines not on this page · raw message

include/linux/mutex.h +3 -3
Index: linux/include/linux/mutex.h
===================================================================
@@ -54,7 +54,7 @@ struct mutex {
 	const char 		*name;
 	void			*magic;
 #endif
-#ifdef CONFIG_PROVE_MUTEX_LOCKING
+#ifdef CONFIG_DEBUG_MUTEX_ALLOC
 	struct lockdep_map	dep_map;
 #endif
 };
@@ -85,7 +85,7 @@ do {							\
 # define mutex_destroy(mutex)				do { } while (0)
 #endif
 
-#ifdef CONFIG_PROVE_MUTEX_LOCKING
+#ifdef CONFIG_DEBUG_MUTEX_ALLOC
 # define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
 		, .dep_map = { .name = #lockname }
 #else
@@ -125,7 +125,7 @@ static inline int fastcall mutex_is_lock
 extern void fastcall mutex_lock(struct mutex *lock);
 extern int fastcall mutex_lock_interruptible(struct mutex *lock);
 
-#ifdef CONFIG_PROVE_MUTEX_LOCKING
+#ifdef CONFIG_DEBUG_MUTEX_ALLOC
 extern void mutex_lock_nested(struct mutex *lock, unsigned int subtype);
 #else
 # define mutex_lock_nested(lock, subtype) mutex_lock(lock)
include/linux/rwsem-spinlock.h +2 -2
Index: linux/include/linux/rwsem-spinlock.h
===================================================================
@@ -35,7 +35,7 @@ struct rw_semaphore {
 #if RWSEM_DEBUG
 	int			debug;
 #endif
-#ifdef CONFIG_PROVE_RWSEM_LOCKING
+#ifdef CONFIG_DEBUG_RWSEM_ALLOC
 	struct lockdep_map dep_map;
 #endif
 };
@@ -49,7 +49,7 @@ struct rw_semaphore {
 #define __RWSEM_DEBUG_INIT	/* */
 #endif
 
-#ifdef CONFIG_PROVE_RWSEM_LOCKING
+#ifdef CONFIG_DEBUG_RWSEM_ALLOC
 # define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
 #else
 # define __RWSEM_DEP_MAP_INIT(lockname)
include/linux/rwsem.h +2 -2
Index: linux/include/linux/rwsem.h
===================================================================
@@ -30,7 +30,7 @@ struct rw_semaphore;
  * Lockdep: type splitting can also be done for dynamic locks, if for
  * example there are per-CPU dynamically allocated locks:
  */
-#ifdef CONFIG_PROVE_RWSEM_LOCKING
+#ifdef CONFIG_DEBUG_RWSEM_ALLOC
 #define init_rwsem_key(sem, key)				\
 	__init_rwsem((sem), #sem, key)
 #else
@@ -100,7 +100,7 @@ static inline void down_write(struct rw_
 /*
  * lock for writing
  */
-#ifdef CONFIG_PROVE_RWSEM_LOCKING
+#ifdef CONFIG_DEBUG_RWSEM_ALLOC
 static inline void down_write_nested(struct rw_semaphore *sem, int subtype)
 {
 	might_sleep();
include/linux/sched.h +1 -0
Index: linux/include/linux/sched.h
===================================================================
@@ -940,6 +940,7 @@ struct task_struct {
 	struct held_lock held_locks[MAX_LOCK_DEPTH];
 #endif
 	unsigned int lockdep_recursion;
+	int lockdep_verbose;
 
 /* journalling filesystem info */
 	void *journal_info;
include/linux/spinlock.h +5 -11
Index: linux/include/linux/spinlock.h
===================================================================
@@ -88,7 +88,7 @@ extern int __lockfunc generic__raw_read_
 # include <linux/spinlock_up.h>
 #endif
 
-#if defined(CONFIG_DEBUG_SPINLOCK) || defined(CONFIG_PROVE_SPIN_LOCKING)
+#ifdef CONFIG_DEBUG_SPINLOCK
   extern void __spin_lock_init(spinlock_t *lock, const char *name,
 			       struct lockdep_type_key *key);
 # define spin_lock_init(lock)					\
@@ -123,7 +123,7 @@ do {								\
 	do { spin_lock_init(lock); (void)(key); } while (0)
 #endif
 
-#if defined(CONFIG_DEBUG_SPINLOCK) || defined(CONFIG_PROVE_RW_LOCKING)
+#ifdef CONFIG_DEBUG_SPINLOCK
   extern void __rwlock_init(rwlock_t *lock, const char *name,
 			    struct lockdep_type_key *key);
 # define rwlock_init(lock)					\
@@ -152,9 +152,7 @@ do {								\
 /*
  * Pull the _spin_*()/_read_*()/_write_*() functions/declarations:
  */
-#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) || \
-	defined(CONFIG_PROVE_SPIN_LOCKING) || \
-	defined(CONFIG_PROVE_RW_LOCKING)
+#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
 # include <linux/spinlock_api_smp.h>
 #else
 # include <linux/spinlock_api_up.h>
@@ -203,9 +201,7 @@ do {								\
 #define write_lock(lock)		_write_lock(lock)
 #define read_lock(lock)			_read_lock(lock)
 
-#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) || \
-	defined(CONFIG_PROVE_SPIN_LOCKING) || \
-	defined(CONFIG_PROVE_RW_LOCKING)
+#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
 #define spin_lock_irqsave(lock, flags)	flags = _spin_lock_irqsave(lock)
 #define read_lock_irqsave(lock, flags)	flags = _read_lock_irqsave(lock)
 #define write_lock_irqsave(lock, flags)	flags = _write_lock_irqsave(lock)
@@ -228,9 +224,7 @@ do {								\
  * We inline the unlock functions in the nondebug case:
  */
 #if defined(CONFIG_DEBUG_SPINLOCK) || defined(CONFIG_PREEMPT) || \
-	!defined(CONFIG_SMP) || \
-	defined(CONFIG_PROVE_SPIN_LOCKING) || \
-	defined(CONFIG_PROVE_RW_LOCKING)
+	!defined(CONFIG_SMP)
 # define spin_unlock(lock)		_spin_unlock(lock)
 # define spin_unlock_non_nested(lock)	_spin_unlock_non_nested(lock)
 # define read_unlock(lock)		_read_unlock(lock)
include/linux/spinlock_types.h +4 -4
Index: linux/include/linux/spinlock_types.h
===================================================================
@@ -26,7 +26,7 @@ typedef struct {
 	unsigned int magic, owner_cpu;
 	void *owner;
 #endif
-#ifdef CONFIG_PROVE_SPIN_LOCKING
+#ifdef CONFIG_DEBUG_SPINLOCK_ALLOC
 	struct lockdep_map dep_map;
 #endif
 } spinlock_t;
@@ -42,7 +42,7 @@ typedef struct {
 	unsigned int magic, owner_cpu;
 	void *owner;
 #endif
-#ifdef CONFIG_PROVE_RW_LOCKING
+#ifdef CONFIG_DEBUG_RWLOCK_ALLOC
 	struct lockdep_map dep_map;
 #endif
 } rwlock_t;
@@ -51,13 +51,13 @@ typedef struct {
 
 #define SPINLOCK_OWNER_INIT	((void *)-1L)
 
-#ifdef CONFIG_PROVE_SPIN_LOCKING
+#ifdef CONFIG_DEBUG_SPINLOCK_ALLOC
 # define SPIN_DEP_MAP_INIT(lockname)	.dep_map = { .name = #lockname }
 #else
 # define SPIN_DEP_MAP_INIT(lockname)
 #endif
 
-#ifdef CONFIG_PROVE_RW_LOCKING
+#ifdef CONFIG_DEBUG_RWLOCK_ALLOC
 # define RW_DEP_MAP_INIT(lockname)	.dep_map = { .name = #lockname }
 #else
 # define RW_DEP_MAP_INIT(lockname)
include/linux/spinlock_types_up.h +4 -4
Index: linux/include/linux/spinlock_types_up.h
===================================================================
@@ -13,12 +13,12 @@
  */
 
 #if defined(CONFIG_DEBUG_SPINLOCK) || \
-	defined(CONFIG_PROVE_SPIN_LOCKING) || \
-	defined(CONFIG_PROVE_RW_LOCKING)
+	defined(CONFIG_DEBUG_SPINLOCK_ALLOC) || \
+	defined(CONFIG_DEBUG_RWLOCK_ALLOC)
 
 typedef struct {
 	volatile unsigned int slock;
-#ifdef CONFIG_PROVE_SPIN_LOCKING
+#ifdef CONFIG_DEBUG_SPINLOCK_ALLOC
 	struct lockdep_map dep_map;
 #endif
 } raw_spinlock_t;
@@ -35,7 +35,7 @@ typedef struct { } raw_spinlock_t;
 
 typedef struct {
 	/* no debug version on UP */
-#ifdef CONFIG_PROVE_RW_LOCKING
+#ifdef CONFIG_DEBUG_RWLOCK_ALLOC
 	struct lockdep_map dep_map;
 #endif
 } raw_rwlock_t;
include/linux/spinlock_up.h +1 -4
Index: linux/include/linux/spinlock_up.h
===================================================================
@@ -17,10 +17,7 @@
  * No atomicity anywhere, we are on UP.
  */
 
-#if defined(CONFIG_DEBUG_SPINLOCK) || \
-	defined(CONFIG_PROVE_SPIN_LOCKING) || \
-	defined(CONFIG_PROVE_RW_LOCKING)
-
+#ifdef CONFIG_DEBUG_SPINLOCK
 #define __raw_spin_is_locked(x)		((x)->slock == 0)
 
 static inline void __raw_spin_lock(raw_spinlock_t *lock)
kernel/lockdep.c +179 -32

357 lines not on this page · raw message

kernel/mutex-debug.c +5 -1
Index: linux/kernel/mutex-debug.c
===================================================================
@@ -82,12 +82,16 @@ void debug_mutex_unlock(struct mutex *lo
 	DEBUG_WARN_ON(lock->owner != current_thread_info());
 }
 
-void debug_mutex_init(struct mutex *lock, const char *name)
+void debug_mutex_init(struct mutex *lock, const char *name,
+		      struct lockdep_type_key *key)
 {
+#ifdef CONFIG_DEBUG_MUTEX_ALLOC
 	/*
 	 * Make sure we are not reinitializing a held lock:
 	 */
 	debug_check_no_locks_freed((void *)lock, sizeof(*lock));
+	lockdep_init_map(&lock->dep_map, name, key);
+#endif
 	lock->owner = NULL;
 	lock->magic = lock;
 }
kernel/mutex-debug.h +2 -1
Index: linux/kernel/mutex-debug.h
===================================================================
@@ -32,7 +32,8 @@ extern void debug_mutex_add_waiter(struc
 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
 				struct thread_info *ti);
 extern void debug_mutex_unlock(struct mutex *lock);
-extern void debug_mutex_init(struct mutex *lock, const char *name);
+extern void debug_mutex_init(struct mutex *lock, const char *name,
+			     struct lockdep_type_key *key);
 
 #define spin_lock_mutex(lock, flags)			\
 	do {						\
kernel/mutex-lockdep.h deleted +0 -40
Index: linux/kernel/mutex-lockdep.h
===================================================================
@@ -1,40 +0,0 @@
-/*
- * Mutexes: blocking mutual exclusion locks
- *
- * started by Ingo Molnar:
- *
- *  Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <[email protected]>
- *
- * This file contains mutex debugging related internal prototypes, for the
- * !CONFIG_DEBUG_MUTEXES && CONFIG_PROVE_MUTEX_LOCKING case. Most of
- * them are NOPs:
- */
-
-#define spin_lock_mutex(lock, flags)			\
-	do {						\
-		local_irq_save(flags);			\
-		__raw_spin_lock(&(lock)->raw_lock);	\
-	} while (0)
-
-#define spin_unlock_mutex(lock, flags)			\
-	do {						\
-		__raw_spin_unlock(&(lock)->raw_lock);	\
-		local_irq_restore(flags);		\
-	} while (0)
-
-#define mutex_remove_waiter(lock, waiter, ti) \
-		__list_del((waiter)->list.prev, (waiter)->list.next)
-
-#define debug_mutex_set_owner(lock, new_owner)		do { } while (0)
-#define debug_mutex_clear_owner(lock)			do { } while (0)
-#define debug_mutex_wake_waiter(lock, waiter)		do { } while (0)
-#define debug_mutex_free_waiter(waiter)			do { } while (0)
-#define debug_mutex_add_waiter(lock, waiter, ti)	do { } while (0)
-#define debug_mutex_unlock(lock)			do { } while (0)
-#define debug_mutex_init(lock, name)			do { } while (0)
-
-static inline void
-debug_mutex_lock_common(struct mutex *lock,
-			struct mutex_waiter *waiter)
-{
-}
kernel/mutex.c +4 -13
Index: linux/kernel/mutex.c
===================================================================
@@ -27,13 +27,8 @@
 # include "mutex-debug.h"
 # include <asm-generic/mutex-null.h>
 #else
-# ifdef CONFIG_PROVE_MUTEX_LOCKING
-#  include "mutex-lockdep.h"
-#  include <asm-generic/mutex-null.h>
-# else
-#  include "mutex.h"
-#  include <asm/mutex.h>
-# endif
+# include "mutex.h"
+# include <asm/mutex.h>
 #endif
 
 /***
@@ -51,11 +46,7 @@ __mutex_init(struct mutex *lock, const c
 	spin_lock_init(&lock->wait_lock);
 	INIT_LIST_HEAD(&lock->wait_list);
 
-	debug_mutex_init(lock, name);
-
-#ifdef CONFIG_PROVE_MUTEX_LOCKING
-	lockdep_init_map(&lock->dep_map, name, key);
-#endif
+	debug_mutex_init(lock, name, key);
 }
 
 EXPORT_SYMBOL(__mutex_init);
@@ -225,7 +216,7 @@ __mutex_lock_slowpath(atomic_t *lock_cou
 	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0);
 }
 
-#ifdef CONFIG_PROVE_MUTEX_LOCKING
+#ifdef CONFIG_DEBUG_MUTEX_ALLOC
 void __sched
 mutex_lock_nested(struct mutex *lock, unsigned int subtype)
 {
kernel/mutex.h +1 -1
Index: linux/kernel/mutex.h
===================================================================
@@ -24,7 +24,7 @@
 #define debug_mutex_free_waiter(waiter)			do { } while (0)
 #define debug_mutex_add_waiter(lock, waiter, ti)	do { } while (0)
 #define debug_mutex_unlock(lock)			do { } while (0)
-#define debug_mutex_init(lock, name)			do { } while (0)
+#define debug_mutex_init(lock, name, key)		do { } while (0)
 
 static inline void
 debug_mutex_lock_common(struct mutex *lock, struct mutex_waiter *waiter)
kernel/spinlock.c +0 -38
Index: linux/kernel/spinlock.c
===================================================================
@@ -17,44 +17,6 @@
 #include <linux/debug_locks.h>
 #include <linux/module.h>
 
-#if defined(CONFIG_DEBUG_SPINLOCK) || defined(CONFIG_PROVE_SPIN_LOCKING)
-void __spin_lock_init(spinlock_t *lock, const char *name,
-		      struct lockdep_type_key *key)
-{
-	lock->raw_lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
-#ifdef CONFIG_DEBUG_SPINLOCK
-	lock->magic = SPINLOCK_MAGIC;
-	lock->owner = SPINLOCK_OWNER_INIT;
-	lock->owner_cpu = -1;
-#endif
-#ifdef CONFIG_PROVE_SPIN_LOCKING
-	lockdep_init_map(&lock->dep_map, name, key);
-#endif
-}
-
-EXPORT_SYMBOL(__spin_lock_init);
-
-#endif
-
-#if defined(CONFIG_DEBUG_SPINLOCK) || defined(CONFIG_PROVE_RW_LOCKING)
-
-void __rwlock_init(rwlock_t *lock, const char *name,
-		   struct lockdep_type_key *key)
-{
-	lock->raw_lock = (raw_rwlock_t) __RAW_RW_LOCK_UNLOCKED;
-#ifdef CONFIG_DEBUG_SPINLOCK
-	lock->magic = RWLOCK_MAGIC;
-	lock->owner = SPINLOCK_OWNER_INIT;
-	lock->owner_cpu = -1;
-#endif
-#ifdef CONFIG_PROVE_RW_LOCKING
-	lockdep_init_map(&lock->dep_map, name, key);
-#endif
-}
-
-EXPORT_SYMBOL(__rwlock_init);
-
-#endif
 /*
  * Generic declaration of the raw read_trylock() function,
  * architectures are supposed to optimize this:
lib/Kconfig.debug +68 -30

160 lines not on this page · raw message

lib/locking-selftest-mutex.h +6 -0
Index: linux/lib/locking-selftest-mutex.h
===================================================================
@@ -3,3 +3,9 @@
 
 #undef UNLOCK
 #define UNLOCK		MU
+
+#undef RLOCK
+#undef WLOCK
+
+#undef INIT
+#define INIT		MI
lib/locking-selftest-rlock.h +9 -0
Index: linux/lib/locking-selftest-rlock.h
===================================================================
@@ -3,3 +3,12 @@
 
 #undef UNLOCK
 #define UNLOCK		RU
+
+#undef RLOCK
+#define RLOCK		RL
+
+#undef WLOCK
+#define WLOCK		WL
+
+#undef INIT
+#define INIT		RWI
lib/locking-selftest-rsem.h +9 -0
Index: linux/lib/locking-selftest-rsem.h
===================================================================
@@ -3,3 +3,12 @@
 
 #undef UNLOCK
 #define UNLOCK		RSU
+
+#undef RLOCK
+#define RLOCK		RSL
+
+#undef WLOCK
+#define WLOCK		WSL
+
+#undef INIT
+#define INIT		RWSI
lib/locking-selftest-spin.h +6 -0
Index: linux/lib/locking-selftest-spin.h
===================================================================
@@ -3,3 +3,9 @@
 
 #undef UNLOCK
 #define UNLOCK		U
+
+#undef RLOCK
+#undef WLOCK
+
+#undef INIT
+#define INIT		SI
lib/locking-selftest-wlock.h +9 -0
Index: linux/lib/locking-selftest-wlock.h
===================================================================
@@ -3,3 +3,12 @@
 
 #undef UNLOCK
 #define UNLOCK		WU
+
+#undef RLOCK
+#define RLOCK		RL
+
+#undef WLOCK
+#define WLOCK		WL
+
+#undef INIT
+#define INIT		RWI
lib/locking-selftest-wsem.h +9 -0
Index: linux/lib/locking-selftest-wsem.h
===================================================================
@@ -3,3 +3,12 @@
 
 #undef UNLOCK
 #define UNLOCK		WSU
+
+#undef RLOCK
+#define RLOCK		RSL
+
+#undef WLOCK
+#define WLOCK		WSL
+
+#undef INIT
+#define INIT		RWSI
lib/locking-selftest.c +96 -11

188 lines not on this page · raw message

lib/rwsem-spinlock.c +7 -3
Index: linux/lib/rwsem-spinlock.c
===================================================================
@@ -33,15 +33,19 @@ void rwsemtrace(struct rw_semaphore *sem
 void __init_rwsem(struct rw_semaphore *sem, const char *name,
 		  struct lockdep_type_key *key)
 {
+#ifdef CONFIG_DEBUG_RWSEM_ALLOC
+	/*
+	 * Make sure we are not reinitializing a held semaphore:
+	 */
+	debug_check_no_locks_freed((void *)sem, sizeof(*sem));
+	lockdep_init_map(&sem->dep_map, name, key);
+#endif
 	sem->activity = 0;
 	spin_lock_init(&sem->wait_lock);
 	INIT_LIST_HEAD(&sem->wait_list);
 #if RWSEM_DEBUG
 	sem->debug = 0;
 #endif
-#ifdef CONFIG_PROVE_RWSEM_LOCKING
-	lockdep_init_map(&sem->dep_map, name, key);
-#endif
 }
 
 /*
lib/rwsem.c +7 -3
Index: linux/lib/rwsem.c
===================================================================
@@ -14,15 +14,19 @@
 void __init_rwsem(struct rw_semaphore *sem, const char *name,
 		  struct lockdep_type_key *key)
 {
+#ifdef CONFIG_DEBUG_RWSEM_ALLOC
+	/*
+	 * Make sure we are not reinitializing a held semaphore:
+	 */
+	debug_check_no_locks_freed((void *)sem, sizeof(*sem));
+	lockdep_init_map(&sem->dep_map, name, key);
+#endif
 	sem->count = RWSEM_UNLOCKED_VALUE;
 	spin_lock_init(&sem->wait_lock);
 	INIT_LIST_HEAD(&sem->wait_list);
 #if RWSEM_DEBUG
 	sem->debug = 0;
 #endif
-#ifdef CONFIG_PROVE_RWSEM_LOCKING
-	lockdep_init_map(&sem->dep_map, name, key);
-#endif
 }
 
 EXPORT_SYMBOL(__init_rwsem);
lib/spinlock_debug.c +36 -0
Index: linux/lib/spinlock_debug.c
===================================================================
@@ -13,6 +13,42 @@
 #include <linux/delay.h>
 #include <linux/module.h>
 
+void __spin_lock_init(spinlock_t *lock, const char *name,
+		      struct lockdep_type_key *key)
+{
+#ifdef CONFIG_DEBUG_SPINLOCK_ALLOC
+	/*
+	 * Make sure we are not reinitializing a held lock:
+	 */
+	debug_check_no_locks_freed((void *)lock, sizeof(*lock));
+	lockdep_init_map(&lock->dep_map, name, key);
+#endif
+	lock->raw_lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
+	lock->magic = SPINLOCK_MAGIC;
+	lock->owner = SPINLOCK_OWNER_INIT;
+	lock->owner_cpu = -1;
+}
+
+EXPORT_SYMBOL(__spin_lock_init);
+
+void __rwlock_init(rwlock_t *lock, const char *name,
+		   struct lockdep_type_key *key)
+{
+#ifdef CONFIG_DEBUG_RWLOCK_ALLOC
+	/*
+	 * Make sure we are not reinitializing a held lock:
+	 */
+	debug_check_no_locks_freed((void *)lock, sizeof(*lock));
+	lockdep_init_map(&lock->dep_map, name, key);
+#endif
+	lock->raw_lock = (raw_rwlock_t) __RAW_RW_LOCK_UNLOCKED;
+	lock->magic = RWLOCK_MAGIC;
+	lock->owner = SPINLOCK_OWNER_INIT;
+	lock->owner_cpu = -1;
+}
+
+EXPORT_SYMBOL(__rwlock_init);
+
 static void spin_bug(spinlock_t *lock, const char *msg)
 {
 	struct task_struct *owner = NULL;
#1 lore raw
Quoted 1 line · On Tue, 6 Jun 2006 17:45:30 +0200 Ingo Molnar <[email protected]> wrote:
 30 files changed, 545 insertions(+), 230 deletions(-)

This basically screws up the whole patch series. It'll create a barrier over which it will be hard to move fixups against existing patches.

ho-hum. Let's make sure that future patches are extremely fine-grained and please try to identify whether they're applicable to -v2 or to -v3 and we'll see how it goes.

#2 lore raw
Quoted 8 lines · Andrew Morton
Quoted 1 line · On Tue, 6 Jun 2006 17:45:30 +0200 Ingo Molnar <[email protected]> wrote:
 30 files changed, 545 insertions(+), 230 deletions(-)

This basically screws up the whole patch series. It'll create a barrier over which it will be hard to move fixups against existing patches.

yes. Dont worry about it, i'll refactor the whole lock validator queue once i've done the cleanups too.

Quoted 3 lines

ho-hum. Let's make sure that future patches are extremely fine-grained and please try to identify whether they're applicable to -v2 or to -v3 and we'll see how it goes.

there was just no other way to do this - this change is intrusive independently of how finegrained the patches are.

Ingo