Unverified Commit d11daa4c authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!5231 af_unix: fix lockdep positive in sk_diag_dump_icons()

parents f88ae203 a6d1adb0
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -47,12 +47,6 @@ struct scm_stat {

#define UNIXCB(skb)	(*(struct unix_skb_parms *)&((skb)->cb))

#define unix_state_lock(s)	spin_lock(&unix_sk(s)->lock)
#define unix_state_unlock(s)	spin_unlock(&unix_sk(s)->lock)
#define unix_state_lock_nested(s) \
				spin_lock_nested(&unix_sk(s)->lock, \
				SINGLE_DEPTH_NESTING)

/* The AF_UNIX socket */
struct unix_sock {
	/* WARNING: sk has to be the first member */
@@ -77,6 +71,20 @@ static inline struct unix_sock *unix_sk(const struct sock *sk)
	return (struct unix_sock *)sk;
}

#define unix_state_lock(s)	spin_lock(&unix_sk(s)->lock)
#define unix_state_unlock(s)	spin_unlock(&unix_sk(s)->lock)
enum unix_socket_lock_class {
	U_LOCK_NORMAL,
	U_LOCK_SECOND,	/* for double locking, see unix_state_double_lock(). */
	U_LOCK_DIAG, /* used while dumping icons, see sk_diag_dump_icons(). */
};

static inline void unix_state_lock_nested(struct sock *sk,
				   enum unix_socket_lock_class subclass)
{
	spin_lock_nested(&unix_sk(sk)->lock, subclass);
}

#define peer_wait peer_wq.wait

long unix_inq_len(struct sock *sk);
+6 −8
Original line number Diff line number Diff line
@@ -1225,13 +1225,11 @@ static void unix_state_double_lock(struct sock *sk1, struct sock *sk2)
		unix_state_lock(sk1);
		return;
	}
	if (sk1 < sk2) {
	if (sk1 > sk2)
		swap(sk1, sk2);

	unix_state_lock(sk1);
		unix_state_lock_nested(sk2);
	} else {
		unix_state_lock(sk2);
		unix_state_lock_nested(sk1);
	}
	unix_state_lock_nested(sk2, U_LOCK_SECOND);
}

static void unix_state_double_unlock(struct sock *sk1, struct sock *sk2)
@@ -1460,7 +1458,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
		goto out_unlock;
	}

	unix_state_lock_nested(sk);
	unix_state_lock_nested(sk, U_LOCK_SECOND);

	if (sk->sk_state != st) {
		unix_state_unlock(sk);
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ static int sk_diag_dump_icons(struct sock *sk, struct sk_buff *nlskb)
			 * queue lock. With the other's queue locked it's
			 * OK to lock the state.
			 */
			unix_state_lock_nested(req);
			unix_state_lock_nested(req, U_LOCK_DIAG);
			peer = unix_sk(req)->peer;
			buf[i++] = (peer ? sock_i_ino(peer) : 0);
			unix_state_unlock(req);