From nobody Mon Oct 6 10:13:30 2025 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 324C7283FDD; Tue, 22 Jul 2025 18:52:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753210362; cv=none; b=OK5+Q2Mv1Pvixr9D0n8a30iFhY8YY1F0XL0tQCKQfijwDRDNhwIudLoYVCCGXEOJPpskNUn4M5THTA8V+Hx1Ar1d5Y1Kds8cGpxWNuJkiBvNihMMIiZRlawS0/QsKVCyfz7QMIT7uJ53d2SEP0B9ldH7oc0Y3nJKEG0qSNBchls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753210362; c=relaxed/simple; bh=apbJUn2GYMxwEvdL9T8Odi+1K6I7qN6CC7cmy3Kd4do=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FtZwpafGPCDDTxqOgW2mkEADZ/se4eTEZQA2mUpXajpqURQ8IHEfHuUhUdVImAYJvuV2MAsxoovy/pGtycJ4h8X3ACID+cbgUluuzSSujrvn53eyc6nvnzT2TGBwbW5aNtVG4i7UtcnvCgSIxRThG4LBVbx0dwVGHy+fKYOvNMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eFNmf1z9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eFNmf1z9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4A7AC4CEF8; Tue, 22 Jul 2025 18:52:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753210362; bh=apbJUn2GYMxwEvdL9T8Odi+1K6I7qN6CC7cmy3Kd4do=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eFNmf1z9FLotZKIyolB5buZFoQiezsQYrah/gCseMWrMkfevaDt6gBsplLbHYbzUF yTgW00AeM1P5OPilZdow5W5NCJUqi98zszkOFXKs2VVAoCHUy0sbZ93EjyqHfnHhSu tw2qGg6De/81mlPI0LW2GE0eNhTz6qRmq6KEnJ79TdNKVEXT/9P0bTYtyHG1yHGL4Q oqgFZxDGDoKKscYb38sT3xtirXdaYKJ+xRSj3qultOkmBnSSXKDRg8JiUJDacCSUP+ ylAg1sRxCAtlkY7iUaRKGIgM69QKpOphpSRwGvtikC9wmJgPxeP/CipORK6S5UaL88 idXUQZ5Iner0g== From: Jeff Layton Date: Tue, 22 Jul 2025 14:52:27 -0400 Subject: [PATCH 1/2] vfs: add tracepoints in inode_set_ctime_deleg Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250722-nfsd-testing-v1-1-31321c7fc97f@kernel.org> References: <20250722-nfsd-testing-v1-0-31321c7fc97f@kernel.org> In-Reply-To: <20250722-nfsd-testing-v1-0-31321c7fc97f@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2709; i=jlayton@kernel.org; h=from:subject:message-id; bh=apbJUn2GYMxwEvdL9T8Odi+1K6I7qN6CC7cmy3Kd4do=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBof932FhldSMvrXMgAlZ3u1/gC/mWBZwP96O8px IYCFg9B/2WJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaH/d9gAKCRAADmhBGVaC FYuWEADGdCj2uZb5ghm1gPxpM7hPE3nblhWkDKZxoiD5M1Q0oc5GWZaQIWLeu63hfPGJO4EWHu0 KoEpXdehUL5GKGHy+b2ZqDV1LIDIAr5j44g4xuh3n7N5tJXxZDF3nH4Z+TsgT/cC5NeVQlgRNfU /OTC1elXvx6RzNHRtYYxaBHA34gyRwIMxUIhVe5qGn7ZGw/H7r+SFOH2JEoSeNVZwfiKMcE4bzJ klxlMTCHvwPMJBDv7NR8QzFW1fTt6PN1PjTcEB29QobW8vtx00T38FXtOp2qkfvgFaDR1hhJQcl ubAaMwCuwDrzzn56OkMdKdycXINnS99IjsGzKungrTfQ3xTdhcz9ThWUSe/6JNj+o6KjxMc8cwb 6Bnnfo2751PlQB2SrHp3ogSFgAZf5O+iMLCU/X0Itkfd4FYdUUDlvxLDtGdF/RoJzfikozITySz FqfHPkKjxEKK5KueIs8i/MYxrOTIHZJjAupIjfBQES8PVhJg5wS0bRpgqYGveGBjNHA4LaIF+Ej DkHNKjldzYuk876a7rkg8RhXfS+89deek5QHukfEmVW899rcMHLXPs30yiCc5kr2uS5kHsIYQgP K6K2qjFAqz17nQC8ohlzyLGnc6yGxPYb4WbhZhe6QGQfNTiIv/UTHzGzDojSfzleReacAX/OA47 u/H2bXK++gRGbdA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add tracepoints in inode_set_ctime_deleg() that show the existing ctime, the requested ctime and the current_time(). Signed-off-by: Jeff Layton Reviewed-by: Chuck Lever --- fs/inode.c | 5 ++++- include/trace/events/timestamp.h | 40 ++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 99318b157a9a13b3dd8dad0f5f90951f08ef64de..6a8bf57d649aa0909b85f09e3b5= b0fbc81efe303 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2811,10 +2811,13 @@ struct timespec64 inode_set_ctime_deleg(struct inod= e *inode, struct timespec64 u cur_ts.tv_sec =3D inode->i_ctime_sec; =20 /* If the update is older than the existing value, skip it. */ - if (timespec64_compare(&update, &cur_ts) <=3D 0) + if (timespec64_compare(&update, &cur_ts) <=3D 0) { + trace_inode_set_ctime_deleg(inode, &cur_ts, &update, NULL); return cur_ts; + } =20 ktime_get_coarse_real_ts64_mg(&now); + trace_inode_set_ctime_deleg(inode, &cur_ts, &update, &now); =20 /* Clamp the update to "now" if it's in the future */ if (timespec64_compare(&update, &now) > 0) diff --git a/include/trace/events/timestamp.h b/include/trace/events/timest= amp.h index c9e5ec930054887a6a7bae8e487611b5ded33d71..e66161d8e14d9b74b0c875f0b32= 4d24895403c18 100644 --- a/include/trace/events/timestamp.h +++ b/include/trace/events/timestamp.h @@ -118,6 +118,46 @@ TRACE_EVENT(fill_mg_cmtime, __entry->mtime_s, __entry->mtime_ns ) ); + +TRACE_EVENT(inode_set_ctime_deleg, + TP_PROTO(struct inode *inode, + struct timespec64 *old, + struct timespec64 *req, + struct timespec64 *now), + + TP_ARGS(inode, old, req, now), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(time64_t, old_s) + __field(time64_t, req_s) + __field(time64_t, now_s) + __field(u32, old_ns) + __field(u32, req_ns) + __field(u32, now_ns) + __field(u32, gen) + ), + + TP_fast_assign( + __entry->dev =3D inode->i_sb->s_dev; + __entry->ino =3D inode->i_ino; + __entry->gen =3D inode->i_generation; + __entry->old_s =3D old->tv_sec; + __entry->req_s =3D req->tv_sec; + __entry->now_s =3D now ? now->tv_sec : 0; + __entry->old_ns =3D old->tv_nsec; + __entry->req_ns =3D req->tv_nsec; + __entry->now_ns =3D now ? now->tv_nsec : 0; + ), + + TP_printk("ino=3D%d:%d:%ld:%u old=3D%lld.%u req=3D%lld.%u now=3D%lld.%u", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->gen, + __entry->old_s, __entry->old_ns, + __entry->req_s, __entry->req_ns, + __entry->now_s, __entry->now_ns + ) +); #endif /* _TRACE_TIMESTAMP_H */ =20 /* This part must be outside protection */ --=20 2.50.1 From nobody Mon Oct 6 10:13:30 2025 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 9B72B284B29; Tue, 22 Jul 2025 18:52:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753210363; cv=none; b=ElulJ1azfoQu6+sFLPPs1nQfQGX6p3pRZgSZnW26F5lDxB3Mv1CVseQnUTayH9M0/b3ENOfJvMjXMdACWmlZjG8htndeZ8tIZdrHZQc/j7gFNTE/s7sEsYNUzZo6XrIKCxZQif09whqLRhN1PpPxC3v2WJGvZ0LbbHWedZ0y/PA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753210363; c=relaxed/simple; bh=iYBw4xhCGRCvfAF5MhNNiyX1HVH5Ue5u6Xd0TVVd7Yc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O/hwRK28pe0sqrWzI7tOkTpNYDV1o6Mu2zyQW/EYTTqqreezV8xMlN+Q/2uexnGDWe1mBDYxv94tAcm7Ex/j1XYcI7vrNUurbz4AmmcniEMcwB9OMEqVbpvgENjngXbvx2r0Sqku9lwkPYoyVtMXIHKwsYlkBXcK57wcPFACjOA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=chi3x1FG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="chi3x1FG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B2FBC4CEF6; Tue, 22 Jul 2025 18:52:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753210363; bh=iYBw4xhCGRCvfAF5MhNNiyX1HVH5Ue5u6Xd0TVVd7Yc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=chi3x1FGBfA1OeZG+zcjT9/+5HlFk5TvmI3otGjcymBEksXGDCC5xfWQdmbCaEtW/ oYECfWACgWyorQOn5mJy5fpkuCqjvLgWVr6AEx4y5vrbivaA7mCTkoYrPJe5wmmOyv Vm7e2jkRa7UgyLyIwUIdnkW7W1C0fB0XQ/0E5ZPvwIfRRj6WEQzQUhXD7NIUW3FLZT Sil5rE4eWIfxX+VYEfxaU32Pfy0jueE4hUlqteQLlnU4xfjGZO+n35kFhwz6/JjcR8 4UMFeFUQTovVYHel4MjqYpd9W7svy2SrebS68ULTt8mYxLxF86xqH30SMOPDA1hFb4 C7UCPPOQIq+Og== From: Jeff Layton Date: Tue, 22 Jul 2025 14:52:28 -0400 Subject: [PATCH 2/2] vfs: fix delegated timestamp handling in setattr_copy() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250722-nfsd-testing-v1-2-31321c7fc97f@kernel.org> References: <20250722-nfsd-testing-v1-0-31321c7fc97f@kernel.org> In-Reply-To: <20250722-nfsd-testing-v1-0-31321c7fc97f@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4536; i=jlayton@kernel.org; h=from:subject:message-id; bh=iYBw4xhCGRCvfAF5MhNNiyX1HVH5Ue5u6Xd0TVVd7Yc=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBof933jwSVWVC4Wssc+UXoCLXpXXdOe6OBGByDN FfNnqfKaKKJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaH/d9wAKCRAADmhBGVaC FaJqD/9VKfJEvpwwpjcl+kilKWRcwygCTf3opH97hbOIq0FSw/ENAU394+huxg23jAZr4dfY5LE EmWcdMcxZC4lpnL5YlRyXDQoVjxVX6I5x3MJWHqBx80X27QWeKjrRdEMPWe1d8V5mxLpeRvBdJj wwijWMD+W+CmQ2+6wa/r3i+oVWy8lJ03QGarpEfGG9Y8Hn7SuyurBnS5AA2Wiz2XRcqJndCncDa +v82IsVJa6qB2jK52HQ46GBzalRL3NjkVI532lHqz6vTFsWVupRNJ6tzkKYKGHmGP9cAF/PqaKQ lH4kxNYYqWNY8lKwvgzA+2C5a1g4Y79EejnQLJednWJqI2Vz6VDbq7ARVH1qEYMXweVCLRsX2w3 ZOhhI740oirzbGxlQTSvwPy/JxlOc6deByEsd1e0owEQ7WGmMNxnbwgNHZgbK7ijhdRK7DriP69 FNG9QsZXoJ79QJkgPKJOb2A3wmqo3GYq6qF/X1T3zF5l90q6k8OgroFC9O9IC3IVTznMOa4cvfd ksrrujp8QXosxmUWT0VK2uRR49Xnnn9B2SEYwqQ2WS5eUAm+nJMl9RB6jnvkitIDhnKcZx4u+oq YBXBK9f1fIzV36vycwqws3aTMVZIQvGCafsgTYIjzUn6yyyxgWXoY3HkbOa7e6HsjM7qFGI+I+1 Dny5qYhaSRi9Skw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 There are a couple of problems with delegated timestamp updates via setattr: 1/ the ia_ctime is always clobbered by notify_change(), so setting the ia_ctime to the same value as the ia_mtime in nfsd4_decode_fattr4() doesn't work. 2/ while it does test the ctime's validity vs. the existing ctime and current_time(), the same is not done for the atime or mtime. The spec requires this. Add a new setattr_copy_delegts() function that handles updating the timestamps whenever ATTR_DELEG is set. For both atime and mtime, validate and clamp the value to current_time(), and then set it. If the mtime gets updated, also update the ctime. Fixes: 7f2c86cba3c5 ("fs: handle delegated timestamps in setattr_copy_mgtim= e") Signed-off-by: Jeff Layton --- fs/attr.c | 52 ++++++++++++++++++++++++++++++++++++++-------------- fs/nfsd/nfs4xdr.c | 4 +--- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index 9caf63d20d03e86c535e9c8c91d49c2a34d34b7a..3e636943d26a36aeeed0ff8b428= b6dd3e63f8dde 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -287,14 +287,7 @@ static void setattr_copy_mgtime(struct inode *inode, c= onst struct iattr *attr) struct timespec64 now; =20 if (ia_valid & ATTR_CTIME) { - /* - * In the case of an update for a write delegation, we must respect - * the value in ia_ctime and not use the current time. - */ - if (ia_valid & ATTR_DELEG) - now =3D inode_set_ctime_deleg(inode, attr->ia_ctime); - else - now =3D inode_set_ctime_current(inode); + now =3D inode_set_ctime_current(inode); } else { /* If ATTR_CTIME isn't set, then ATTR_MTIME shouldn't be either. */ WARN_ON_ONCE(ia_valid & ATTR_MTIME); @@ -312,6 +305,39 @@ static void setattr_copy_mgtime(struct inode *inode, c= onst struct iattr *attr) inode_set_mtime_to_ts(inode, now); } =20 +/* + * Skip update if new value is older than existing time. Clamp + * to current_time() if it's in the future. + */ +static void setattr_copy_delegts(struct inode *inode, const struct iattr *= attr) +{ + struct timespec64 now =3D current_time(inode); + unsigned int ia_valid =3D attr->ia_valid; + + if (ia_valid & ATTR_MTIME) { + struct timespec64 cur =3D inode_get_mtime(inode); + + if (timespec64_compare(&attr->ia_mtime, &cur) > 0) { + if (timespec64_compare(&attr->ia_mtime, &now) > 0) + inode_set_mtime_to_ts(inode, now); + else + inode_set_mtime_to_ts(inode, attr->ia_mtime); + inode_set_ctime_deleg(inode, attr->ia_mtime); + } + } + + if (ia_valid & ATTR_ATIME) { + struct timespec64 cur =3D inode_get_atime(inode); + + if (timespec64_compare(&attr->ia_atime, &cur) > 0) { + if (timespec64_compare(&attr->ia_atime, &now) > 0) + inode_set_atime_to_ts(inode, now); + else + inode_set_atime_to_ts(inode, attr->ia_atime); + } + } +} + /** * setattr_copy - copy simple metadata updates into the generic inode * @idmap: idmap of the mount the inode was found from @@ -352,6 +378,8 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode= *inode, inode->i_mode =3D mode; } =20 + if (ia_valid & ATTR_DELEG) + return setattr_copy_delegts(inode, attr); if (is_mgtime(inode)) return setattr_copy_mgtime(inode, attr); =20 @@ -359,12 +387,8 @@ void setattr_copy(struct mnt_idmap *idmap, struct inod= e *inode, inode_set_atime_to_ts(inode, attr->ia_atime); if (ia_valid & ATTR_MTIME) inode_set_mtime_to_ts(inode, attr->ia_mtime); - if (ia_valid & ATTR_CTIME) { - if (ia_valid & ATTR_DELEG) - inode_set_ctime_deleg(inode, attr->ia_ctime); - else - inode_set_ctime_to_ts(inode, attr->ia_ctime); - } + if (ia_valid & ATTR_CTIME) + inode_set_ctime_to_ts(inode, attr->ia_ctime); } EXPORT_SYMBOL(setattr_copy); =20 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 8b68f74a8cf08c6aa1305a2a3093467656085e4a..e6899a3502332d686138abee228= 4c87fc7fbc0ae 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -537,9 +537,7 @@ nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u3= 2 *bmval, u32 bmlen, return nfserr_bad_xdr; iattr->ia_mtime.tv_sec =3D modify.seconds; iattr->ia_mtime.tv_nsec =3D modify.nseconds; - iattr->ia_ctime.tv_sec =3D modify.seconds; - iattr->ia_ctime.tv_nsec =3D modify.seconds; - iattr->ia_valid |=3D ATTR_CTIME | ATTR_MTIME | ATTR_MTIME_SET | ATTR_DEL= EG; + iattr->ia_valid |=3D ATTR_MTIME | ATTR_MTIME_SET | ATTR_DELEG; } =20 /* request sanity: did attrlist4 contain the expected number of words? */ --=20 2.50.1