From nobody Tue Dec 16 16:35:21 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 788D4C4167B for ; Thu, 30 Nov 2023 11:57:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345283AbjK3L53 (ORCPT ); Thu, 30 Nov 2023 06:57:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345218AbjK3L5V (ORCPT ); Thu, 30 Nov 2023 06:57:21 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F04110F5 for ; Thu, 30 Nov 2023 03:57:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701345445; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=sVfNW74TR25Kp191FL/LLed7iao257GPYIjo6idrk0M=; b=DhwvaCK8M4oLSYFpeC7ZLvuuF1d18/FUN9ViRt/UsiiPMoCBx/L9Tw56WR3oPCP+hZ1tAi 5xVeDY5y7b1ZR+emdwhpRFgrlFZX8sSVOVT0VdayM1gtcPa1Z9DMNFFPFs2d/TNc9pLXBO q6U9lL13P/g/BD2HtmzjCH0N52j4qC4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-4PhxWY-tNXyeTAF8kl3csA-1; Thu, 30 Nov 2023 06:57:20 -0500 X-MC-Unique: 4PhxWY-tNXyeTAF8kl3csA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 36F491C01401; Thu, 30 Nov 2023 11:57:20 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.2]) by smtp.corp.redhat.com (Postfix) with SMTP id EE73D36E2; Thu, 30 Nov 2023 11:57:13 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 30 Nov 2023 12:56:14 +0100 (CET) Date: Thu, 30 Nov 2023 12:56:06 +0100 From: Oleg Nesterov To: David Howells Cc: Al Viro , Marc Dionne , linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] afs: fix the usage of read_seqbegin_or_lock() in afs_lookup_volume_rcu() Message-ID: <20231130115606.GA21571@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231130115537.GA21550@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" David Howells says: (2) afs_lookup_volume_rcu(). There can be a lot of volumes known by a system. A thousand would require a 10-step walk and this is drivable by remote operation, so I think this should probably take a lock on the second pass too. Make the "seq" counter odd on the 2nd pass, otherwise read_seqbegin_or_lock= () never takes the lock. Signed-off-by: Oleg Nesterov --- fs/afs/callback.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/afs/callback.c b/fs/afs/callback.c index a484fa642808..90f9b2a46ff4 100644 --- a/fs/afs/callback.c +++ b/fs/afs/callback.c @@ -110,13 +110,14 @@ static struct afs_volume *afs_lookup_volume_rcu(struc= t afs_cell *cell, { struct afs_volume *volume =3D NULL; struct rb_node *p; - int seq =3D 0; + int seq =3D 1; =20 do { /* Unfortunately, rbtree walking doesn't give reliable results * under just the RCU read lock, so we have to check for * changes. */ + seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&cell->volume_lock, &seq); =20 p =3D rcu_dereference_raw(cell->volumes.rb_node); --=20 2.25.1.362.g51ebf55 From nobody Tue Dec 16 16:35:21 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDBB1C4167B for ; Thu, 30 Nov 2023 11:57:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345231AbjK3L50 (ORCPT ); Thu, 30 Nov 2023 06:57:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345209AbjK3L5V (ORCPT ); Thu, 30 Nov 2023 06:57:21 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7056510E6 for ; Thu, 30 Nov 2023 03:57:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701345444; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=G3JJovR5ANNN22m1sBKdWmGjw6RkikjOxrrW7bRBDJw=; b=Kp54wFBlod6YFeTo0dPJMszdIsvOebEPGUp6Z1pbR+tZ+xfuub00YsKqkR+pDPzhXnpqkp sHzyc/IQY12xTigc8N7U4SFf/bAWH6+63oxb2FuYgt5HEsZ/gHfK154g5u2XKHXBQrD3hi ihXej+xpM8mjGfc/5x4PdZsozIe3feY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-461-WEd_hmXvPBmloKojSz0weA-1; Thu, 30 Nov 2023 06:57:23 -0500 X-MC-Unique: WEd_hmXvPBmloKojSz0weA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D1ADD810FC1; Thu, 30 Nov 2023 11:57:22 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.2]) by smtp.corp.redhat.com (Postfix) with SMTP id 66053C15983; Thu, 30 Nov 2023 11:57:21 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 30 Nov 2023 12:56:16 +0100 (CET) Date: Thu, 30 Nov 2023 12:56:14 +0100 From: Oleg Nesterov To: David Howells Cc: Al Viro , Marc Dionne , linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] afs: fix the usage of read_seqbegin_or_lock() in afs_find_server*() Message-ID: <20231130115614.GA21581@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231130115537.GA21550@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" David Howells says: (5) afs_find_server(). There could be a lot of servers in the list and each server can have multiple addresses, so I think this would be better with an exclusive second pass. The server list isn't likely to change all that often, but when it does change, there's a good chance several servers are going to be added/removed one after the other. Further, this is only going to be used for incoming cache management/callback requests from the server, which hopefully aren't going to happen too often - but it is remotely drivable. (6) afs_find_server_by_uuid(). Similarly to (5), there could be a lot of servers to search through, b= ut they are in a tree not a flat list, so it should be faster to process. Again, it's not likely to change that often and, again, when it does change it's likely to involve multiple changes. This can be driven remotely by an incoming cache management request but is mostly going to be driven by setting up or reconfiguring a volume's server list - something that also isn't likely to happen often. Make the "seq" counter odd on the 2nd pass, otherwise read_seqbegin_or_lock= () never takes the lock. Signed-off-by: Oleg Nesterov --- fs/afs/server.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/afs/server.c b/fs/afs/server.c index b5237206eac3..0bd2f5ba6900 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c @@ -27,7 +27,7 @@ struct afs_server *afs_find_server(struct afs_net *net, const struct afs_addr_list *alist; struct afs_server *server =3D NULL; unsigned int i; - int seq =3D 0, diff; + int seq =3D 1, diff; =20 rcu_read_lock(); =20 @@ -35,6 +35,7 @@ struct afs_server *afs_find_server(struct afs_net *net, if (server) afs_unuse_server_notime(net, server, afs_server_trace_put_find_rsq); server =3D NULL; + seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&net->fs_addr_lock, &seq); =20 if (srx->transport.family =3D=3D AF_INET6) { @@ -90,7 +91,7 @@ struct afs_server *afs_find_server_by_uuid(struct afs_net= *net, const uuid_t *uu { struct afs_server *server =3D NULL; struct rb_node *p; - int diff, seq =3D 0; + int diff, seq =3D 1; =20 _enter("%pU", uuid); =20 @@ -102,7 +103,7 @@ struct afs_server *afs_find_server_by_uuid(struct afs_n= et *net, const uuid_t *uu if (server) afs_unuse_server(net, server, afs_server_trace_put_uuid_rsq); server =3D NULL; - + seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&net->fs_lock, &seq); =20 p =3D net->fs_servers.rb_node; --=20 2.25.1.362.g51ebf55 From nobody Tue Dec 16 16:35:21 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C892CC4167B for ; Thu, 30 Nov 2023 11:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345291AbjK3L5d (ORCPT ); Thu, 30 Nov 2023 06:57:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345214AbjK3L5X (ORCPT ); Thu, 30 Nov 2023 06:57:23 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCA9599 for ; Thu, 30 Nov 2023 03:57:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701345449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=6RcSbHR7cFN6wAchAsaYdBBxf6WBZ1koqQk/TqaNhwk=; b=Xwupty/nMJJhM/yZticViVqt36a0O2GGZSLPnwYwxxdWGRjA1TMHB122zTXcg5hti9MwSY bHFWH/6m6a6H87MZCTi6aY+WEJENuH0Q59/ZCP5tVjDIgkVlJMoIGb3qAiikch1KHE5Q+U TTTr8k2Y/dBo6QagV4BsJAGNmwVfUzg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-102-cbkPqBosOSuYjqSifHfZyA-1; Thu, 30 Nov 2023 06:57:25 -0500 X-MC-Unique: cbkPqBosOSuYjqSifHfZyA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4944238117F3; Thu, 30 Nov 2023 11:57:25 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.2]) by smtp.corp.redhat.com (Postfix) with SMTP id ED0951C060B1; Thu, 30 Nov 2023 11:57:23 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 30 Nov 2023 12:56:19 +0100 (CET) Date: Thu, 30 Nov 2023 12:56:17 +0100 From: Oleg Nesterov To: David Howells Cc: Al Viro , Marc Dionne , linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] afs: use read_seqbegin() in afs_check_validity() and afs_getattr() Message-ID: <20231130115617.GA21584@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231130115537.GA21550@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" David Howells says: (3) afs_check_validity(). (4) afs_getattr(). These are both pretty short, so your solution is probably good for the= m. That said, afs_vnode_commit_status() can spend a long time under the write lock - and pretty much every file RPC op returns a status update. Change these functions to use read_seqbegin(). This simplifies the code and doesn't change the current behaviour, the "seq" counter is always even so read_seqbegin_or_lock() can never take the lock. Signed-off-by: Oleg Nesterov --- fs/afs/inode.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/afs/inode.c b/fs/afs/inode.c index 78efc9719349..a6ae74d5b698 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -629,10 +629,10 @@ bool afs_check_validity(struct afs_vnode *vnode) enum afs_cb_break_reason need_clear =3D afs_cb_break_no_break; time64_t now =3D ktime_get_real_seconds(); unsigned int cb_break; - int seq =3D 0; + int seq; =20 do { - read_seqbegin_or_lock(&vnode->cb_lock, &seq); + seq =3D read_seqbegin(&vnode->cb_lock); cb_break =3D vnode->cb_break; =20 if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { @@ -650,9 +650,7 @@ bool afs_check_validity(struct afs_vnode *vnode) need_clear =3D afs_cb_break_no_promise; } =20 - } while (need_seqretry(&vnode->cb_lock, seq)); - - done_seqretry(&vnode->cb_lock, seq); + } while (read_seqretry(&vnode->cb_lock, seq)); =20 if (need_clear =3D=3D afs_cb_break_no_break) return true; @@ -755,7 +753,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct p= ath *path, struct inode *inode =3D d_inode(path->dentry); struct afs_vnode *vnode =3D AFS_FS_I(inode); struct key *key; - int ret, seq =3D 0; + int ret, seq; =20 _enter("{ ino=3D%lu v=3D%u }", inode->i_ino, inode->i_generation); =20 @@ -772,7 +770,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct p= ath *path, } =20 do { - read_seqbegin_or_lock(&vnode->cb_lock, &seq); + seq =3D read_seqbegin(&vnode->cb_lock); generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat); if (test_bit(AFS_VNODE_SILLY_DELETED, &vnode->flags) && stat->nlink > 0) @@ -784,9 +782,8 @@ int afs_getattr(struct mnt_idmap *idmap, const struct p= ath *path, */ if (S_ISDIR(inode->i_mode)) stat->size =3D vnode->netfs.remote_i_size; - } while (need_seqretry(&vnode->cb_lock, seq)); + } while (read_seqretry(&vnode->cb_lock, seq)); =20 - done_seqretry(&vnode->cb_lock, seq); return 0; } =20 --=20 2.25.1.362.g51ebf55