From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 14D4545036; Tue, 16 Jan 2024 00:26:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FX6RM38S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC25FC433C7; Tue, 16 Jan 2024 00:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705364791; bh=cLreHMuGSVq/SIbvcoPyiFSC9i8RJO+pSbjOsfDSuXo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FX6RM38SuLr15IMi8rKf1VYRZ+yVp6HwOu8vfDaLN3bjVaWTUi2elMXbL5AdyTxeb zcR/Wkj/5lU7Wp9GZbmllnSiZcZLZT8hbb3p6E2KHuaaxuZ3eh/yXYj/zs55DlqEf+ NuRZ6mEWehhXgdGg+nLG1jVuTUh+MJPqzxYiZBScAd2AZ7jNIdvhhZZZLJftNPCsKh cobYECB2gzcnrL/RX4XnWSms5spI6gw+/r7OM4egE2aPxL6MkifI9qIIhpdnq4uk7M ooQjkxDZd62e+2fW2p3k620kiuBG/NqUuvUsbeGU/WDCIUrT0WSpdM60kTGbmAAOTu sX98IhCy0coyg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Oleg Nesterov , David Howells , Marc Dionne , linux-afs@lists.infradead.org, Sasha Levin Subject: [PATCH AUTOSEL 5.15 10/13] afs: fix the usage of read_seqbegin_or_lock() in afs_lookup_volume_rcu() Date: Mon, 15 Jan 2024 19:25:46 -0500 Message-ID: <20240116002603.215942-10-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240116002603.215942-1-sashal@kernel.org> References: <20240116002603.215942-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.15.147 Content-Transfer-Encoding: 8bit From: Oleg Nesterov [ Upstream commit 4121b4337146b64560d1e46ebec77196d9287802 ] 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 Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org Link: https://lore.kernel.org/r/20231130115606.GA21571@redhat.com/ Signed-off-by: Sasha Levin --- 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 1b4d5809808d..e0f5dcffe4e3 100644 --- a/fs/afs/callback.c +++ b/fs/afs/callback.c @@ -110,13 +110,14 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell, { struct afs_volume *volume = NULL; struct rb_node *p; - int seq = 0; + int seq = 1; 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); p = rcu_dereference_raw(cell->volumes.rb_node); -- 2.43.0