From nobody Tue Apr 7 16:16:38 2026 Received: from flow-b5-smtp.messagingengine.com (flow-b5-smtp.messagingengine.com [202.12.124.140]) (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 F1F7F30E0F5; Fri, 13 Mar 2026 00:46:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.140 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773362785; cv=none; b=fDtKIH7WKHYoawMyRMIADuSWc+yBdyrVj5mULZ8CL6vt0R+0PwzrBgGqKi/fzaz6yQtDD3yK/RnqsqZADIiWrZf8GptoQvregszQZaxzhW0PCukso1f3i9T+Hi/Pw0fV2fGyVqyNF5y4JwyE8XgpJiZGR/BdNIgETgJ9NcKRTMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773362785; c=relaxed/simple; bh=tv8rKn4N2IeoFeMnFx+2x9JGOMGaY+wE9fF08LJwdQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=coavq4eHehs7M7b7ep4G5L7sEGWLykXSOI3H3GYZbc2bW0jReJAIeLcl2Ziu6F6DdQ1WnCMWiqmTqAaTT+uf9ope/lkvIZf0kt0qXU+fCurp2tfeRC7EZzV829LAw/FZ4qaTR73xLsFtuXN7txQiFvFfiiw2rgBG7Z+mBvzSL+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net; spf=pass smtp.mailfrom=ownmail.net; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b=WHV8jLjR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZIH5/VZH; arc=none smtp.client-ip=202.12.124.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ownmail.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b="WHV8jLjR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZIH5/VZH" Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailflow.stl.internal (Postfix) with ESMTP id 2F4F01301B58; Thu, 12 Mar 2026 20:46:21 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Thu, 12 Mar 2026 20:46:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ownmail.net; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to; s=fm1; t=1773362781; x=1773369981; bh=beibKrJw8gVlJSS1MC+gPsWPAAjnc1lfM9GVMreQ7l0=; b= WHV8jLjRFjvExaZUz/IeuFgzAji4iuC1qCdaaeCT+yhJO1A8Jy46xlJATz84RftX 8ziuDP+FIoVk37AiwmkWNq59mHh58p+afnfWD/PswUpqQxv2VeqaDwUpCCy1ua2S UTsPcAo+khmfNmWIe4/dEMaxZPSeXxrGb/QhRIAyhV4Q0EucmpogkjrKFycwgKSu 8XvmsnDj5S9ck3EDBgdc36XgPp5YT7phSDnE54m2kT6FBaPSFqUxsEP5LfQT8Ibd kwPFZIqhYefJcMp6GHUuks2lW91o2lXD9/uMMRk5odSMf2vU+pN6LAFgjwuofxko Pxd4qYjc0WMvZ9umgpIH+Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1773362781; x=1773369981; bh=b eibKrJw8gVlJSS1MC+gPsWPAAjnc1lfM9GVMreQ7l0=; b=ZIH5/VZHZrMfU1cW/ wG0qw06iFIqEqoHXhM5fZAFsUmmSTK8s5iHKFawt41sSzRFI2voGV/g2vxNPRvvZ QT4aLkhEZTZsQGWPLjlqLtmevQqurNCd2EhPslV4EIvWQatGKGq6tQ6DUKA7hkfJ wjgHPYeUDwzEedB/fhcD6NPn128Xk4owWwoTOWNwhF+JKbEEbpihYJy0ES1ozFab f79UKDfTMpYIQuiK2/rFGv9Osd/YLjjgERMzFcZkc7zkq+y6Jg08tF8TybJSGwX8 LmtR+qvbnSUv3BTDBUn27O3PhnWN1IVPZyiwC0uUVCe52zEbcPFy0n0GgdtLfz4g ljLng== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvkeekvdeiucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhhrggfgsedtkeertdertddtnecuhfhrohhmpefpvghilheu rhhofihnuceonhgvihhlsgesohifnhhmrghilhdrnhgvtheqnecuggftrfgrthhtvghrnh epveevkeffudeuvefhieeghffgudektdelkeejiedtjedugfeukedvkeffvdefvddunecu vehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepnhgvihhlsg esohifnhhmrghilhdrnhgvthdpnhgspghrtghpthhtohephedupdhmohguvgepshhmthhp ohhuthdprhgtphhtthhopehvihhrohesiigvnhhivhdrlhhinhhugidrohhrghdruhhkpd hrtghpthhtoheplhhinhhugidqgihfshesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgt phhtthhopehlihhnuhigqdhunhhiohhnfhhssehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtoheplhhinhhugidqthhrrggtvgdqkhgvrhhnvghlsehvghgvrhdrkhgvrhhn vghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqnhhfshesvhhgvghrrdhkvghrnhgvlh drohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgv lhdrohhrghdprhgtphhtthhopehlihhnuhigqdhfshguvghvvghlsehvghgvrhdrkhgvrh hnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqvgigthegsehvghgvrhdrkhgvrhhn vghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqvghfihesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Mar 2026 20:46:07 -0400 (EDT) From: NeilBrown To: Linus Torvalds , Alexander Viro , Christian Brauner , Jan Kara , Jeff Layton , Trond Myklebust , Anna Schumaker , Carlos Maiolino , Miklos Szeredi , Amir Goldstein , Jan Harkes , Hugh Dickins , Baolin Wang , David Howells , Marc Dionne , Steve French , Namjae Jeon , Sungjong Seo , Yuezhang Mo , Andreas Hindborg , Breno Leitao , "Theodore Ts'o" , Andreas Dilger , Steven Rostedt , Masami Hiramatsu , Ilya Dryomov , Alex Markuze , Viacheslav Dubeyko , Tyler Hicks , Andreas Gruenbacher , Richard Weinberger , Anton Ivanov , Johannes Berg , Jeremy Kerr , Ard Biesheuvel Cc: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-unionfs@vger.kernel.org, coda@cs.cmu.edu, linux-mm@kvack.org, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, ceph-devel@vger.kernel.org, ecryptfs@vger.kernel.org, gfs2@lists.linux.dev, linux-um@lists.infradead.org, linux-efi@vger.kernel.org Subject: [PATCH 26/53] smb/client: don't unhashed and rehash to prevent new opens. Date: Fri, 13 Mar 2026 08:12:13 +1100 Message-ID: <20260312214330.3885211-27-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20260312214330.3885211-1-neilb@ownmail.net> References: <20260312214330.3885211-1-neilb@ownmail.net> Reply-To: NeilBrown Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: NeilBrown smb/client needs to block new opens of the target of unlink and rename while the operation is progressing. This stablises d_count() and allows a determination of whether a "silly-rename" is required. It currently unhashes the dentry which will cause lookup to block on the parent directory i_rwsem. Proposed changes to locking will cause this approach to stop working and the exclusivity will be provided for the dentry only, and only while it is hashed. So we introduce a new machanism similar to that used by nfs and afs. ->d_fsdata (currently unused by smb/client) is set to a non-NULL value when lookups need to be blocked. ->d_revalidate checks for this and blocks. This might still allow d_count() to increment, but once it has been tested as 1, there can be no new opens completed. Signed-off-by: NeilBrown --- fs/smb/client/dir.c | 3 +++ fs/smb/client/inode.c | 48 +++++++++++++++++-------------------------- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/fs/smb/client/dir.c b/fs/smb/client/dir.c index cb10088197d2..cecbc0cce5c5 100644 --- a/fs/smb/client/dir.c +++ b/fs/smb/client/dir.c @@ -790,6 +790,9 @@ cifs_d_revalidate(struct inode *dir, const struct qstr = *name, if (flags & LOOKUP_RCU) return -ECHILD; =20 + /* Wait for pending rename/unlink */ + wait_var_event(&direntry->d_fsdata, direntry->d_fsdata =3D=3D NULL); + if (d_really_is_positive(direntry)) { int rc; struct inode *inode =3D d_inode(direntry); diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index d4d3cfeb6c90..3549605fa9c2 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -28,6 +28,13 @@ #include "cached_dir.h" #include "reparse.h" =20 +/* This is stored in ->d_fsdata to block d_revalidate on a + * file dentry that is being removed - unlink or rename target. + * This causes any open attempt to block. There may be existing opens + * but they can be detected by checking d_count() under ->d_lock. + */ +#define CIFS_FSDATA_BLOCKED ((void *)1) + /* * Set parameters for the netfs library */ @@ -1946,27 +1953,21 @@ static int __cifs_unlink(struct inode *dir, struct = dentry *dentry, bool sillyren __u32 dosattr =3D 0, origattr =3D 0; struct TCP_Server_Info *server; struct iattr *attrs =3D NULL; - bool rehash =3D false; =20 cifs_dbg(FYI, "cifs_unlink, dir=3D0x%p, dentry=3D0x%p\n", dir, dentry); =20 if (unlikely(cifs_forced_shutdown(cifs_sb))) return smb_EIO(smb_eio_trace_forced_shutdown); =20 - /* Unhash dentry in advance to prevent any concurrent opens */ - spin_lock(&dentry->d_lock); - if (!d_unhashed(dentry)) { - __d_drop(dentry); - rehash =3D true; - } - spin_unlock(&dentry->d_lock); - tlink =3D cifs_sb_tlink(cifs_sb); if (IS_ERR(tlink)) return PTR_ERR(tlink); tcon =3D tlink_tcon(tlink); server =3D tcon->ses->server; =20 + /* Set d_fsdata to prevent any concurrent opens */ + dentry->d_fsdata =3D CIFS_FSDATA_BLOCKED; + xid =3D get_xid(); page =3D alloc_dentry_path(); =20 @@ -2083,8 +2084,9 @@ static int __cifs_unlink(struct inode *dir, struct de= ntry *dentry, bool sillyren kfree(attrs); free_xid(xid); cifs_put_tlink(tlink); - if (rehash) - d_rehash(dentry); + + /* Allow lookups */ + store_release_wake_up(&dentry->d_fsdata, NULL); return rc; } =20 @@ -2501,7 +2503,6 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *s= ource_dir, struct cifs_sb_info *cifs_sb; struct tcon_link *tlink; struct cifs_tcon *tcon; - bool rehash =3D false; unsigned int xid; int rc, tmprc; int retry_count =3D 0; @@ -2517,23 +2518,15 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode = *source_dir, if (unlikely(cifs_forced_shutdown(cifs_sb))) return smb_EIO(smb_eio_trace_forced_shutdown); =20 - /* - * Prevent any concurrent opens on the target by unhashing the dentry. - * VFS already unhashes the target when renaming directories. - */ - if (d_is_positive(target_dentry) && !d_is_dir(target_dentry)) { - if (!d_unhashed(target_dentry)) { - d_drop(target_dentry); - rehash =3D true; - } - } - tlink =3D cifs_sb_tlink(cifs_sb); if (IS_ERR(tlink)) return PTR_ERR(tlink); tcon =3D tlink_tcon(tlink); server =3D tcon->ses->server; =20 + /* Set d_fsdata to prevent any concurrent opens */ + target_dentry->d_fsdata =3D CIFS_FSDATA_BLOCKED; + page1 =3D alloc_dentry_path(); page2 =3D alloc_dentry_path(); xid =3D get_xid(); @@ -2570,8 +2563,6 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *s= ource_dir, } } =20 - if (!rc) - rehash =3D false; /* * No-replace is the natural behavior for CIFS, so skip unlink hacks. */ @@ -2662,8 +2653,6 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *s= ource_dir, } rc =3D cifs_do_rename(xid, source_dentry, from_name, target_dentry, to_name); - if (!rc) - rehash =3D false; } } =20 @@ -2671,8 +2660,9 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *s= ource_dir, CIFS_I(source_dir)->time =3D CIFS_I(target_dir)->time =3D 0; =20 cifs_rename_exit: - if (rehash) - d_rehash(target_dentry); + /* Allow lookups */ + store_release_wake_up(&target_dentry->d_fsdata, NULL); + kfree(info_buf_source); free_dentry_path(page2); free_dentry_path(page1); --=20 2.50.0.107.gf914562f5916.dirty