[PATCH] lockdep: annotate af_unix locking
authorIngo Molnar <mingo@elte.hu>
Mon, 3 Jul 2006 07:25:12 +0000 (00:25 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Mon, 3 Jul 2006 22:27:07 +0000 (15:27 -0700)
Teach special (recursive) locking code to the lock validator.  Also splits
af_unix's sk_receive_queue.lock class from the other networking skb-queue
locks.  Has no effect on non-lockdep kernels.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
include/net/af_unix.h
net/unix/af_unix.c

index 5ba72d9..2fec827 100644 (file)
@@ -67,6 +67,9 @@ struct unix_skb_parms {
 #define unix_state_rlock(s)    spin_lock(&unix_sk(s)->lock)
 #define unix_state_runlock(s)  spin_unlock(&unix_sk(s)->lock)
 #define unix_state_wlock(s)    spin_lock(&unix_sk(s)->lock)
 #define unix_state_rlock(s)    spin_lock(&unix_sk(s)->lock)
 #define unix_state_runlock(s)  spin_unlock(&unix_sk(s)->lock)
 #define unix_state_wlock(s)    spin_lock(&unix_sk(s)->lock)
+#define unix_state_wlock_nested(s) \
+                               spin_lock_nested(&unix_sk(s)->lock, \
+                               SINGLE_DEPTH_NESTING)
 #define unix_state_wunlock(s)  spin_unlock(&unix_sk(s)->lock)
 
 #ifdef __KERNEL__
 #define unix_state_wunlock(s)  spin_unlock(&unix_sk(s)->lock)
 
 #ifdef __KERNEL__
index aca6501..e9a287b 100644 (file)
@@ -565,6 +565,14 @@ static struct proto unix_proto = {
        .obj_size = sizeof(struct unix_sock),
 };
 
        .obj_size = sizeof(struct unix_sock),
 };
 
+/*
+ * AF_UNIX sockets do not interact with hardware, hence they
+ * dont trigger interrupts - so it's safe for them to have
+ * bh-unsafe locking for their sk_receive_queue.lock. Split off
+ * this special lock-class by reinitializing the spinlock key:
+ */
+static struct lock_class_key af_unix_sk_receive_queue_lock_key;
+
 static struct sock * unix_create1(struct socket *sock)
 {
        struct sock *sk = NULL;
 static struct sock * unix_create1(struct socket *sock)
 {
        struct sock *sk = NULL;
@@ -580,6 +588,8 @@ static struct sock * unix_create1(struct socket *sock)
        atomic_inc(&unix_nr_socks);
 
        sock_init_data(sock,sk);
        atomic_inc(&unix_nr_socks);
 
        sock_init_data(sock,sk);
+       lockdep_set_class(&sk->sk_receive_queue.lock,
+                               &af_unix_sk_receive_queue_lock_key);
 
        sk->sk_write_space      = unix_write_space;
        sk->sk_max_ack_backlog  = sysctl_unix_max_dgram_qlen;
 
        sk->sk_write_space      = unix_write_space;
        sk->sk_max_ack_backlog  = sysctl_unix_max_dgram_qlen;
@@ -1045,7 +1055,7 @@ restart:
                goto out_unlock;
        }
 
                goto out_unlock;
        }
 
-       unix_state_wlock(sk);
+       unix_state_wlock_nested(sk);
 
        if (sk->sk_state != st) {
                unix_state_wunlock(sk);
 
        if (sk->sk_state != st) {
                unix_state_wunlock(sk);