Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795061473; b=sLncGt+nFA8UrIF3vcdnpvwM70lzpCWuNZf/BycFzHCT2rawTTteBnCV4urVliKwwWpe 84XuPun3udzTGr1v5sVwldbqwhq0Ad/sacQqoSlSI/gGmyVRwGvgh6L8wjWRRmv86bd3F nCEpk01akJSfypfWn2b1f2qZVK3gMgT7PWRz/Ax1QNU3uN+2IdQs7vcE4oR6UfIUo5Kb5 dmOEiNXIQyO2ZYX/mqWOJcfd0C2Oc1wtAOVCoA4P4FeKlC+v1eiQoO1DniBFjMQ+wbFuq 8pz6ex7etRHoWJ4jnut65hKQTjvnSPeNyDsdRyc1wdZqhcgINZP4wRHHJoKVbyJXRQQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795061473; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=Mf/xCF58E7OwqTTzcHj75WEmS0Ykax2nF/NirQqFxVY=; b=aWk6L85IdSOp+lL6PLSWZNVIMUXq84YZW2KDQcm0cbL8Pm7lJT8FWWPibdlCQF1rUq0M yPFroNHRorN/lqDSC9U3FWzB2E+zauT49AHAaQirYORDTRGjsvZrpee2VyqW5Ppag2+c3 99cUOINm8o5Pmvd7mH178/R3T4NQOrbGEG5FlP/4fVXLe3LTw1MaRzamVSJJt5/chnPHp tMMfL8BdflaHZvOJ6C36W3Y8nAQd9wJe5OxTIDSsIb6qr5q6y/9SQIHp4zmFHsKnUVKOU MfPwlvr/zX8bvlo5FuRhVp3fE2ZBQwQ69/NjA0YIIU1OOONC/h5L5C8d9rZalUjzEQg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="ExuDUe4/"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70A05606A325; Thu, 19 Nov 2026 04:11:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ExuDUe4/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F31E1F000C5; Thu, 19 Nov 2026 04:11:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795061473; bh=Mf/xCF58E7OwqTTzcHj75WEmS0Ykax2nF/NirQqFxVY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ExuDUe4/5aiY2u6+aq6YGbWppBdRbNjRsd7PE74OXjZcSCjwAIBkzRe+hqvnoF/fO Qr199R8T76Qrk3V1HZYr6NIOOyLkgfim6O/kX9q38a7ONywulxNZcirJ9UDm5eUO0K qnq5t0fndSFJ0b63yrOaamBdOjHfVDrKmthKaSHw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Roberto Bergantinos Corpas , Anna Schumaker , Sasha Levin Subject: [PATCH 5.10 1566/1848] nfs: set gencount on protocol-specific remove Date: Wed, 18 Nov 2026 16:00:04 +0100 Message-ID: <20261118150025.137802889@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118145911.150052362@linuxfoundation.org> References: <20261118145911.150052362@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Roberto Bergantinos Corpas [ Upstream commit 8c955dacf45f8964b98f26910ffecb5e26c02e31 ] commit bd4928ec799b ("NFS: Avoid changing nlink when file removes and attribute updates race") avoids races on attribute cache with any inflight RPC that may modify inode attributes (and gencount) during i.e. REMOVE. However it does not take into account that REMOVE may trigger a delegation return which also advances gencount (via the attribute refresh during delegation return), and in that case the gencount mismatch is not due to an inflight RPC that already reflected the removal. Push the setting of gencount under each version-specific layer, reordering correctly for nfsv4 case after the delegation returns. This fixes LTP/inotify04 failure after bd4928ec799b. Fixes: bd4928ec799b ("NFS: Avoid changing nlink when file removes and attribute updates race") Signed-off-by: Roberto Bergantinos Corpas Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- fs/nfs/dir.c | 13 +++---------- fs/nfs/internal.h | 1 + fs/nfs/nfs3proc.c | 8 ++++++++ fs/nfs/nfs4proc.c | 5 +++++ fs/nfs/proc.c | 8 ++++++++ 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index a4af767149538..ea383f614a97a 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1523,7 +1523,7 @@ static int nfs_dentry_delete(const struct dentry *dentry) } /* Ensure that we revalidate inode->i_nlink */ -static void nfs_drop_nlink(struct inode *inode, unsigned long gencount) +void nfs_drop_nlink(struct inode *inode, unsigned long gencount) { struct nfs_inode *nfsi = NFS_I(inode); @@ -1537,6 +1537,7 @@ static void nfs_drop_nlink(struct inode *inode, unsigned long gencount) NFS_INO_INVALID_OTHER | NFS_INO_REVAL_FORCED); spin_unlock(&inode->i_lock); } +EXPORT_SYMBOL_GPL(nfs_drop_nlink); /* * Called when the dentry loses inode. @@ -2079,7 +2080,6 @@ EXPORT_SYMBOL_GPL(nfs_rmdir); static int nfs_safe_remove(struct dentry *dentry) { struct inode *dir = d_inode(dentry->d_parent); - struct inode *inode = d_inode(dentry); int error = -EBUSY; dfprintk(VFS, "NFS: safe_remove(%pd2)\n", dentry); @@ -2091,14 +2091,7 @@ static int nfs_safe_remove(struct dentry *dentry) } trace_nfs_remove_enter(dir, dentry); - if (inode != NULL) { - unsigned long gencount = READ_ONCE(NFS_I(inode)->attr_gencount); - - error = NFS_PROTO(dir)->remove(dir, dentry); - if (error == 0) - nfs_drop_nlink(inode, gencount); - } else - error = NFS_PROTO(dir)->remove(dir, dentry); + error = NFS_PROTO(dir)->remove(dir, dentry); if (error == -ENOENT) nfs_dentry_handle_enoent(dentry); trace_nfs_remove_exit(dir, dentry, error); diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index abd0ba394e42f..93c7e286c393d 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -395,6 +395,7 @@ extern unsigned long nfs_access_cache_count(struct shrinker *shrink, struct shrink_control *sc); extern unsigned long nfs_access_cache_scan(struct shrinker *shrink, struct shrink_control *sc); +extern void nfs_drop_nlink(struct inode *inode, unsigned long gencount); struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int); int nfs_create(struct inode *, struct dentry *, umode_t, bool); int nfs_mkdir(struct inode *, struct dentry *, umode_t); diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c index e1491def7124f..d6306899eec79 100644 --- a/fs/nfs/nfs3proc.c +++ b/fs/nfs/nfs3proc.c @@ -419,13 +419,21 @@ nfs3_proc_remove(struct inode *dir, struct dentry *dentry) .rpc_resp = &res, }; int status = -ENOMEM; + struct inode *inode = d_inode(dentry); + unsigned long gencount; dprintk("NFS call remove %pd2\n", dentry); res.dir_attr = nfs_alloc_fattr(); if (res.dir_attr == NULL) goto out; + if (inode) + gencount = READ_ONCE(NFS_I(inode)->attr_gencount); + status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); + if (status == 0 && inode) + nfs_drop_nlink(inode, gencount); + nfs_post_op_update_inode(dir, res.dir_attr); nfs_free_fattr(res.dir_attr); out: diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 94a290c8f648a..7028b46b5579b 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -4645,12 +4645,14 @@ static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) }; struct inode *inode = d_inode(dentry); int err; + unsigned long gencount; if (inode) { if (inode->i_nlink == 1) nfs4_inode_return_delegation(inode); else nfs4_inode_make_writeable(inode); + gencount = READ_ONCE(NFS_I(inode)->attr_gencount); } do { err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); @@ -4658,6 +4660,9 @@ static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); } while (exception.retry); + + if (err == 0 && inode) + nfs_drop_nlink(inode, gencount); return err; } diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c index 15c865cc837fa..2ba9b83202974 100644 --- a/fs/nfs/proc.c +++ b/fs/nfs/proc.c @@ -322,9 +322,17 @@ nfs_proc_remove(struct inode *dir, struct dentry *dentry) .rpc_argp = &arg, }; int status; + struct inode *inode = d_inode(dentry); + unsigned long gencount; dprintk("NFS call remove %pd2\n",dentry); + if (inode) + gencount = READ_ONCE(NFS_I(inode)->attr_gencount); + status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); + if (status == 0 && inode) + nfs_drop_nlink(inode, gencount); + nfs_mark_for_revalidate(dir); dprintk("NFS reply remove: %d\n", status); -- 2.53.0