Message ID | 20240127020833.487907-5-kent.overstreet@linux.dev |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-41013-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2395:b0:106:343:edcb with SMTP id gw21csp274267dyb; Fri, 26 Jan 2024 18:26:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzCwj7NlJzP+SWIIgxjjhznPNMMgSHRCSf4UT/0Vn4qwBth3RoU4+7UiI3VIAMGJaMoiCn X-Received: by 2002:a17:906:ae8e:b0:a35:44fd:c0e2 with SMTP id md14-20020a170906ae8e00b00a3544fdc0e2mr77859ejb.8.1706322400191; Fri, 26 Jan 2024 18:26:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706322400; cv=pass; d=google.com; s=arc-20160816; b=kwaDpNZfCC4aPYs3+BUN+fPUosGcU/z0uGKZzYCVTres5e90pFll/N9NIxg8dBW3kl Mc2wcpfMXHOBcNqC0FwUdJiYHMp3evNpY8LCCt6xujT7sUSWUssOLH/x2xXbNGTZJG4P NiA/S2VubeF9FEvTNS5SN+5lZdSdtw9MOyz6kXCK/yLRZVVymJnocTHA77U7hVTxtbo4 AsVBqqnMtDrplaX36Y5qqOgFZ4rcwoDVXgUakUhiBLltZLH6HMg7BZqgmMCIp9VnBtay 7wY3DpwuLsin11L9Mb+7rvpYHBf6xV3SSsvEFdYvzLUoR6ZI9LlIwyu7i7gDHKe2ttQY MdIg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uLB5skfy3BEv0JbsXyQzZFD+57i+sZEpeM1MJI3SUiw=; fh=G5DaSdor7MropyFk0CA4E4srFTXsRWsLAIC8xcZLlO4=; b=ISx35ilBVVDdvRQ/VmUXJ1VyWsm+E7NnQErGzhui5BeWRb+N83BKkF4DruiDpW2fFA 0niuvR5/LTS5p3+0o4GtebISPyXgCObher3LwV3HWuQsumRcXzT2ktvKRkfX1sk7kJKS xCEtlFvoepiac4Rmtzbh7TxEawlh6yWYXx4d8ZYZWZR7b37tihK5PMD1Z7/S1V8CVSJk wtPDr0Q+YL/j1Mw98cHMURyXogJk+pAITU/kyrojGnHl5bscg2LfIGBGZzaynuQtA9EL 1L/sJjin3S5qz2JayVKdvwIRiT2dKBU3Fh4eMUBLTOPv4UbWg9QUCX27KrYItxYR0RO/ B2yg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=qJ+Rs5He; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-41013-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41013-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f19-20020a17090624d300b00a317e4aad11si1227203ejb.375.2024.01.26.18.26.40 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 18:26:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41013-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=qJ+Rs5He; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-41013-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41013-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 21EB31F2BD74 for <ouuuleilei@gmail.com>; Sat, 27 Jan 2024 02:16:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EFDBA20339; Sat, 27 Jan 2024 02:08:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="qJ+Rs5He" Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53CD514AB0 for <linux-kernel@vger.kernel.org>; Sat, 27 Jan 2024 02:08:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706321328; cv=none; b=MLHCtg/PJbpai6nYelccDCmcVCxcGpU0bM/kkzL4nr2fWugqtyt6FR/kwqQQ4DZPyKr6ISacto4bDaNW0gEPb90knUDFGRfWPGfNJ8xtrGj/7KP3Ej2x4Ol8SEqwG37EfyZmXMPw9IMVBgff6OBtnXSxsOkqi4ixzrBdlrQciSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706321328; c=relaxed/simple; bh=WEGpc0xxaxj2AY+Xn8ROwEZelU+zXk/EivX8ekFZmeA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WM3HiLZvkWcgYXV48scmJOUGI2kjehlbu8GM/i+QfkUUOgm9+qBahJwvu22OC3d7yhRr8QEVsnwo3GfG4d0oQ1M/e4/lHI6xLYe7I6X7ooFS3EJ25v0QD0OXuIWy3waNIiHlwHo9YF8a72sGKPFXr+YTPDRZe4CPXYkV3QhigNk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=qJ+Rs5He; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1706321324; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uLB5skfy3BEv0JbsXyQzZFD+57i+sZEpeM1MJI3SUiw=; b=qJ+Rs5Hetw76AhWzqkBqPEZ/rwuaoaVg6aS11PxBaqriW5WPXxSENcSnZNZXM1c6eVbqmM HjfsYmTkTsHI6SIAhoLt7RahUYWkpTQ2q28spAAEQ3SMoy/8FpcbppN6VBQqYXblzzV86c YEZMI0JmVQa5R1JwUH/xLTa6AQ/1YSA= From: Kent Overstreet <kent.overstreet@linux.dev> To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Kent Overstreet <kent.overstreet@linux.dev>, peterz@infradead.org, boqun.feng@gmail.com Subject: [PATCH 4/4] af_unix: convert to lock_cmp_fn Date: Fri, 26 Jan 2024 21:08:31 -0500 Message-ID: <20240127020833.487907-5-kent.overstreet@linux.dev> In-Reply-To: <20240127020833.487907-1-kent.overstreet@linux.dev> References: <20240127020833.487907-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789208716809595483 X-GMAIL-MSGID: 1789208716809595483 |
Series | lockdep cmp fn conversions | |
Commit Message
Kent Overstreet
Jan. 27, 2024, 2:08 a.m. UTC
Kill
- unix_state_lock_nested
- _nested usage for net->unx.table.locks[].
replace both with lock_set_cmp_fn_ptr_order(&u->lock).
The lock ordering in sk_diag_dump_icons() looks suspicious; this may
turn up a real issue.
Cc: netdev@vger.kernel.org
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
include/net/af_unix.h | 3 ---
net/unix/af_unix.c | 20 ++++++++------------
net/unix/diag.c | 2 +-
3 files changed, 9 insertions(+), 16 deletions(-)
Comments
From: Kent Overstreet <kent.overstreet@linux.dev> Date: Fri, 26 Jan 2024 21:08:31 -0500 > Kill > - unix_state_lock_nested > - _nested usage for net->unx.table.locks[]. > > replace both with lock_set_cmp_fn_ptr_order(&u->lock). > > The lock ordering in sk_diag_dump_icons() looks suspicious; this may > turn up a real issue. Yes, you cannot use lock_cmp_fn() for unix_state_lock_nested(). The lock order in sk_diag_dump_icons() is listening socket -> child socket in the listener's queue , and the inverse order never happens. ptr comparison does not make sense in this case, and lockdep will complain about false positive. > > Cc: netdev@vger.kernel.org > Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev> > --- > include/net/af_unix.h | 3 --- > net/unix/af_unix.c | 20 ++++++++------------ > net/unix/diag.c | 2 +- > 3 files changed, 9 insertions(+), 16 deletions(-) > > diff --git a/include/net/af_unix.h b/include/net/af_unix.h > index 49c4640027d8..4eff0a089640 100644 > --- a/include/net/af_unix.h > +++ b/include/net/af_unix.h > @@ -48,9 +48,6 @@ struct scm_stat { > > #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 { > diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c > index d013de3c5490..1a0d273799c1 100644 > --- a/net/unix/af_unix.c > +++ b/net/unix/af_unix.c > @@ -170,7 +170,7 @@ static void unix_table_double_lock(struct net *net, > swap(hash1, hash2); > > spin_lock(&net->unx.table.locks[hash1]); > - spin_lock_nested(&net->unx.table.locks[hash2], SINGLE_DEPTH_NESTING); > + spin_lock(&net->unx.table.locks[hash2]); > } > > static void unix_table_double_unlock(struct net *net, > @@ -997,6 +997,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern, > u->path.dentry = NULL; > u->path.mnt = NULL; > spin_lock_init(&u->lock); > + lock_set_cmp_fn_ptr_order(&u->lock); > atomic_long_set(&u->inflight, 0); > INIT_LIST_HEAD(&u->link); > mutex_init(&u->iolock); /* single task reading lock */ > @@ -1340,17 +1341,11 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) > > static void unix_state_double_lock(struct sock *sk1, struct sock *sk2) > { > - if (unlikely(sk1 == sk2) || !sk2) { > - unix_state_lock(sk1); > - return; > - } > - if (sk1 < sk2) { > + if (sk1 > sk2) > + swap(sk1, sk2); > + if (sk1 && sk1 != sk2) > unix_state_lock(sk1); > - unix_state_lock_nested(sk2); > - } else { > - unix_state_lock(sk2); > - unix_state_lock_nested(sk1); > - } > + unix_state_lock(sk2); > } > > static void unix_state_double_unlock(struct sock *sk1, struct sock *sk2) > @@ -1591,7 +1586,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, > goto out_unlock; > } > > - unix_state_lock_nested(sk); > + unix_state_lock(sk); > > if (sk->sk_state != st) { > unix_state_unlock(sk); > @@ -3575,6 +3570,7 @@ static int __net_init unix_net_init(struct net *net) > > for (i = 0; i < UNIX_HASH_SIZE; i++) { > spin_lock_init(&net->unx.table.locks[i]); > + lock_set_cmp_fn_ptr_order(&net->unx.table.locks[i]); > INIT_HLIST_HEAD(&net->unx.table.buckets[i]); > } > > diff --git a/net/unix/diag.c b/net/unix/diag.c > index bec09a3a1d44..8ab5e2217e4c 100644 > --- a/net/unix/diag.c > +++ b/net/unix/diag.c > @@ -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(req); > peer = unix_sk(req)->peer; > buf[i++] = (peer ? sock_i_ino(peer) : 0); > unix_state_unlock(req); > -- > 2.43.0
On Sun, Jan 28, 2024 at 12:28:38AM -0800, Kuniyuki Iwashima wrote: > From: Kent Overstreet <kent.overstreet@linux.dev> > Date: Fri, 26 Jan 2024 21:08:31 -0500 > > Kill > > - unix_state_lock_nested > > - _nested usage for net->unx.table.locks[]. > > > > replace both with lock_set_cmp_fn_ptr_order(&u->lock). > > > > The lock ordering in sk_diag_dump_icons() looks suspicious; this may > > turn up a real issue. > > Yes, you cannot use lock_cmp_fn() for unix_state_lock_nested(). > > The lock order in sk_diag_dump_icons() is > > listening socket -> child socket in the listener's queue > > , and the inverse order never happens. ptr comparison does not make > sense in this case, and lockdep will complain about false positive. Is that a real lock ordering? Is this parent -> child relationship well defined? If it is, we should be able to write a lock_cmp_fn for it, as long as it's not some handwavy "this will never happen but _nested won't check for it" like I saw elsewhere in the net code... :)
From: Kent Overstreet <kent.overstreet@linux.dev> Date: Sun, 28 Jan 2024 14:38:02 -0500 > On Sun, Jan 28, 2024 at 12:28:38AM -0800, Kuniyuki Iwashima wrote: > > From: Kent Overstreet <kent.overstreet@linux.dev> > > Date: Fri, 26 Jan 2024 21:08:31 -0500 > > > Kill > > > - unix_state_lock_nested > > > - _nested usage for net->unx.table.locks[]. > > > > > > replace both with lock_set_cmp_fn_ptr_order(&u->lock). > > > > > > The lock ordering in sk_diag_dump_icons() looks suspicious; this may > > > turn up a real issue. > > > > Yes, you cannot use lock_cmp_fn() for unix_state_lock_nested(). > > > > The lock order in sk_diag_dump_icons() is > > > > listening socket -> child socket in the listener's queue > > > > , and the inverse order never happens. ptr comparison does not make > > sense in this case, and lockdep will complain about false positive. > > Is that a real lock ordering? Is this parent -> child relationship well > defined? > > If it is, we should be able to write a lock_cmp_fn for it, as long as > it's not some handwavy "this will never happen but _nested won't check > for it" like I saw elsewhere in the net code... :) The problem would be there's no handy way to detect the relationship except for iterating the queue again. ---8<--- static int unix_state_lock_cmp_fn(const struct lockdep_map *_a, const struct lockdep_map *_b) { const struct unix_sock *a = container_of(_a, struct unix_sock, lock.dep_map); const struct unix_sock *b = container_of(_b, struct unix_sock, lock.dep_map); if (a->sk.sk_state == TCP_LISTEN && b->sk.sk_state == TCP_ESTABLISHED) { /* check if b is a's cihld */ } /* otherwise, ptr comparison here. */ } ---8<--- This can be resolved by a patch like this, which is in my local tree for another series. So, after posting the series, I can revisit this and write lock_cmp_fn for u->lock. ---8<--- commit 12d39766b06068fda5987f4e7b4827e8c3273137 Author: Kuniyuki Iwashima <kuniyu@amazon.com> Date: Thu Jan 11 22:36:58 2024 +0000 af_unix: Save listener for embryo socket. Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> diff --git a/include/net/af_unix.h b/include/net/af_unix.h index 9ea04653c7c9..d0c0d81bcb1d 100644 --- a/include/net/af_unix.h +++ b/include/net/af_unix.h @@ -82,6 +82,7 @@ struct scm_stat { struct unix_sock { /* WARNING: sk has to be the first member */ struct sock sk; +#define usk_listener sk.__sk_common.skc_unix_listener struct unix_address *addr; struct path path; struct mutex iolock, bindlock; diff --git a/include/net/sock.h b/include/net/sock.h index a9d99a9c583f..3df3d068345a 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -142,6 +142,8 @@ typedef __u64 __bitwise __addrpair; * [union with @skc_incoming_cpu] * @skc_tw_rcv_nxt: (aka tw_rcv_nxt) TCP window next expected seq number * [union with @skc_incoming_cpu] + * @skc_unix_listener: connection request listener socket for AF_UNIX + * [union with @skc_rxhash] * @skc_refcnt: reference count * * This is the minimal network layer representation of sockets, the header @@ -227,6 +229,7 @@ struct sock_common { u32 skc_rxhash; u32 skc_window_clamp; u32 skc_tw_snd_nxt; /* struct tcp_timewait_sock */ + struct sock *skc_unix_listener; /* struct unix_sock */ }; /* public: */ }; diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 5f9871555ec6..4a41bb727c32 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -991,6 +991,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern, sk->sk_max_ack_backlog = net->unx.sysctl_max_dgram_qlen; sk->sk_destruct = unix_sock_destructor; u = unix_sk(sk); + u->usk_listener = NULL; u->inflight = 0; u->path.dentry = NULL; u->path.mnt = NULL; @@ -1612,6 +1613,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, newsk->sk_type = sk->sk_type; init_peercred(newsk); newu = unix_sk(newsk); + newu->usk_listener = other; RCU_INIT_POINTER(newsk->sk_wq, &newu->peer_wq); otheru = unix_sk(other); @@ -1707,8 +1709,8 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags, bool kern) { struct sock *sk = sock->sk; - struct sock *tsk; struct sk_buff *skb; + struct sock *tsk; int err; err = -EOPNOTSUPP; @@ -1733,6 +1735,7 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags, } tsk = skb->sk; + unix_sk(tsk)->usk_listener = NULL; skb_free_datagram(sk, skb); wake_up_interruptible(&unix_sk(sk)->peer_wait); ---8<---
On Sun, Jan 28, 2024 at 12:56:32PM -0800, Kuniyuki Iwashima wrote: > From: Kent Overstreet <kent.overstreet@linux.dev> > Date: Sun, 28 Jan 2024 14:38:02 -0500 > > On Sun, Jan 28, 2024 at 12:28:38AM -0800, Kuniyuki Iwashima wrote: > > > From: Kent Overstreet <kent.overstreet@linux.dev> > > > Date: Fri, 26 Jan 2024 21:08:31 -0500 > > > > Kill > > > > - unix_state_lock_nested > > > > - _nested usage for net->unx.table.locks[]. > > > > > > > > replace both with lock_set_cmp_fn_ptr_order(&u->lock). > > > > > > > > The lock ordering in sk_diag_dump_icons() looks suspicious; this may > > > > turn up a real issue. > > > > > > Yes, you cannot use lock_cmp_fn() for unix_state_lock_nested(). > > > > > > The lock order in sk_diag_dump_icons() is > > > > > > listening socket -> child socket in the listener's queue > > > > > > , and the inverse order never happens. ptr comparison does not make > > > sense in this case, and lockdep will complain about false positive. > > > > Is that a real lock ordering? Is this parent -> child relationship well > > defined? > > > > If it is, we should be able to write a lock_cmp_fn for it, as long as > > it's not some handwavy "this will never happen but _nested won't check > > for it" like I saw elsewhere in the net code... :) > > The problem would be there's no handy way to detect the relationship > except for iterating the queue again. > > ---8<--- > static int unix_state_lock_cmp_fn(const struct lockdep_map *_a, > const struct lockdep_map *_b) > { > const struct unix_sock *a = container_of(_a, struct unix_sock, lock.dep_map); > const struct unix_sock *b = container_of(_b, struct unix_sock, lock.dep_map); > > if (a->sk.sk_state == TCP_LISTEN && b->sk.sk_state == TCP_ESTABLISHED) { > /* check if b is a's cihld */ > } > > /* otherwise, ptr comparison here. */ > } > ---8<--- > > > This can be resolved by a patch like this, which is in my local tree > for another series. > > So, after posting the series, I can revisit this and write lock_cmp_fn > for u->lock. Sounds good! Please CC me when you do.
diff --git a/include/net/af_unix.h b/include/net/af_unix.h index 49c4640027d8..4eff0a089640 100644 --- a/include/net/af_unix.h +++ b/include/net/af_unix.h @@ -48,9 +48,6 @@ struct scm_stat { #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 { diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index d013de3c5490..1a0d273799c1 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -170,7 +170,7 @@ static void unix_table_double_lock(struct net *net, swap(hash1, hash2); spin_lock(&net->unx.table.locks[hash1]); - spin_lock_nested(&net->unx.table.locks[hash2], SINGLE_DEPTH_NESTING); + spin_lock(&net->unx.table.locks[hash2]); } static void unix_table_double_unlock(struct net *net, @@ -997,6 +997,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern, u->path.dentry = NULL; u->path.mnt = NULL; spin_lock_init(&u->lock); + lock_set_cmp_fn_ptr_order(&u->lock); atomic_long_set(&u->inflight, 0); INIT_LIST_HEAD(&u->link); mutex_init(&u->iolock); /* single task reading lock */ @@ -1340,17 +1341,11 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) static void unix_state_double_lock(struct sock *sk1, struct sock *sk2) { - if (unlikely(sk1 == sk2) || !sk2) { - unix_state_lock(sk1); - return; - } - if (sk1 < sk2) { + if (sk1 > sk2) + swap(sk1, sk2); + if (sk1 && sk1 != sk2) unix_state_lock(sk1); - unix_state_lock_nested(sk2); - } else { - unix_state_lock(sk2); - unix_state_lock_nested(sk1); - } + unix_state_lock(sk2); } static void unix_state_double_unlock(struct sock *sk1, struct sock *sk2) @@ -1591,7 +1586,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, goto out_unlock; } - unix_state_lock_nested(sk); + unix_state_lock(sk); if (sk->sk_state != st) { unix_state_unlock(sk); @@ -3575,6 +3570,7 @@ static int __net_init unix_net_init(struct net *net) for (i = 0; i < UNIX_HASH_SIZE; i++) { spin_lock_init(&net->unx.table.locks[i]); + lock_set_cmp_fn_ptr_order(&net->unx.table.locks[i]); INIT_HLIST_HEAD(&net->unx.table.buckets[i]); } diff --git a/net/unix/diag.c b/net/unix/diag.c index bec09a3a1d44..8ab5e2217e4c 100644 --- a/net/unix/diag.c +++ b/net/unix/diag.c @@ -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(req); peer = unix_sk(req)->peer; buf[i++] = (peer ? sock_i_ino(peer) : 0); unix_state_unlock(req);