From nobody Tue Dec 16 23:56:07 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