From nobody Tue Dec 16 23:40:36 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