Commit 9a11b49a authored by Ingo Molnar's avatar Ingo Molnar Committed by Linus Torvalds

[PATCH] lockdep: better lock debugging

Generic lock debugging:

 - generalized lock debugging framework. For example, a bug in one lock
   subsystem turns off debugging in all lock subsystems.

 - got rid of the caller address passing (__IP__/__IP_DECL__/etc.) from
   the mutex/rtmutex debugging code: it caused way too much prototype
   hackery, and lockdep will give the same information anyway.

 - ability to do silent tests

 - check lock freeing in vfree too.

 - more finegrained debugging options, to allow distributions to
   turn off more expensive debugging features.

There's no separate 'held mutexes' list anymore - but there's a 'held locks'
stack within lockdep, which unifies deadlock detection across all lock
classes.  (this is independent of the lockdep validation stuff - lockdep first
checks whether we are holding a lock already)

Here are the current debugging options:

CONFIG_DEBUG_MUTEXES=y
CONFIG_DEBUG_LOCK_ALLOC=y

which do:

 config DEBUG_MUTEXES
          bool "Mutex debugging, basic checks"

 config DEBUG_LOCK_ALLOC
         bool "Detect incorrect freeing of live mutexes"
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarArjan van de Ven <arjan@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent fb7e4241
...@@ -151,7 +151,7 @@ static struct sysrq_key_op sysrq_mountro_op = { ...@@ -151,7 +151,7 @@ static struct sysrq_key_op sysrq_mountro_op = {
static void sysrq_handle_showlocks(int key, struct pt_regs *pt_regs, static void sysrq_handle_showlocks(int key, struct pt_regs *pt_regs,
struct tty_struct *tty) struct tty_struct *tty)
{ {
mutex_debug_show_all_locks(); debug_show_all_locks();
} }
static struct sysrq_key_op sysrq_showlocks_op = { static struct sysrq_key_op sysrq_showlocks_op = {
.handler = sysrq_handle_showlocks, .handler = sysrq_handle_showlocks,
......
...@@ -10,15 +10,10 @@ ...@@ -10,15 +10,10 @@
#ifndef _ASM_GENERIC_MUTEX_NULL_H #ifndef _ASM_GENERIC_MUTEX_NULL_H
#define _ASM_GENERIC_MUTEX_NULL_H #define _ASM_GENERIC_MUTEX_NULL_H
/* extra parameter only needed for mutex debugging: */ #define __mutex_fastpath_lock(count, fail_fn) fail_fn(count)
#ifndef __IP__ #define __mutex_fastpath_lock_retval(count, fail_fn) fail_fn(count)
# define __IP__ #define __mutex_fastpath_unlock(count, fail_fn) fail_fn(count)
#endif #define __mutex_fastpath_trylock(count, fail_fn) fail_fn(count)
#define __mutex_slowpath_needs_to_unlock() 1
#define __mutex_fastpath_lock(count, fail_fn) fail_fn(count __RET_IP__)
#define __mutex_fastpath_lock_retval(count, fail_fn) fail_fn(count __RET_IP__)
#define __mutex_fastpath_unlock(count, fail_fn) fail_fn(count __RET_IP__)
#define __mutex_fastpath_trylock(count, fail_fn) fail_fn(count)
#define __mutex_slowpath_needs_to_unlock() 1
#endif #endif
#ifndef __LINUX_DEBUG_LOCKING_H
#define __LINUX_DEBUG_LOCKING_H
extern int debug_locks;
extern int debug_locks_silent;
/*
* Generic 'turn off all lock debugging' function:
*/
extern int debug_locks_off(void);
/*
* In the debug case we carry the caller's instruction pointer into
* other functions, but we dont want the function argument overhead
* in the nondebug case - hence these macros:
*/
#define _RET_IP_ (unsigned long)__builtin_return_address(0)
#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
#define DEBUG_LOCKS_WARN_ON(c) \
({ \
int __ret = 0; \
\
if (unlikely(c)) { \
if (debug_locks_off()) \
WARN_ON(1); \
__ret = 1; \
} \
__ret; \
})
#ifdef CONFIG_SMP
# define SMP_DEBUG_LOCKS_WARN_ON(c) DEBUG_LOCKS_WARN_ON(c)
#else
# define SMP_DEBUG_LOCKS_WARN_ON(c) do { } while (0)
#endif
#ifdef CONFIG_DEBUG_LOCKING_API_SELFTESTS
extern void locking_selftest(void);
#else
# define locking_selftest() do { } while (0)
#endif
#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_show_held_locks(struct task_struct *task)
{
}
static inline void
debug_check_no_locks_freed(const void *from, unsigned long len)
{
}
static inline void
debug_check_no_locks_held(struct task_struct *task)
{
}
#endif
#endif
...@@ -124,7 +124,6 @@ extern struct group_info init_groups; ...@@ -124,7 +124,6 @@ extern struct group_info init_groups;
.cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
.fs_excl = ATOMIC_INIT(0), \ .fs_excl = ATOMIC_INIT(0), \
.pi_lock = SPIN_LOCK_UNLOCKED, \ .pi_lock = SPIN_LOCK_UNLOCKED, \
INIT_RT_MUTEXES(tsk) \
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/prio_tree.h> #include <linux/prio_tree.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/debug_locks.h>
struct mempolicy; struct mempolicy;
struct anon_vma; struct anon_vma;
...@@ -1034,13 +1035,6 @@ static inline void vm_stat_account(struct mm_struct *mm, ...@@ -1034,13 +1035,6 @@ static inline void vm_stat_account(struct mm_struct *mm,
} }
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
static inline void
debug_check_no_locks_freed(const void *from, unsigned long len)
{
mutex_debug_check_no_locks_freed(from, len);
rt_mutex_debug_check_no_locks_freed(from, len);
}
#ifndef CONFIG_DEBUG_PAGEALLOC #ifndef CONFIG_DEBUG_PAGEALLOC
static inline void static inline void
kernel_map_pages(struct page *page, int numpages, int enable) kernel_map_pages(struct page *page, int numpages, int enable)
......
...@@ -7,17 +7,11 @@ ...@@ -7,17 +7,11 @@
* Mutexes - debugging helpers: * Mutexes - debugging helpers:
*/ */
#define __DEBUG_MUTEX_INITIALIZER(lockname) \ #define __DEBUG_MUTEX_INITIALIZER(lockname) \
, .held_list = LIST_HEAD_INIT(lockname.held_list), \ , .magic = &lockname
.name = #lockname , .magic = &lockname
#define mutex_init(sem) __mutex_init(sem, __FUNCTION__) #define mutex_init(sem) __mutex_init(sem, __FILE__":"#sem)
extern void FASTCALL(mutex_destroy(struct mutex *lock)); extern void FASTCALL(mutex_destroy(struct mutex *lock));
extern void mutex_debug_show_all_locks(void);
extern void mutex_debug_show_held_locks(struct task_struct *filter);
extern void mutex_debug_check_no_locks_held(struct task_struct *task);
extern void mutex_debug_check_no_locks_freed(const void *from, unsigned long len);
#endif #endif
...@@ -50,8 +50,6 @@ struct mutex { ...@@ -50,8 +50,6 @@ struct mutex {
struct list_head wait_list; struct list_head wait_list;
#ifdef CONFIG_DEBUG_MUTEXES #ifdef CONFIG_DEBUG_MUTEXES
struct thread_info *owner; struct thread_info *owner;
struct list_head held_list;
unsigned long acquire_ip;
const char *name; const char *name;
void *magic; void *magic;
#endif #endif
...@@ -76,10 +74,6 @@ struct mutex_waiter { ...@@ -76,10 +74,6 @@ struct mutex_waiter {
# define __DEBUG_MUTEX_INITIALIZER(lockname) # define __DEBUG_MUTEX_INITIALIZER(lockname)
# define mutex_init(mutex) __mutex_init(mutex, NULL) # define mutex_init(mutex) __mutex_init(mutex, NULL)
# define mutex_destroy(mutex) do { } while (0) # define mutex_destroy(mutex) do { } while (0)
# define mutex_debug_show_all_locks() do { } while (0)
# define mutex_debug_show_held_locks(p) do { } while (0)
# define mutex_debug_check_no_locks_held(task) do { } while (0)
# define mutex_debug_check_no_locks_freed(from, len) do { } while (0)
#endif #endif
#define __MUTEX_INITIALIZER(lockname) \ #define __MUTEX_INITIALIZER(lockname) \
......
...@@ -29,8 +29,6 @@ struct rt_mutex { ...@@ -29,8 +29,6 @@ struct rt_mutex {
struct task_struct *owner; struct task_struct *owner;
#ifdef CONFIG_DEBUG_RT_MUTEXES #ifdef CONFIG_DEBUG_RT_MUTEXES
int save_state; int save_state;
struct list_head held_list_entry;
unsigned long acquire_ip;
const char *name, *file; const char *name, *file;
int line; int line;
void *magic; void *magic;
...@@ -98,14 +96,6 @@ extern int rt_mutex_trylock(struct rt_mutex *lock); ...@@ -98,14 +96,6 @@ extern int rt_mutex_trylock(struct rt_mutex *lock);
extern void rt_mutex_unlock(struct rt_mutex *lock); extern void rt_mutex_unlock(struct rt_mutex *lock);
#ifdef CONFIG_DEBUG_RT_MUTEXES
# define INIT_RT_MUTEX_DEBUG(tsk) \
.held_list_head = LIST_HEAD_INIT(tsk.held_list_head), \
.held_list_lock = SPIN_LOCK_UNLOCKED
#else
# define INIT_RT_MUTEX_DEBUG(tsk)
#endif
#ifdef CONFIG_RT_MUTEXES #ifdef CONFIG_RT_MUTEXES
# define INIT_RT_MUTEXES(tsk) \ # define INIT_RT_MUTEXES(tsk) \
.pi_waiters = PLIST_HEAD_INIT(tsk.pi_waiters, tsk.pi_lock), \ .pi_waiters = PLIST_HEAD_INIT(tsk.pi_waiters, tsk.pi_lock), \
......
...@@ -865,10 +865,6 @@ struct task_struct { ...@@ -865,10 +865,6 @@ struct task_struct {
struct plist_head pi_waiters; struct plist_head pi_waiters;
/* Deadlock detection and priority inheritance handling */ /* Deadlock detection and priority inheritance handling */
struct rt_mutex_waiter *pi_blocked_on; struct rt_mutex_waiter *pi_blocked_on;
# ifdef CONFIG_DEBUG_RT_MUTEXES
spinlock_t held_list_lock;
struct list_head held_list_head;
# endif
#endif #endif
#ifdef CONFIG_DEBUG_MUTEXES #ifdef CONFIG_DEBUG_MUTEXES
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <linux/key.h> #include <linux/key.h>
#include <linux/unwind.h> #include <linux/unwind.h>
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include <linux/debug_locks.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/bugs.h> #include <asm/bugs.h>
...@@ -511,6 +512,13 @@ asmlinkage void __init start_kernel(void) ...@@ -511,6 +512,13 @@ asmlinkage void __init start_kernel(void)
console_init(); console_init();
if (panic_later) if (panic_later)
panic(panic_later, panic_param); panic(panic_later, panic_param);
/*
* Need to run this when irqs are enabled, because it wants
* to self-test [hard/soft]-irqs on/off lock inversion bugs
* too:
*/
locking_selftest();
#ifdef CONFIG_BLK_DEV_INITRD #ifdef CONFIG_BLK_DEV_INITRD
if (initrd_start && !initrd_below_start_ok && if (initrd_start && !initrd_below_start_ok &&
initrd_start < min_low_pfn << PAGE_SHIFT) { initrd_start < min_low_pfn << PAGE_SHIFT) {
......
...@@ -933,10 +933,9 @@ fastcall NORET_TYPE void do_exit(long code) ...@@ -933,10 +933,9 @@ fastcall NORET_TYPE void do_exit(long code)
if (unlikely(current->pi_state_cache)) if (unlikely(current->pi_state_cache))
kfree(current->pi_state_cache); kfree(current->pi_state_cache);
/* /*
* If DEBUG_MUTEXES is on, make sure we are holding no locks: * Make sure we are holding no locks:
*/ */
mutex_debug_check_no_locks_held(tsk); debug_check_no_locks_held(tsk);
rt_mutex_debug_check_no_locks_held(tsk);
if (tsk->io_context) if (tsk->io_context)
exit_io_context(); exit_io_context();
......
...@@ -919,10 +919,6 @@ static inline void rt_mutex_init_task(struct task_struct *p) ...@@ -919,10 +919,6 @@ static inline void rt_mutex_init_task(struct task_struct *p)
spin_lock_init(&p->pi_lock); spin_lock_init(&p->pi_lock);
plist_head_init(&p->pi_waiters, &p->pi_lock); plist_head_init(&p->pi_waiters, &p->pi_lock);
p->pi_blocked_on = NULL; p->pi_blocked_on = NULL;
# ifdef CONFIG_DEBUG_RT_MUTEXES
spin_lock_init(&p->held_list_lock);
INIT_LIST_HEAD(&p->held_list_head);
# endif
#endif #endif
} }
......
...@@ -20,52 +20,19 @@ ...@@ -20,52 +20,19 @@
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/kallsyms.h> #include <linux/kallsyms.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/debug_locks.h>
#include "mutex-debug.h" #include "mutex-debug.h"
/*
* We need a global lock when we walk through the multi-process
* lock tree. Only used in the deadlock-debugging case.
*/
DEFINE_SPINLOCK(debug_mutex_lock);
/*
* All locks held by all tasks, in a single global list:
*/
LIST_HEAD(debug_mutex_held_locks);
/*
* In the debug case we carry the caller's instruction pointer into
* other functions, but we dont want the function argument overhead
* in the nondebug case - hence these macros:
*/
#define __IP_DECL__ , unsigned long ip
#define __IP__ , ip
#define __RET_IP__ , (unsigned long)__builtin_return_address(0)
/*
* "mutex debugging enabled" flag. We turn it off when we detect
* the first problem because we dont want to recurse back
* into the tracing code when doing error printk or
* executing a BUG():
*/
int debug_mutex_on = 1;
/* /*
* Must be called with lock->wait_lock held. * Must be called with lock->wait_lock held.
*/ */
void debug_mutex_set_owner(struct mutex *lock, void debug_mutex_set_owner(struct mutex *lock, struct thread_info *new_owner)
struct thread_info *new_owner __IP_DECL__)
{ {
lock->owner = new_owner; lock->owner = new_owner;
DEBUG_LOCKS_WARN_ON(!list_empty(&lock->held_list));
if (debug_mutex_on) {
list_add_tail(&lock->held_list, &debug_mutex_held_locks);
lock->acquire_ip = ip;
}
} }
void debug_mutex_init_waiter(struct mutex_waiter *waiter) void debug_mutex_lock_common(struct mutex *lock, struct mutex_waiter *waiter)
{ {
memset(waiter, MUTEX_DEBUG_INIT, sizeof(*waiter)); memset(waiter, MUTEX_DEBUG_INIT, sizeof(*waiter));
waiter->magic = waiter; waiter->magic = waiter;
...@@ -87,9 +54,10 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter) ...@@ -87,9 +54,10 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
} }
void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter, void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
struct thread_info *ti __IP_DECL__) struct thread_info *ti)
{ {
SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock)); SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
/* Mark the current thread as blocked on the lock: */ /* Mark the current thread as blocked on the lock: */
ti->task->blocked_on = waiter; ti->task->blocked_on = waiter;
waiter->lock = lock; waiter->lock = lock;
...@@ -109,13 +77,10 @@ void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter, ...@@ -109,13 +77,10 @@ void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
void debug_mutex_unlock(struct mutex *lock) void debug_mutex_unlock(struct mutex *lock)
{ {
DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
DEBUG_LOCKS_WARN_ON(lock->magic != lock); DEBUG_LOCKS_WARN_ON(lock->magic != lock);
DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next); DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info()); DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
if (debug_mutex_on) {
DEBUG_LOCKS_WARN_ON(list_empty(&lock->held_list));
list_del_init(&lock->held_list);
}
} }
void debug_mutex_init(struct mutex *lock, const char *name) void debug_mutex_init(struct mutex *lock, const char *name)
...@@ -123,10 +88,8 @@ void debug_mutex_init(struct mutex *lock, const char *name) ...@@ -123,10 +88,8 @@ void debug_mutex_init(struct mutex *lock, const char *name)
/* /*
* Make sure we are not reinitializing a held lock: * Make sure we are not reinitializing a held lock:
*/ */
mutex_debug_check_no_locks_freed((void *)lock, sizeof(*lock)); debug_check_no_locks_freed((void *)lock, sizeof(*lock));
lock->owner = NULL; lock->owner = NULL;
INIT_LIST_HEAD(&lock->held_list);
lock->name = name;
lock->magic = lock; lock->magic = lock;
} }
......
...@@ -10,102 +10,44 @@ ...@@ -10,102 +10,44 @@
* More details are in kernel/mutex-debug.c. * More details are in kernel/mutex-debug.c.
*/ */
extern spinlock_t debug_mutex_lock;
extern struct list_head debug_mutex_held_locks;
extern int debug_mutex_on;
/*
* In the debug case we carry the caller's instruction pointer into
* other functions, but we dont want the function argument overhead
* in the nondebug case - hence these macros:
*/
#define __IP_DECL__ , unsigned long ip
#define __IP__ , ip
#define __RET_IP__ , (unsigned long)__builtin_return_address(0)
/* /*
* This must be called with lock->wait_lock held. * This must be called with lock->wait_lock held.
*/ */
extern void debug_mutex_set_owner(struct mutex *lock, extern void
struct thread_info *new_owner __IP_DECL__); debug_mutex_set_owner(struct mutex *lock, struct thread_info *new_owner);
static inline void debug_mutex_clear_owner(struct mutex *lock) static inline void debug_mutex_clear_owner(struct mutex *lock)
{ {
lock->owner = NULL; lock->owner = NULL;
} }
extern void debug_mutex_init_waiter(struct mutex_waiter *waiter); extern void debug_mutex_lock_common(struct mutex *lock,
struct mutex_waiter *waiter);
extern void debug_mutex_wake_waiter(struct mutex *lock, extern void debug_mutex_wake_waiter(struct mutex *lock,
struct mutex_waiter *waiter); struct mutex_waiter *waiter);
extern void debug_mutex_free_waiter(struct mutex_waiter *waiter); extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
extern void debug_mutex_add_waiter(struct mutex *lock, extern void debug_mutex_add_waiter(struct mutex *lock,
struct mutex_waiter *waiter, struct mutex_waiter *waiter,
struct thread_info *ti __IP_DECL__); struct thread_info *ti);
extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter, extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
struct thread_info *ti); struct thread_info *ti);
extern void debug_mutex_unlock(struct mutex *lock); 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 lock_class_key *key);
#define debug_spin_lock_save(lock, flags) \
do { \
local_irq_save(flags); \
if (debug_mutex_on) \
spin_lock(lock); \
} while (0)
#define debug_spin_unlock_restore(lock, flags) \
do { \
if (debug_mutex_on) \
spin_unlock(lock); \
local_irq_restore(flags); \
preempt_check_resched(); \
} while (0)
#define spin_lock_mutex(lock, flags) \ #define spin_lock_mutex(lock, flags) \
do { \ do { \
struct mutex *l = container_of(lock, struct mutex, wait_lock); \ struct mutex *l = container_of(lock, struct mutex, wait_lock); \
\ \
DEBUG_LOCKS_WARN_ON(in_interrupt()); \ DEBUG_LOCKS_WARN_ON(in_interrupt()); \
debug_spin_lock_save(&debug_mutex_lock, flags); \ local_irq_save(flags); \
spin_lock(lock); \ __raw_spin_lock(&(lock)->raw_lock); \
DEBUG_LOCKS_WARN_ON(l->magic != l); \ DEBUG_LOCKS_WARN_ON(l->magic != l); \
} while (0) } while (0)
#define spin_unlock_mutex(lock, flags) \ #define spin_unlock_mutex(lock, flags) \
do { \ do { \
spin_unlock(lock); \ __raw_spin_unlock(&(lock)->raw_lock); \
debug_spin_unlock_restore(&debug_mutex_lock, flags); \ local_irq_restore(flags); \
preempt_check_resched(); \
} while (0) } while (0)
#define DEBUG_OFF() \
do { \
if (debug_mutex_on) { \
debug_mutex_on = 0; \
console_verbose(); \
if (spin_is_locked(&debug_mutex_lock)) \
spin_unlock(&debug_mutex_lock); \
} \
} while (0)
#define DEBUG_BUG() \
do { \
if (debug_mutex_on) { \
DEBUG_OFF(); \
BUG(); \
} \
} while (0)
#define DEBUG_LOCKS_WARN_ON(c) \
do { \
if (unlikely(c && debug_mutex_on)) { \
DEBUG_OFF(); \
WARN_ON(1); \
} \
} while (0)
#ifdef CONFIG_SMP
# define SMP_DEBUG_LOCKS_WARN_ON(c) DEBUG_LOCKS_WARN_ON(c)
#else
# define SMP_DEBUG_LOCKS_WARN_ON(c) do { } while (0)
#endif
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/debug_locks.h>
/* /*
* In the DEBUG case we are using the "NULL fastpath" for mutexes, * In the DEBUG case we are using the "NULL fastpath" for mutexes,
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
* *
* It is not allowed to initialize an already locked mutex. * It is not allowed to initialize an already locked mutex.
*/ */
void fastcall __mutex_init(struct mutex *lock, const char *name) __always_inline void fastcall __mutex_init(struct mutex *lock, const char *name)
{ {
atomic_set(&lock->count, 1); atomic_set(&lock->count, 1);
spin_lock_init(&lock->wait_lock); spin_lock_init(&lock->wait_lock);
...@@ -56,7 +57,7 @@ EXPORT_SYMBOL(__mutex_init); ...@@ -56,7 +57,7 @@ EXPORT_SYMBOL(__mutex_init);
* branch is predicted by the CPU as default-untaken. * branch is predicted by the CPU as default-untaken.
*/ */
static void fastcall noinline __sched static void fastcall noinline __sched
__mutex_lock_slowpath(atomic_t *lock_count __IP_DECL__); __mutex_lock_slowpath(atomic_t *lock_count);
/*** /***
* mutex_lock - acquire the mutex * mutex_lock - acquire the mutex
...@@ -79,7 +80,7 @@ __mutex_lock_slowpath(atomic_t *lock_count __IP_DECL__); ...@@ -79,7 +80,7 @@ __mutex_lock_slowpath(atomic_t *lock_count __IP_DECL__);
* *
* This function is similar to (but not equivalent to) down(). * This function is similar to (but not equivalent to) down().
*/ */
void fastcall __sched mutex_lock(struct mutex *lock) void inline fastcall __sched mutex_lock(struct mutex *lock)
{ {
might_sleep(); might_sleep();
/* /*
...@@ -92,7 +93,7 @@ void fastcall __sched mutex_lock(struct mutex *lock) ...@@ -92,7 +93,7 @@ void fastcall __sched mutex_lock(struct mutex *lock)
EXPORT_SYMBOL(mutex_lock); EXPORT_SYMBOL(mutex_lock);
static void fastcall noinline __sched static void fastcall noinline __sched
__mutex_unlock_slowpath(atomic_t *lock_count __IP_DECL__); __mutex_unlock_slowpath(atomic_t *lock_count);
/*** /***
* mutex_unlock - release the mutex * mutex_unlock - release the mutex
...@@ -120,18 +121,17 @@ EXPORT_SYMBOL(mutex_unlock); ...@@ -120,18 +121,17 @@ EXPORT_SYMBOL(mutex_unlock);
* Lock a mutex (possibly interruptible), slowpath: * Lock a mutex (possibly interruptible), slowpath:
*/ */
static inline int __sched static inline int __sched
__mutex_lock_common(struct mutex *lock, long state __IP_DECL__) __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass)
{ {
struct task_struct *task = current; struct task_struct *task = current;
struct mutex_waiter waiter; struct mutex_waiter waiter;
unsigned int old_val; unsigned int old_val;
unsigned long flags; unsigned long flags;
debug_mutex_init_waiter(&waiter);
spin_lock_mutex(&lock->wait_lock, flags); spin_lock_mutex(&lock->wait_lock, flags);
debug_mutex_add_waiter(lock, &waiter, task->thread_info, ip); debug_mutex_lock_common(lock, &waiter);
debug_mutex_add_waiter(lock, &waiter, task->thread_info);
/* add waiting tasks to the end of the waitqueue (FIFO): */ /* add waiting tasks to the end of the waitqueue (FIFO): */
list_add_tail(&waiter.list, &lock->wait_list); list_add_tail(&waiter.list, &lock->wait_list);
...@@ -173,7 +173,7 @@ __mutex_lock_common(struct mutex *lock, long state __IP_DECL__) ...@@ -173,7 +173,7 @@ __mutex_lock_common(struct mutex *lock, long state __IP_DECL__)
/* got the lock - rejoice! */ /* got the lock - rejoice! */
mutex_remove_waiter(lock, &waiter, task->thread_info); mutex_remove_waiter(lock, &waiter, task->thread_info);
debug_mutex_set_owner(lock, task->thread_info __IP__); debug_mutex_set_owner(lock, task->thread_info);
/* set it to 0 if there are no waiters left: */ /* set it to 0 if there are no waiters left: */
if (likely(list_empty(&lock->wait_list))) if (likely(list_empty(&lock->wait_list)))
...@@ -183,32 +183,28 @@ __mutex_lock_common(struct mutex *lock, long state __IP_DECL__) ...@@ -183,32 +183,28 @@ __mutex_lock_common(struct mutex *lock, long state __IP_DECL__)
debug_mutex_free_waiter(&waiter); debug_mutex_free_waiter(&waiter);
DEBUG_LOCKS_WARN_ON(list_empty(&lock->held_list));
DEBUG_LOCKS_WARN_ON(lock->owner != task->thread_info);
return 0; return 0;
} }
static void fastcall noinline __sched static void fastcall noinline __sched
__mutex_lock_slowpath(atomic_t *lock_count __IP_DECL__) __mutex_lock_slowpath(atomic_t *lock_count)
{ {
struct mutex *lock = container_of(lock_count, struct mutex, count); struct mutex *lock = container_of(lock_count, struct mutex, count);
__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE __IP__); __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0);
} }
/* /*
* Release the lock, slowpath: * Release the lock, slowpath:
*/ */
static fastcall noinline void static fastcall inline void
__mutex_unlock_slowpath(atomic_t *lock_count __IP_DECL__) __mutex_unlock_common_slowpath(atomic_t *lock_count)
{ {
struct mutex *lock = container_of(lock_count, struct mutex, count); struct mutex *lock = container_of(lock_count, struct mutex, count);
unsigned long flags; unsigned long flags;
DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
spin_lock_mutex(&lock->wait_lock, flags); spin_lock_mutex(&lock->wait_lock, flags);
debug_mutex_unlock(lock);
/*