From patchwork Thu Sep 7 16:33:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13376610 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B2A6EC873D for ; Thu, 7 Sep 2023 16:35:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231835AbjIGQf1 (ORCPT ); Thu, 7 Sep 2023 12:35:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234869AbjIGQf0 (ORCPT ); Thu, 7 Sep 2023 12:35:26 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2EA5E57; Thu, 7 Sep 2023 09:34:58 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 724F9C433CB; Thu, 7 Sep 2023 16:33:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694104440; bh=JP9tUiLZ6T/k5I6nBBltrDdOGnjoSsJgaiX+JXKr3so=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hdFbPPEzdSggibPtiqud6tUTPGMrh4MM86UWNxl9U3J28kRJoe+NUIQq+qzv2mje6 Ja2aq6qq2GkG+BDPQWzl2bIZr2AYMmYYX0dvu9txwAR4+BmCRL6iQAy+l5BS2KHf9R L7gsz0OgS9poH0dwdoqLJSmHoBhTg83wfdN8XiSGVTxJwtQqvmVnNieX3WtGq7Qxi7 FCTHt945til2Bt8OkSEcyzDaickDMZjoM49bzDucTwOY4Iex0VDRJpj99XZB9yMrvc 7HL/KThu0iddy0hyBBpdZIX105Oq1xfP4aj41OqLFYN4/CHe1Y3crJbtWHCWTcUgVc WvJQz1IJXrm3A== From: Jeff Layton Date: Thu, 07 Sep 2023 12:33:47 -0400 Subject: [PATCH 1/2] fs: initialize inode->__i_ctime to the epoch MIME-Version: 1.0 Message-Id: <20230907-ctime-fixes-v1-1-3b74c970d934@kernel.org> References: <20230907-ctime-fixes-v1-0-3b74c970d934@kernel.org> In-Reply-To: <20230907-ctime-fixes-v1-0-3b74c970d934@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jeff Layton , kernel test robot X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1130; i=jlayton@kernel.org; h=from:subject:message-id; bh=JP9tUiLZ6T/k5I6nBBltrDdOGnjoSsJgaiX+JXKr3so=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBk+ft2F+0r47Otgg6Kb6XEIaO9dJBYAFU8gjygE 8uEhYSQQs2JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZPn7dgAKCRAADmhBGVaC Fc5OD/0bSZpmszFw2mR0jS9vvjyJK3F4b0SARjnyo1q9za9QbR3U8c8lrWzVlySgIRm6ISqeg+C irV1RBOgwNkJRO3/EnwPLcA0K8UAN1VzTC2pn9M7qy6uaxpRlBsFN67vJcdj6I+lmO2QWeTtkkf lMZqAWOh2lR7jc7LqoFT7/Q0hLd0mWFiqtsw2SsSUNj7kIJ8O/QRbpXEfdwPS2Kp4vXtxBFZ34s uyVJFb9N2ZMnDUJiP6cHCnJ8zkAd/ggrB3G5Ea/ydtkv94vSMnJdmr2JYmnUp4QyrNG0qSID0YH XYiQZtdNX8+RGKgBqo4yvR2jrzy8nYAdtXJfejw++Yg22v9gtG26j2eXD9TZWFrYg9w3iPns1mz WRGVVRFZTlfDxJnZggpAYC/S1kCq9xgc4+gFVwmJYfELyIkG74thIdPu8+RSFGQIfTzarjCCytX LoO0DjJMuDA7fcIq7CHGvrn6XLG7AFr1K13ECVagnzBxBXalayHS+ynyi6Al8lW+JjwnIwwd0d8 DbnQCw/H+jM1pllv2qM00QHrq8zwnNekLI/jcZ9OojuPzfxmBby3hA+imSR8zeZdfwRasO7RNZC twEjfkwQ5XzhrFa1e/DlzOrJC2JW/JAqjeXKtqoLrQ0YUIqE1KyW0qN8Aeb5BvS/kH42jezqvTp kG2YAXIFgW/nmJw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org With the advent of multigrain timestamps, we use inode_set_ctime_current to set the ctime, which can skip updating if the existing ctime appears to be in the future. Because we don't initialize this field at allocation time, that could prevent the ctime from being initialized properly when the inode is instantiated. Always initialize the ctime field to the epoch so that the filesystem can set the timestamps properly later. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202309071017.a64aca5e-oliver.sang@intel.com Signed-off-by: Jeff Layton Reviewed-by: Jan Kara --- fs/inode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index 35fd688168c5..54237f4242ff 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -168,6 +168,8 @@ int inode_init_always(struct super_block *sb, struct inode *inode) inode->i_fop = &no_open_fops; inode->i_ino = 0; inode->__i_nlink = 1; + inode->__i_ctime.tv_sec = 0; + inode->__i_ctime.tv_nsec = 0; inode->i_opflags = 0; if (sb->s_xattr) inode->i_opflags |= IOP_XATTR; From patchwork Thu Sep 7 16:33:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13376760 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2752CEC8743 for ; Thu, 7 Sep 2023 17:53:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239693AbjIGRxL (ORCPT ); Thu, 7 Sep 2023 13:53:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239373AbjIGRxK (ORCPT ); Thu, 7 Sep 2023 13:53:10 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC581171C; Thu, 7 Sep 2023 10:52:40 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D749C4339A; Thu, 7 Sep 2023 16:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694104441; bh=1rA76M1gNfenw+XkkpPAQfgJBEGVBm9PuOG7uc/Jkm8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Ch5oAfNfwuXOaXDTxKt6lI5yl8T5rJQFAVT0NRgVHrWXuy+QZU0CvU05eqlS1E4He s2ooWMNuNKWz1qOxnh935WS3Keaz1kNDahl/G8ezv0mXx7kvmrn1FLffFLxUuHetAw wXJAb5qu9K7uHtRdRxpp8pVoas0c3zr6rzoEya/ObjKGGuxAlvsn10n4ZXjNdPFwZw 9fpAcRYcHFZI1TY3+iTLudZIiXk49F/Gwm+jFBF8BLjzNMX0SUCRY3We5Exs1x8AW7 4G1RqnI/2bxSqXM1IJE75CL5gaB29mooRiQ/qpsv1Lr6h6DjZIpDs1hp/wX0WXqykk 1JMOqekpDaZsg== From: Jeff Layton Date: Thu, 07 Sep 2023 12:33:48 -0400 Subject: [PATCH 2/2] fs: don't update the atime if existing atime is newer than "now" MIME-Version: 1.0 Message-Id: <20230907-ctime-fixes-v1-2-3b74c970d934@kernel.org> References: <20230907-ctime-fixes-v1-0-3b74c970d934@kernel.org> In-Reply-To: <20230907-ctime-fixes-v1-0-3b74c970d934@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jeff Layton , kernel test robot X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1253; i=jlayton@kernel.org; h=from:subject:message-id; bh=1rA76M1gNfenw+XkkpPAQfgJBEGVBm9PuOG7uc/Jkm8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBk+ft24KZSXjqnylLBtdm3crreHjPaKA2NTl+Vq 1+dgCFXBRKJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZPn7dgAKCRAADmhBGVaC FZPuD/98kwCV1M6EJYg97zAUpyxuVXP0vI6qklYlW6dZ+wrkPLkeaE2VOlbz4dwJjIVfn3S85A/ Gou8Lq8ahPqTJ+DcVi1DD9Iv9FCYKqqRGIAv8aXwA4sNlRjCJyPqe2U+m3ZnW7tYp+zIbLyWyIo eC3q0GwVb/abjQZxfouOavamZVfB4uFA4ZkrSYcUNf3yypt23ZUhqBPpoH1rPVSIh0boAJ+7x/A uDbu7bGbpLHdL29/9jRcTaFXk3k85ucNJhOLkUAjip+xvOWl3KQSI0XScOPhcFGbcDwhaNNhFwl x6oT/gqmu3JpLpXGd+GWZy6mGVhCjMaXjMf2pMfyYwPnvKfwuzC2Ot8bW24Lo2QvB8xK4yeTogm j1TkOajtQPZWU54of+7DAxyc0j968X1PnP70DDPzYAh6CgIKNVFviTJw3Zx/thblA9w8wCOq7cL PMpvoWzyAI2K1uB0Di6iZFDYJJIxDdiOqsi+fcLicpK4BIXo1m0W4kKcL/L/1wuyX2n+dvaYIf/ eKF22UqKB5kJuHcwaNqvIUcPxnurhNxpXVpFH83nPgOMBPUhLkDPW/JEFcFV6M+LPz/qqNYC8Pq HYmgpuegUySatx1qqO7IyH4sCZaZWp35VOce4X9C/Nfkq0aumlnyVInlTiN4v+ueko9qD2Ni6B8 DLz4wdBuZW80C+A== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org It's possible for the atime to be updated with a fine-grained timestamp and then later get an update that uses a coarse-grained timestamp which makes the atime appear to go backward. Fix this by only updating the atime if "now" is later than the current value. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202309071017.a64aca5e-oliver.sang@intel.com Signed-off-by: Jeff Layton Reviewed-by: Jan Kara --- fs/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 54237f4242ff..cf4726b7f4b5 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1905,7 +1905,7 @@ int inode_update_timestamps(struct inode *inode, int flags) } if (flags & S_ATIME) { - if (!timespec64_equal(&now, &inode->i_atime)) { + if (timespec64_compare(&inode->i_atime, &now) < 0) { inode->i_atime = now; updated |= S_ATIME; } @@ -1991,7 +1991,7 @@ bool atime_needs_update(const struct path *path, struct inode *inode) if (!relatime_need_update(mnt, inode, now)) return false; - if (timespec64_equal(&inode->i_atime, &now)) + if (timespec64_compare(&inode->i_atime, &now) >= 0) return false; return true;