* [PATCH 0/2] fs: fixes for multigrain ctime code
@ 2023-09-07 16:33 Jeff Layton
2023-09-07 16:33 ` [PATCH 1/2] fs: initialize inode->__i_ctime to the epoch Jeff Layton
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Jeff Layton @ 2023-09-07 16:33 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Jan Kara
Cc: linux-mm, linux-fsdevel, linux-kernel, Jeff Layton,
kernel test robot
The kernel test robot noted some test failures with the LTP mount03 test
on tmpfs. From the test output, it looked like the atime had gone
backward.
One way this could happen would be for tmpfs to get a new inode from the
slab that had a ctime that appeared to be in the future.
inode_update_ctime_current would just return that time and then the
mtime and atime would be set to the same value. Then later, the atime
gets overwritten by "now" which is still lower than the garbage ctime
value.
I've not been able to reproduce this on my test rig, so I'm not certain
this fixes the problem that was reported. I'm hopeful though, so I've
left the KTR tags in place.
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
Jeff Layton (2):
fs: initialize inode->__i_ctime to the epoch
fs: don't update the atime if existing atime is newer than "now"
fs/inode.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
---
base-commit: 7ba2090ca64ea1aa435744884124387db1fac70f
change-id: 20230907-ctime-fixes-ec6319ca01be
Best regards,
--
Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] fs: initialize inode->__i_ctime to the epoch
2023-09-07 16:33 [PATCH 0/2] fs: fixes for multigrain ctime code Jeff Layton
@ 2023-09-07 16:33 ` Jeff Layton
2023-09-08 10:42 ` Jan Kara
2023-09-07 16:33 ` [PATCH 2/2] fs: don't update the atime if existing atime is newer than "now" Jeff Layton
2023-09-08 12:10 ` [PATCH 0/2] fs: fixes for multigrain ctime code Christian Brauner
2 siblings, 1 reply; 8+ messages in thread
From: Jeff Layton @ 2023-09-07 16:33 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Jan Kara
Cc: linux-mm, linux-fsdevel, linux-kernel, Jeff Layton,
kernel test robot
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 <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202309071017.a64aca5e-oliver.sang@intel.com
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
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;
--
2.41.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] fs: don't update the atime if existing atime is newer than "now"
2023-09-07 16:33 [PATCH 0/2] fs: fixes for multigrain ctime code Jeff Layton
2023-09-07 16:33 ` [PATCH 1/2] fs: initialize inode->__i_ctime to the epoch Jeff Layton
@ 2023-09-07 16:33 ` Jeff Layton
2023-09-08 12:11 ` Jan Kara
2023-09-08 12:10 ` [PATCH 0/2] fs: fixes for multigrain ctime code Christian Brauner
2 siblings, 1 reply; 8+ messages in thread
From: Jeff Layton @ 2023-09-07 16:33 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Jan Kara
Cc: linux-mm, linux-fsdevel, linux-kernel, Jeff Layton,
kernel test robot
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 <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202309071017.a64aca5e-oliver.sang@intel.com
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
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;
--
2.41.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] fs: initialize inode->__i_ctime to the epoch
2023-09-07 16:33 ` [PATCH 1/2] fs: initialize inode->__i_ctime to the epoch Jeff Layton
@ 2023-09-08 10:42 ` Jan Kara
2023-09-08 11:41 ` Jeff Layton
0 siblings, 1 reply; 8+ messages in thread
From: Jan Kara @ 2023-09-08 10:42 UTC (permalink / raw)
To: Jeff Layton
Cc: Alexander Viro, Christian Brauner, Jan Kara, linux-mm,
linux-fsdevel, linux-kernel, kernel test robot
On Thu 07-09-23 12:33:47, Jeff Layton wrote:
> 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 <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202309071017.a64aca5e-oliver.sang@intel.com
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
Looks good but don't you need the same treatment to atime after your patch
2/2?
Honza
> ---
> 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;
>
> --
> 2.41.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] fs: initialize inode->__i_ctime to the epoch
2023-09-08 10:42 ` Jan Kara
@ 2023-09-08 11:41 ` Jeff Layton
2023-09-08 12:10 ` Jan Kara
0 siblings, 1 reply; 8+ messages in thread
From: Jeff Layton @ 2023-09-08 11:41 UTC (permalink / raw)
To: Jan Kara
Cc: Alexander Viro, Christian Brauner, linux-mm, linux-fsdevel,
linux-kernel, kernel test robot
On Fri, 2023-09-08 at 12:42 +0200, Jan Kara wrote:
> On Thu 07-09-23 12:33:47, Jeff Layton wrote:
> > 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 <oliver.sang@intel.com>
> > Closes: https://lore.kernel.org/oe-lkp/202309071017.a64aca5e-oliver.sang@intel.com
> > Signed-off-by: Jeff Layton <jlayton@kernel.org>
>
> Looks good but don't you need the same treatment to atime after your patch
> 2/2?
>
>
I don't think so. Most filesystems are doing something along the lines
of this when allocating a new inode:
inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode);
...and I think they pretty much all have to initialize i_atime properly,
since someone could stat the inode before an atime update occurs.
> > ---
> > 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;
> >
> > --
> > 2.41.0
> >
--
Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] fs: initialize inode->__i_ctime to the epoch
2023-09-08 11:41 ` Jeff Layton
@ 2023-09-08 12:10 ` Jan Kara
0 siblings, 0 replies; 8+ messages in thread
From: Jan Kara @ 2023-09-08 12:10 UTC (permalink / raw)
To: Jeff Layton
Cc: Jan Kara, Alexander Viro, Christian Brauner, linux-mm,
linux-fsdevel, linux-kernel, kernel test robot
On Fri 08-09-23 07:41:45, Jeff Layton wrote:
> On Fri, 2023-09-08 at 12:42 +0200, Jan Kara wrote:
> > On Thu 07-09-23 12:33:47, Jeff Layton wrote:
> > > 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 <oliver.sang@intel.com>
> > > Closes: https://lore.kernel.org/oe-lkp/202309071017.a64aca5e-oliver.sang@intel.com
> > > Signed-off-by: Jeff Layton <jlayton@kernel.org>
> >
> > Looks good but don't you need the same treatment to atime after your patch
> > 2/2?
> >
> >
>
> I don't think so. Most filesystems are doing something along the lines
> of this when allocating a new inode:
>
> inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode);
>
> ...and I think they pretty much all have to initialize i_atime properly,
> since someone could stat the inode before an atime update occurs.
Ah, right. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> > > ---
> > > 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;
> > >
> > > --
> > > 2.41.0
> > >
>
> --
> Jeff Layton <jlayton@kernel.org>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/2] fs: fixes for multigrain ctime code
2023-09-07 16:33 [PATCH 0/2] fs: fixes for multigrain ctime code Jeff Layton
2023-09-07 16:33 ` [PATCH 1/2] fs: initialize inode->__i_ctime to the epoch Jeff Layton
2023-09-07 16:33 ` [PATCH 2/2] fs: don't update the atime if existing atime is newer than "now" Jeff Layton
@ 2023-09-08 12:10 ` Christian Brauner
2 siblings, 0 replies; 8+ messages in thread
From: Christian Brauner @ 2023-09-08 12:10 UTC (permalink / raw)
To: Jeff Layton
Cc: Christian Brauner, linux-mm, linux-fsdevel, linux-kernel,
kernel test robot, Alexander Viro, Jan Kara
On Thu, 07 Sep 2023 12:33:46 -0400, Jeff Layton wrote:
> The kernel test robot noted some test failures with the LTP mount03 test
> on tmpfs. From the test output, it looked like the atime had gone
> backward.
>
> One way this could happen would be for tmpfs to get a new inode from the
> slab that had a ctime that appeared to be in the future.
> inode_update_ctime_current would just return that time and then the
> mtime and atime would be set to the same value. Then later, the atime
> gets overwritten by "now" which is still lower than the garbage ctime
> value.
>
> [...]
Picked up so we can get some -next testing. Hopefully that test thing can
verify the fix.
---
Applied to the vfs.ctime branch of the vfs/vfs.git tree.
Patches in the vfs.ctime branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.ctime
[1/2] fs: initialize inode->__i_ctime to the epoch
https://git.kernel.org/vfs/vfs/c/7651a330dcbd
[2/2] fs: don't update the atime if existing atime is newer than "now"
https://git.kernel.org/vfs/vfs/c/4c950d80d98d
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] fs: don't update the atime if existing atime is newer than "now"
2023-09-07 16:33 ` [PATCH 2/2] fs: don't update the atime if existing atime is newer than "now" Jeff Layton
@ 2023-09-08 12:11 ` Jan Kara
0 siblings, 0 replies; 8+ messages in thread
From: Jan Kara @ 2023-09-08 12:11 UTC (permalink / raw)
To: Jeff Layton
Cc: Alexander Viro, Christian Brauner, Jan Kara, linux-mm,
linux-fsdevel, linux-kernel, kernel test robot
On Thu 07-09-23 12:33:48, Jeff Layton wrote:
> 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 <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202309071017.a64aca5e-oliver.sang@intel.com
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> 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;
>
> --
> 2.41.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-09-08 12:11 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-07 16:33 [PATCH 0/2] fs: fixes for multigrain ctime code Jeff Layton
2023-09-07 16:33 ` [PATCH 1/2] fs: initialize inode->__i_ctime to the epoch Jeff Layton
2023-09-08 10:42 ` Jan Kara
2023-09-08 11:41 ` Jeff Layton
2023-09-08 12:10 ` Jan Kara
2023-09-07 16:33 ` [PATCH 2/2] fs: don't update the atime if existing atime is newer than "now" Jeff Layton
2023-09-08 12:11 ` Jan Kara
2023-09-08 12:10 ` [PATCH 0/2] fs: fixes for multigrain ctime code Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).