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=1796239554; b=aRcjHd2ijvvGzpNhXMVsVFlJ42e1i0BZbOuBbhOBAKi0ub+rbT17OgFW5yqMIGcZV9ih OSG8EF8710mM7rpZjX+579cHOd4HDQOehhXsainGz3xYWC/YPEQpVWqlsOyBoUmKZNGcM 46Cu6hgBtWuVlrvUTNaZ7vq3VPtuSNOXBw62W9x8CdXfXKpUXHZsHAuIc47NeKagJQ8HO 9Fob+9LxsI6wQhimVpMM6AuZtSy1hQK4gzrcDyUzWQFI1I4RiK5BfHRmCHCbgwfY1FeWK ju5/9hYfUZ6A9331UD7N3X3iqTSH5xJy5/PFSRSCcYzlTz9uA8+x5pHlkGT14G3jh6A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796239554; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=XkKsX+NKAMZnKlwh6LIkXAFLUa1wOGmTmymu2z1H98M=; b=4D8Y+7mQCeTCfLdxwcCVlMv0paPfZkkQyeM4aSzvWukaLi5B/BgBslYxAnXlR1L8ABC9 D7/KiEkPSJL9uwGpWuWdY3Hl17csZE9LdY7fTqvg011E+orc2Ulsrqm+C2eXhqWRXY+7v NuzXSVGWBsN32cSrnOTaV6J1khqtgLlfBXLxL/hMcJx7BojDUB/kNNh8kVuseW8xN8HdB ir2X7odtM4GhLi1AfBVfRUnxYvaOmeUd9Zd5u+AuoRsmTrJblbS43bqwTkNgor1fbC+ZP EeAqrz0Y0KGEFpBNaruPO4gPrV/0epkU28hy/sHBUoKUYGd4Qva+QsahMDTpiC938gg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="OMA/2rPK"; 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 7798E606A334 for ; Wed, 2 Dec 2026 19:25:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OMA/2rPK Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4DD61F00897; Wed, 2 Dec 2026 19:25:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796239554; bh=XkKsX+NKAMZnKlwh6LIkXAFLUa1wOGmTmymu2z1H98M=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=OMA/2rPKh3yyQ/JIHsthHTmCRrxFm33LTJrXIZYCU1D+Y6Epyb/bfyqnZi9jws3PD cHCi4ce1yT0QfrbMMVn9HbWFL0IFDTxGnNXBI4FEnJxmI4IQvIMotOMrvIfCwoh8Ra R9svHwIl5H5zzYPcaeqUQlch89MXcxEeikaqpMS42pe2VyJ7MUrTgY7SVZuJmHtQm6 8F1zp747R53shYXHne8kUjqxUpe5vDaT/8jsXQLKZUwHSzGhttiHibDV4GLERu3Ckx Z8XhaAZnbzxga1gWxzXwaC94mRanBBa2fIEyPDh4grfHT2tuXm5ngizjU8KSkX6dCi ZIS1LTNV53BTA== From: Jeff Layton Date: Wed, 02 Dec 2026 14:25:40 -0500 Subject: [PATCH 3/5] nfsd: don't reapply unchanged CB_GETATTR times X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-delegts-fixes-v1-3-e3b237925b24@kernel.org> References: <20261202-delegts-fixes-v1-0-e3b237925b24@kernel.org> In-Reply-To: <20261202-delegts-fixes-v1-0-e3b237925b24@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: linux-nfs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5731; i=jlayton@kernel.org; h=from:subject:message-id; bh=9jwsAYf4+gPhkRSwW4RMec4QcLCZkdQ0qbgjjts2gAk=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBrEHC+Edvs2L9mSCogay8MYlyzfejnUcHIDFvoj FlYd6WxvZGJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaxBwvgAKCRAADmhBGVaC Ffq6D/93qB5W4uKOosFWx2X5+eecaUY+GAW7INznycUsJcKzOxt9T3TPKR/rBMFXMFHzxuf911E 1qxhH4Qg3lwc13jUgJBHaUwwlksLMrUcSdXU332hRL9YtG0fKXCrNRspI6OwvxkdOQWztQ1NUza 9C5m7t3nyuWQaacF0SfC7XOigI5EVwbAnClolHtZbSiMLbbn+aDPmcdNlKn43ke1iFQDh0JR0qm fVKmE9V9O7A2TRXb9ruAlpVipvrlDKs0j1w7tU53lQj8JYCQx2NS26sEvmP32TcD5tTns8KIgUH ALCmp37rQmnnx437krP/CYKCmxfKZNDBzHB5IMChrdRl1vIDso6AlQvjEZ0O0Y+kc+AvraR8GJ1 XU9w53ZbLkXN0q3AEJ2s4IjxmZiJkk4diAy5Y7q/kXXP/XPnF+gZ5R2TNjzYUpS7s9Kv+PJrTau fsxBYfwNl/BlX75dbbhFLpmgrsgHJLqUxO0ig48xGwkl8X3CvbbiFHinDN2NPNhK7DDkBlXgJQz NHpE1ZeahlWpYXUHqisqVmTD1M3B2ONMxejtmwr/3CEcHyket0jRIm+z1wYQxfX7Nv9BXYOEPVx 5hj4oVyM0LJzK1R3yqusvVvgdba+ZeZHwmbPlRfFzWr0XUxko1e3ww5+vGEYJ/SEl/0Opu4egZB +nQMNBDRqjwZD6g== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 ncf_file_modified is sticky, so once a CB_GETATTR reply shows a changed change or size, every later GETATTR calls cb_getattr_update_times(). dl_atime and dl_mtime stay at their grant values, so a reply repeating the holder's times passes vetting each time and is written to the inode again: on xfs, a transaction with a forced i_version bump under the exclusive inode_lock. A time in the future is clamped to the current time, which differs on each call, so a repeat moves the inode's time on every GETATTR. Skip: - a time the inode already holds after truncation, and the ctime update that goes with a skipped mtime; - an exact repeat of the last raw time applied (new dl_cb_[am]time) while it is still in the future. Once the current time passes it, it is applied as is, once. Fixes: 6ae30d6eb26b ("nfsd: add support for delegated timestamps") Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++---- fs/nfsd/state.h | 3 ++ 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 40a598bc5b51..6de15d7fb09c 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -10678,21 +10678,78 @@ bool nfsd4_vet_deleg_time(struct timespec64 *req, const struct timespec64 *orig, return true; } +/* + * Should a vetted CB_GETATTR time be dropped rather than applied? + * dl_atime and dl_mtime stay at their grant values, so a reply that + * repeats the holder's times passes vetting on every GETATTR. Drop a + * time the inode already holds. Also drop an exact repeat of the last + * raw time applied while it is still in the future: it was clamped to + * the current time, and clamping it again would move the inode's time + * on every GETATTR. Once the current time passes it, it's applied as is. + */ +static bool cb_getattr_time_unchanged(struct inode *inode, + const struct timespec64 *vetted, + const struct timespec64 *raw, + const struct timespec64 *last_raw, + const struct timespec64 *cur, + const struct timespec64 *now) +{ + struct timespec64 ts = timestamp_truncate(*vetted, inode); + + if (timespec64_equal(&ts, cur)) + return true; + return timespec64_equal(raw, last_raw) && + timespec64_compare(raw, now) > 0; +} + +/* + * Return @attrs->ia_valid without the vetted CB_GETATTR times that + * cb_getattr_time_unchanged() drops. ctime moves only with a delegated + * mtime. Caller holds inode_lock. + */ +static unsigned int cb_getattr_drop_unchanged(struct inode *inode, + const struct nfs4_delegation *dp, + const struct iattr *attrs, + const struct timespec64 *cb_atime, + const struct timespec64 *cb_mtime, + const struct timespec64 *now) +{ + unsigned int valid = attrs->ia_valid; + struct timespec64 cur; + + cur = inode_get_atime(inode); + if ((valid & ATTR_ATIME_SET) && + cb_getattr_time_unchanged(inode, &attrs->ia_atime, cb_atime, + &dp->dl_cb_atime, &cur, now)) + valid &= ~(ATTR_ATIME | ATTR_ATIME_SET); + cur = inode_get_mtime(inode); + if ((valid & ATTR_MTIME_SET) && + cb_getattr_time_unchanged(inode, &attrs->ia_mtime, cb_mtime, + &dp->dl_cb_mtime, &cur, now)) + valid &= ~(ATTR_MTIME | ATTR_MTIME_SET | + ATTR_CTIME | ATTR_CTIME_SET); + return valid; +} + static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation *dp) { struct inode *inode = d_inode(dentry); struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr; struct nfs4_file *fp = dp->dl_stid.sc_file; + struct timespec64 now, cb_atime, cb_mtime; struct iattr attrs = { }; struct nfsd_file *nf; + unsigned int valid; bool hashed; int ret = 0; if (deleg_attrs_deleg(dp->dl_type)) { - struct timespec64 now = current_time(inode); + now = current_time(inode); + cb_atime = ncf->ncf_cb_atime; + cb_mtime = ncf->ncf_cb_mtime; - attrs.ia_atime = ncf->ncf_cb_atime; - attrs.ia_mtime = ncf->ncf_cb_mtime; + attrs.ia_atime = cb_atime; + attrs.ia_mtime = cb_mtime; if (nfsd4_vet_deleg_time(&attrs.ia_atime, &dp->dl_atime, &now)) attrs.ia_valid |= ATTR_ATIME | ATTR_ATIME_SET; @@ -10746,8 +10803,25 @@ static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation spin_lock(&fp->fi_lock); hashed = delegation_hashed(dp); spin_unlock(&fp->fi_lock); - if (hashed) - ret = notify_change(&nop_mnt_idmap, dentry, &attrs, NULL); + if (!hashed) + goto out_unlock; + + if (deleg_attrs_deleg(dp->dl_type)) { + attrs.ia_valid = cb_getattr_drop_unchanged(inode, dp, &attrs, + &cb_atime, &cb_mtime, + &now); + if (!(attrs.ia_valid & (ATTR_ATIME | ATTR_MTIME))) + goto out_unlock; + } + + /* notify_change() can alter its iattr argument */ + valid = attrs.ia_valid; + ret = notify_change(&nop_mnt_idmap, dentry, &attrs, NULL); + if (!ret && (valid & ATTR_ATIME_SET)) + dp->dl_cb_atime = cb_atime; + if (!ret && (valid & ATTR_MTIME_SET)) + dp->dl_cb_mtime = cb_mtime; +out_unlock: inode_unlock(inode); file_end_write(nf->nf_file); nfsd_file_put(nf); diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 7f2c63cd3bf8..7afdf6ef6727 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -335,6 +335,9 @@ struct nfs4_delegation { struct timespec64 dl_atime; struct timespec64 dl_mtime; struct timespec64 dl_ctime; + /* CB_GETATTR times last applied, before clamping (inode_lock) */ + struct timespec64 dl_cb_atime; + struct timespec64 dl_cb_mtime; /* For dir delegations */ u32 dl_notify_mask; -- 2.56.1