Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp608107rdb; Sun, 28 Jan 2024 00:29:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzYgk9UrSH7PP5AaliomHqk/A+JqJZeOJIxQr6jMnYKaKxK2VaWFPr/75jN4+IVahIDJr8 X-Received: by 2002:a05:6a20:6a86:b0:199:a6cb:20ab with SMTP id bi6-20020a056a206a8600b00199a6cb20abmr2356182pzb.123.1706430552675; Sun, 28 Jan 2024 00:29:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706430552; cv=pass; d=google.com; s=arc-20160816; b=tuVv3qocMqKH1kERieNyGp8Fu5IL12D26QRpKTBens9YMwUzS6UAEgc+Sd8dPtve3z TY7LTgwPE68FL3h/M3RUCMPGFtxSZ9B9kp5SZ+m2iEic3q7rjEDUypQy0VzIpI1Qy/Vu T4h2kD0RKg2eH9F2wZtUvmxi1od0GFXm5vS/rDwawdUbGwqEp0yvzREc89qAEVgtFwsM 6iNWKXwZrmwaoV4xW+jrTGHo51BaR9ZUquHQUzQidBXuWcRtnRB2jBNsAYwaZwaF7ZfC RZ6WM7rpFTLp2dz0/yUepJ+h30SyH2NJje4zBDs86j7aqw4KPTKOisXRpYXyg2c+Jqep q72A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=precedence: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=Aer27LddC3vgYFmEG+ckZUqU4qn8n6YISCTG6G1GZy8=; fh=rVFZznV7aQfvA+dzaiELucjJrud5+NVcwTT3PBaHRTI=; b=fAFpDMQhWQTKlPycP2fM0NnngM2YDt6rRytB/6WrAaP5yyi/5M3sgg2s59dHzd2OeM Xo1fMMjXcJhFBhJGeb80TNy0oNnZhFpD8gzlalok3SZl/dQ+UYoqD/H0xnIXU0rV7XpN 8Gkb/vjBk4PDIhNY8KSnFAAdWQyYY5T4K7kSm5cc3NBqcUXuGzMkWH2XGsM/TcAT1hCX PNUzuhPPR1XjuuTg4eoNRkGnpARI5Zt8gIfECB+Sy9pn+5AP7MjXY7oz3mtnSJMi08vT NgUjIhkeff6OaHR9U9nt7D4YaS5jOGw449L5K8QSfxcu7dXT8DHBhrmRSK5Eg3npY490 LeqA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=VgHeaGEL; arc=pass (i=1 spf=pass spfdomain=amazon.co.jp dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-41562-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41562-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ln12-20020a056a003ccc00b006ddce890c13si3943233pfb.267.2024.01.28.00.29.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 00:29:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41562-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=VgHeaGEL; arc=pass (i=1 spf=pass spfdomain=amazon.co.jp dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-41562-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41562-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E02FAB2114C for ; Sun, 28 Jan 2024 08:29:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 76279DF49; Sun, 28 Jan 2024 08:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="VgHeaGEL" Received: from smtp-fw-52005.amazon.com (smtp-fw-52005.amazon.com [52.119.213.156]) (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 A03E8D536; Sun, 28 Jan 2024 08:28:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.156 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706430535; cv=none; b=i4V9AnslqtD5iCsdjxeaJDms+v3Wet0BjyiL4q3B0clgnomHFQcG9dt/wfT4ucYRBan9RLBLy0km4J9utxsZIS/PFn95v+2xx4FO+IhksERVjPR44Ksl54Cade1qZX+HTu+b1e4GESWkO509r/TPxJsoIfTVHA+TZUQZdttNHZQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706430535; c=relaxed/simple; bh=VZJ32uBSnHeYLRqyWtoGJ+vKF2durp0l+kmkeHMQY4g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uB/ua+2Igt6iGv9TOb81S6d8Ab95AJdoAB+s2TBymZ2Q5zIaSnSA9DngXCP5iiuV6ln6/EQsItkhr5V7FSEPzJa2YLoxGliz8CTXTeYNzNnyxTNGIY61wYu7XqXahThpcVxggYWKLtPrWOYkqIJVid3dcvIVBcTJQbG1MfE26ok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=VgHeaGEL; arc=none smtp.client-ip=52.119.213.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1706430533; x=1737966533; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Aer27LddC3vgYFmEG+ckZUqU4qn8n6YISCTG6G1GZy8=; b=VgHeaGELqUwp7GAJTzhRXTiNKRZy5doIseqYQYbIP0Em+fusrfWfImOp 2lTPH/sQslDYPUUE7dgkDTLyC48CjZJznQpoFe6ITEzrHlhxaK4eomVBE MebhBQjDGOSiIdVy3aWpOy+elbi8LgMwgMnM5GiLNdumoadZxCvAbboWM c=; X-IronPort-AV: E=Sophos;i="6.05,220,1701129600"; d="scan'208";a="630396084" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2c-m6i4x-8c5b1df3.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-52005.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2024 08:28:51 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan3.pdx.amazon.com [10.39.38.70]) by email-inbound-relay-pdx-2c-m6i4x-8c5b1df3.us-west-2.amazon.com (Postfix) with ESMTPS id 1D98440D4A; Sun, 28 Jan 2024 08:28:50 +0000 (UTC) Received: from EX19MTAUWA002.ant.amazon.com [10.0.7.35:28618] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.3.8:2525] with esmtp (Farcaster) id a741d178-266c-4cf2-9742-14a26ef5d16b; Sun, 28 Jan 2024 08:28:49 +0000 (UTC) X-Farcaster-Flow-ID: a741d178-266c-4cf2-9742-14a26ef5d16b Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Sun, 28 Jan 2024 08:28:49 +0000 Received: from 88665a182662.ant.amazon.com (10.106.101.48) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Sun, 28 Jan 2024 08:28:46 +0000 From: Kuniyuki Iwashima To: CC: , , , , , Subject: Re: [PATCH 4/4] af_unix: convert to lock_cmp_fn Date: Sun, 28 Jan 2024 00:28:38 -0800 Message-ID: <20240128082838.3961-1-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240127020833.487907-5-kent.overstreet@linux.dev> References: <20240127020833.487907-5-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D038UWB003.ant.amazon.com (10.13.139.157) To EX19D004ANA001.ant.amazon.com (10.37.240.138) Precedence: Bulk From: Kent Overstreet 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 > --- > 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