From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (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 DC83A35C1B6; Mon, 27 Apr 2026 03:37:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777261070; cv=none; b=NK3CnRL3lqiwTK1ODj9ZBe/VYy/XNuCUJLhccIzWPA3Qb+QYHQAr2MAUtfDywG6CDpBxnA29StNJEUUFE1+w7AW7jImdhG/ns4TDoG5LcT81MVQchGPrKTkrtkkK5v+1MMHNcxa2cFX3EcIV4QlGLh1bE1Oco8XHhSm2icLcZiY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777261070; c=relaxed/simple; bh=R8RTr73kDdtIdtZlHNHhZGf1H97V3ZZBbREhAgyCF6g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HvWMUtXJeaqA0aaDtvywVdhxJE15kK3FJ0bqBJqAZenU7+NJqQl99IFprbYwNcIwacdm15KTZPdFQb95V7KT+JIRXrEA1ZQDvvhBfNL/YvolQ0p+0UnQmqhVApPkMno8xdqc3X+F4IET0FLfkr8Bu1TGfm10eT4O2eOPhAnQkV8= 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=n/Jl9BPQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=JnzLS7fm; arc=none smtp.client-ip=103.168.172.156 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="n/Jl9BPQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JnzLS7fm" Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 319D114000C1; Sun, 26 Apr 2026 23:37:48 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Sun, 26 Apr 2026 23:37:48 -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=fm2; t=1777261068; x=1777347468; bh=9AVqWdMXv3arOefL33JAEpcHRtNfzSlIFOE+OQc0Rdg=; b= n/Jl9BPQnrzgqkfxnYh++OtV4pu5XTi7d6V1bsjLo8BKyHnDZwKFs0GoPXinSGqe jkvX9V91C/aydWlY9Qh86chu+18XNpyLNn5iiFriP/psg8rogTQCaX3Xx6RyPLE+ FL38nFi2Xx4/ONA0/uO0rdQvXpzthdc+uF+AuR4/gjIyQz16KLRNKq1YCqPIWQzS n2yxGa6Xp6wwK69VVRAcL8EZ1K8Lp8/Wzbu1+Pl32401b/ZDqd2J3lioAjEhZsTQ QtepihsFCOORDu3Q04kWChqgzGB1a9iuC9CV00jqJhB+ZSunRmh1VVKpMr8bGLGW z6Qc3cVces+5E7xk4v5yBg== 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=fm2; t=1777261068; x=1777347468; bh=9 AVqWdMXv3arOefL33JAEpcHRtNfzSlIFOE+OQc0Rdg=; b=JnzLS7fm3gCHv27/b 6QOk2QODprz9PUPLJ8HyFbAobK0ZAZMKgTqmhm6PRYtbkuNhIDDqWjwNT67r2Lyw iRVAmFKmuleq2DoQ5NmRx7smlM0loIyoIsDbaDluvPPo9ElKzEOH3NIje+a/G5pW CugvlNmFbmwIJHKKAdGBJh4QldedBC9CL9U0mIwPBeoGHudk1wJDMu3X51PhoDNH NJCktrqZLLVliAgDeHU9hRLS4bhK+tjroD5nr4TSBpg63JvQFM8jDvvPnZA8s3ux yl6rC/BBSyZ7cx6P0jysyi/F1Yrc9Ny1HLq6hxD4aSAtycNhMksV9lMrDXrLd0F8 i9hXA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdejjeeivdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefhvfevufffkffojghfrhgggfestdekredtredttdenucfhrhhomheppfgvihhluehr ohifnhcuoehnvghilhgssehofihnmhgrihhlrdhnvghtqeenucggtffrrghtthgvrhhnpe evveekffduueevhfeigefhgfdukedtleekjeeitdejudfgueekvdekffdvfedvudenucev lhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehnvghilhgsse hofihnmhgrihhlrdhnvghtpdhnsggprhgtphhtthhopedujedpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepvhhirhhoseiivghnihhvrdhlihhnuhigrdhorhhgrdhukhdprh gtphhtthhopehlihhnuhigqdhunhhiohhnfhhssehvghgvrhdrkhgvrhhnvghlrdhorhhg pdhrtghpthhtoheplhhinhhugidqnhhfshesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehlihhnuhigqdhfshguvghvvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg pdhrtghpthhtoheplhhinhhugidqvghfihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdprhgtphht thhopehmihhklhhoshesshiivghrvgguihdrhhhupdhrtghpthhtohepjhgrtghksehsuh hsvgdrtgiipdhrtghpthhtohepjhhksehoiihlrggsshdrohhrgh X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 26 Apr 2026 23:37:43 -0400 (EDT) From: NeilBrown To: Linus Torvalds , Alexander Viro , Christian Brauner , Jan Kara , Jeff Layton , Trond Myklebust , Anna Schumaker , Miklos Szeredi , Amir Goldstein , Jeremy Kerr , Ard Biesheuvel , Christoph Hellwig Cc: linux-efi@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel Subject: [PATCH v2 13/19] nfs: remove d_drop()/d_alloc_parallel() from nfs_atomic_open() Date: Mon, 27 Apr 2026 13:29:46 +1000 Message-ID: <20260427033527.773006-14-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20260427033527.773006-1-neilb@ownmail.net> References: <20260427033527.773006-1-neilb@ownmail.net> Reply-To: NeilBrown Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: NeilBrown It is important that two non-create NFS "open"s of a negative dentry don't race. They both have only a shared lock on i_rwsem and so could run concurrently, but they might both try to call d_splice_alias() at the same time which is confusing at best. nfs_atomic_open() currently avoids this by discarding the negative dentry and creating a new one using d_alloc_parallel(). Only one thread can successfully get the d_in_lookup() dentry, the other will wait for the first to finish, and can use the result of that first lookup. A proposed locking change inverts the order between i_rwsem and d_alloc_parallel() so it will not be safe to call d_alloc_parallel() while holding i_rwsem - even shared. We can achieve the same effect by causing ->d_revalidate to invalidate a negative dentry when LOOKUP_OPEN is set. Doing this is consistent with the "close to open" caching semantics of NFS which requires the server to be queried whenever opening a file - cached information must not be trusted. With this change to ->d_revaliate (implemented in nfs_neg_need_reval) we can be sure that we have exclusive access to any dentry that reaches nfs_atomic_open(). Either O_CREAT was requested and so the parent is locked exclusively, or the dentry will have DCACHE_PAR_LOOKUP set. This means that the d_drop() and d_alloc_parallel() calls in nfs_atomic_lookup() are no longer needed to provide exclusion Signed-off-by: NeilBrown --- fs/nfs/dir.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 9580af999d70..0791fc2d161b 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1656,6 +1656,13 @@ int nfs_neg_need_reval(struct inode *dir, struct dentry *dentry, { if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)) return 0; + if (flags & LOOKUP_OPEN) + /* close-to-open semantics require we go to server + * on each open. By invalidating the dentry we + * also ensure nfs_atomic_open() always has exclusive + * access to the dentry. + */ + return 0; if (NFS_SERVER(dir)->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) return 1; /* Case insensitive server? Revalidate negative dentries */ @@ -2111,7 +2118,6 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry, struct inode *inode; unsigned int lookup_flags = 0; unsigned long dir_verifier; - bool switched = false; int created = 0; int err; @@ -2156,17 +2162,6 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry, attr.ia_size = 0; } - if (!(open_flags & O_CREAT) && !d_in_lookup(dentry)) { - d_drop(dentry); - switched = true; - dentry = d_alloc_parallel(dentry->d_parent, - &dentry->d_name); - if (IS_ERR(dentry)) - return PTR_ERR(dentry); - if (unlikely(!d_in_lookup(dentry))) - return finish_no_open(file, dentry); - } - ctx = create_nfs_open_context(dentry, open_flags, file); err = PTR_ERR(ctx); if (IS_ERR(ctx)) @@ -2209,10 +2204,6 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry, trace_nfs_atomic_open_exit(dir, ctx, open_flags, err); put_nfs_open_context(ctx); out: - if (unlikely(switched)) { - d_lookup_done(dentry); - dput(dentry); - } return err; no_open: @@ -2235,13 +2226,6 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry, res = ERR_PTR(-EOPENSTALE); } } - if (switched) { - d_lookup_done(dentry); - if (!res) - res = dentry; - else - dput(dentry); - } return finish_no_open(file, res); } EXPORT_SYMBOL_GPL(nfs_atomic_open); -- 2.50.0.107.gf914562f5916.dirty