From: Ingo Molnar Teach special (multi-initialized, per-address-family) locking code to the lock validator. Has no effect on non-lockdep kernels. Signed-off-by: Ingo Molnar Signed-off-by: Arjan van de Ven Cc: "David S. Miller" Signed-off-by: Andrew Morton --- include/net/sock.h | 6 ------ net/core/sock.c | 27 +++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) diff -puN include/net/sock.h~lock-validator-special-locking-sock_lock_init include/net/sock.h --- devel/include/net/sock.h~lock-validator-special-locking-sock_lock_init 2006-05-29 18:13:24.000000000 -0700 +++ devel-akpm/include/net/sock.h 2006-05-29 18:13:24.000000000 -0700 @@ -80,12 +80,6 @@ typedef struct { wait_queue_head_t wq; } socket_lock_t; -#define sock_lock_init(__sk) \ -do { spin_lock_init(&((__sk)->sk_lock.slock)); \ - (__sk)->sk_lock.owner = NULL; \ - init_waitqueue_head(&((__sk)->sk_lock.wq)); \ -} while(0) - struct sock; struct proto; diff -puN net/core/sock.c~lock-validator-special-locking-sock_lock_init net/core/sock.c --- devel/net/core/sock.c~lock-validator-special-locking-sock_lock_init 2006-05-29 18:13:24.000000000 -0700 +++ devel-akpm/net/core/sock.c 2006-05-29 18:13:24.000000000 -0700 @@ -739,6 +739,27 @@ lenout: return 0; } +/* + * Each address family might have different locking rules, so we have + * one slock key per address family: + */ +static struct lockdep_type_key af_family_keys[AF_MAX]; + +static void noinline sock_lock_init(struct sock *sk) +{ + spin_lock_init_key(&sk->sk_lock.slock, af_family_keys + sk->sk_family); + sk->sk_lock.owner = NULL; + init_waitqueue_head(&sk->sk_lock.wq); +} + +static struct lockdep_type_key af_callback_keys[AF_MAX]; + +static void noinline sock_rwlock_init(struct sock *sk) +{ + rwlock_init(&sk->sk_dst_lock); + rwlock_init_key(&sk->sk_callback_lock, af_callback_keys + sk->sk_family); +} + /** * sk_alloc - All socket objects are allocated here * @family: protocol family @@ -836,8 +857,7 @@ struct sock *sk_clone(const struct sock skb_queue_head_init(&newsk->sk_async_wait_queue); #endif - rwlock_init(&newsk->sk_dst_lock); - rwlock_init(&newsk->sk_callback_lock); + sock_rwlock_init(newsk); newsk->sk_dst_cache = NULL; newsk->sk_wmem_queued = 0; @@ -1410,8 +1430,7 @@ void sock_init_data(struct socket *sock, } else sk->sk_sleep = NULL; - rwlock_init(&sk->sk_dst_lock); - rwlock_init(&sk->sk_callback_lock); + sock_rwlock_init(sk); sk->sk_state_change = sock_def_wakeup; sk->sk_data_ready = sock_def_readable; _