qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tests/tcg/multiarch/linux/linux-test: Don't try to test atime update
@ 2025-10-10 12:14 Peter Maydell
  2025-10-16 10:41 ` Peter Maydell
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Peter Maydell @ 2025-10-10 12:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Alex Bennée

The linux-test test includes an attempt to check the utime and stat
syscalls by setting the atime and mtime of a file to specific values,
and then calling stat() to check that the values read back correctly.

Unfortunately this is flaky, as it will fail if some other process
(for instance a virus scanner, backup program, etc) gets in and reads
the file between the utime() and stat() call, resulting in a host
syscall sequence like this:

utimensat(AT_FDCWD, "file2",
  [{tv_sec=1001, tv_nsec=0} /* 1970-01-01T01:16:41+0100 */,
   {tv_sec=1000, tv_nsec=0} /* 1970-01-01T01:16:40+0100 */], 0) = 0
# successfully set atime to 1001 and mtime to 1000
statx(AT_FDCWD, "file2", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT,
  STATX_BASIC_STATS,
  {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID,
   stx_blksize=4096, stx_attributes=0, stx_nlink=1, stx_uid=32808,
   stx_gid=32808, stx_mode=S_IFREG|0600, stx_ino=21659016,
   stx_size=100, stx_blocks=8,
   stx_attributes_mask=STATX_ATTR_COMPRESSED|STATX_ATTR_IMMUTABLE|
         STATX_ATTR_APPEND|STATX_ATTR_NODUMP|STATX_ATTR_ENCRYPTED|
         STATX_ATTR_AUTOMOUNT|STATX_ATTR_MOUNT_ROOT|STATX_ATTR_VERITY|
         STATX_ATTR_DAX,
   stx_atime={tv_sec=1760091862, tv_nsec=63509009} /* 2025-10-10T11:24:22.063509009+0100 */,
   stx_ctime={tv_sec=1760091862, tv_nsec=63509009} /* 2025-10-10T11:24:22.063509009+0100 */,
   stx_mtime={tv_sec=1000, tv_nsec=0} /* 1970-01-01T01:16:40+0100 */,
   stx_rdev_major=0, stx_rdev_minor=0, stx_dev_major=252,
   stx_dev_minor=0, stx_mnt_id=0x1f}) = 0
# but when we statx the file, we get back an mtime of 1000
# but an atime corresponding to when the other process read it

and which will cause the test program to fail with the error
message "stat time".

In theory we could defend against this by e.g.  operating on files in
a dummy loopback mount filesystem which we mounted as 'noatime', but
this isn't worth the hassle.  Just drop the check on atime.

Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
The failure happens to me occasionally on my local system.
---
 tests/tcg/multiarch/linux/linux-test.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tests/tcg/multiarch/linux/linux-test.c b/tests/tcg/multiarch/linux/linux-test.c
index 64f57cb287e..bf6e0fda262 100644
--- a/tests/tcg/multiarch/linux/linux-test.c
+++ b/tests/tcg/multiarch/linux/linux-test.c
@@ -155,9 +155,14 @@ static void test_file(void)
         error("stat mode");
     if ((st.st_mode & 0777) != 0600)
         error("stat mode2");
-    if (st.st_atime != 1001 ||
-        st.st_mtime != 1000)
+    /*
+     * Only check mtime, not atime: other processes such as
+     * virus scanners might race with this test program and get
+     * in and update the atime, causing random failures.
+     */
+    if (st.st_mtime != 1000) {
         error("stat time");
+    }
 
     chk_error(stat(tmpdir, &st));
     if (!S_ISDIR(st.st_mode))
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tests/tcg/multiarch/linux/linux-test: Don't try to test atime update
  2025-10-10 12:14 [PATCH] tests/tcg/multiarch/linux/linux-test: Don't try to test atime update Peter Maydell
@ 2025-10-16 10:41 ` Peter Maydell
  2025-10-16 12:08 ` Thomas Huth
  2025-10-16 14:34 ` Alex Bennée
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2025-10-16 10:41 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Alex Bennée

Ping for review?

thanks
-- PMM

On Fri, 10 Oct 2025 at 13:14, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> The linux-test test includes an attempt to check the utime and stat
> syscalls by setting the atime and mtime of a file to specific values,
> and then calling stat() to check that the values read back correctly.
>
> Unfortunately this is flaky, as it will fail if some other process
> (for instance a virus scanner, backup program, etc) gets in and reads
> the file between the utime() and stat() call, resulting in a host
> syscall sequence like this:
>
> utimensat(AT_FDCWD, "file2",
>   [{tv_sec=1001, tv_nsec=0} /* 1970-01-01T01:16:41+0100 */,
>    {tv_sec=1000, tv_nsec=0} /* 1970-01-01T01:16:40+0100 */], 0) = 0
> # successfully set atime to 1001 and mtime to 1000
> statx(AT_FDCWD, "file2", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT,
>   STATX_BASIC_STATS,
>   {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID,
>    stx_blksize=4096, stx_attributes=0, stx_nlink=1, stx_uid=32808,
>    stx_gid=32808, stx_mode=S_IFREG|0600, stx_ino=21659016,
>    stx_size=100, stx_blocks=8,
>    stx_attributes_mask=STATX_ATTR_COMPRESSED|STATX_ATTR_IMMUTABLE|
>          STATX_ATTR_APPEND|STATX_ATTR_NODUMP|STATX_ATTR_ENCRYPTED|
>          STATX_ATTR_AUTOMOUNT|STATX_ATTR_MOUNT_ROOT|STATX_ATTR_VERITY|
>          STATX_ATTR_DAX,
>    stx_atime={tv_sec=1760091862, tv_nsec=63509009} /* 2025-10-10T11:24:22.063509009+0100 */,
>    stx_ctime={tv_sec=1760091862, tv_nsec=63509009} /* 2025-10-10T11:24:22.063509009+0100 */,
>    stx_mtime={tv_sec=1000, tv_nsec=0} /* 1970-01-01T01:16:40+0100 */,
>    stx_rdev_major=0, stx_rdev_minor=0, stx_dev_major=252,
>    stx_dev_minor=0, stx_mnt_id=0x1f}) = 0
> # but when we statx the file, we get back an mtime of 1000
> # but an atime corresponding to when the other process read it
>
> and which will cause the test program to fail with the error
> message "stat time".
>
> In theory we could defend against this by e.g.  operating on files in
> a dummy loopback mount filesystem which we mounted as 'noatime', but
> this isn't worth the hassle.  Just drop the check on atime.
>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> The failure happens to me occasionally on my local system.
> ---
>  tests/tcg/multiarch/linux/linux-test.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/tests/tcg/multiarch/linux/linux-test.c b/tests/tcg/multiarch/linux/linux-test.c
> index 64f57cb287e..bf6e0fda262 100644
> --- a/tests/tcg/multiarch/linux/linux-test.c
> +++ b/tests/tcg/multiarch/linux/linux-test.c
> @@ -155,9 +155,14 @@ static void test_file(void)
>          error("stat mode");
>      if ((st.st_mode & 0777) != 0600)
>          error("stat mode2");
> -    if (st.st_atime != 1001 ||
> -        st.st_mtime != 1000)
> +    /*
> +     * Only check mtime, not atime: other processes such as
> +     * virus scanners might race with this test program and get
> +     * in and update the atime, causing random failures.
> +     */
> +    if (st.st_mtime != 1000) {
>          error("stat time");
> +    }
>
>      chk_error(stat(tmpdir, &st));
>      if (!S_ISDIR(st.st_mode))
> --
> 2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tests/tcg/multiarch/linux/linux-test: Don't try to test atime update
  2025-10-10 12:14 [PATCH] tests/tcg/multiarch/linux/linux-test: Don't try to test atime update Peter Maydell
  2025-10-16 10:41 ` Peter Maydell
@ 2025-10-16 12:08 ` Thomas Huth
  2025-10-16 12:11   ` Peter Maydell
  2025-10-16 14:34 ` Alex Bennée
  2 siblings, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2025-10-16 12:08 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: qemu-stable, Alex Bennée

On 10/10/2025 14.14, Peter Maydell wrote:
> The linux-test test includes an attempt to check the utime and stat
> syscalls by setting the atime and mtime of a file to specific values,
> and then calling stat() to check that the values read back correctly.
> 
> Unfortunately this is flaky, as it will fail if some other process
> (for instance a virus scanner, backup program, etc) gets in and reads
> the file between the utime() and stat() call, resulting in a host
> syscall sequence like this:
> 
> utimensat(AT_FDCWD, "file2",
>    [{tv_sec=1001, tv_nsec=0} /* 1970-01-01T01:16:41+0100 */,
>     {tv_sec=1000, tv_nsec=0} /* 1970-01-01T01:16:40+0100 */], 0) = 0
> # successfully set atime to 1001 and mtime to 1000
> statx(AT_FDCWD, "file2", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT,
>    STATX_BASIC_STATS,
>    {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID,
>     stx_blksize=4096, stx_attributes=0, stx_nlink=1, stx_uid=32808,
>     stx_gid=32808, stx_mode=S_IFREG|0600, stx_ino=21659016,
>     stx_size=100, stx_blocks=8,
>     stx_attributes_mask=STATX_ATTR_COMPRESSED|STATX_ATTR_IMMUTABLE|
>           STATX_ATTR_APPEND|STATX_ATTR_NODUMP|STATX_ATTR_ENCRYPTED|
>           STATX_ATTR_AUTOMOUNT|STATX_ATTR_MOUNT_ROOT|STATX_ATTR_VERITY|
>           STATX_ATTR_DAX,
>     stx_atime={tv_sec=1760091862, tv_nsec=63509009} /* 2025-10-10T11:24:22.063509009+0100 */,
>     stx_ctime={tv_sec=1760091862, tv_nsec=63509009} /* 2025-10-10T11:24:22.063509009+0100 */,
>     stx_mtime={tv_sec=1000, tv_nsec=0} /* 1970-01-01T01:16:40+0100 */,
>     stx_rdev_major=0, stx_rdev_minor=0, stx_dev_major=252,
>     stx_dev_minor=0, stx_mnt_id=0x1f}) = 0
> # but when we statx the file, we get back an mtime of 1000
> # but an atime corresponding to when the other process read it
> 
> and which will cause the test program to fail with the error
> message "stat time".
> 
> In theory we could defend against this by e.g.  operating on files in
> a dummy loopback mount filesystem which we mounted as 'noatime', but
> this isn't worth the hassle.  Just drop the check on atime.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> The failure happens to me occasionally on my local system.
> ---
>   tests/tcg/multiarch/linux/linux-test.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/tcg/multiarch/linux/linux-test.c b/tests/tcg/multiarch/linux/linux-test.c
> index 64f57cb287e..bf6e0fda262 100644
> --- a/tests/tcg/multiarch/linux/linux-test.c
> +++ b/tests/tcg/multiarch/linux/linux-test.c
> @@ -155,9 +155,14 @@ static void test_file(void)

Maybe drop the "tbuf.actime = 1001;" earlier in this file, too?

>           error("stat mode");
>       if ((st.st_mode & 0777) != 0600)
>           error("stat mode2");
> -    if (st.st_atime != 1001 ||
> -        st.st_mtime != 1000)
> +    /*
> +     * Only check mtime, not atime: other processes such as
> +     * virus scanners might race with this test program and get
> +     * in and update the atime, causing random failures.

I actually saw similar problems when looking at the atimes of the files in 
the functional test cache, so I agree, checking atime cannot work reliably.

Reviewed-by: Thomas Huth <thuth@redhat.com>


> +     */
> +    if (st.st_mtime != 1000) {
>           error("stat time");
> +    }




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tests/tcg/multiarch/linux/linux-test: Don't try to test atime update
  2025-10-16 12:08 ` Thomas Huth
@ 2025-10-16 12:11   ` Peter Maydell
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2025-10-16 12:11 UTC (permalink / raw)
  To: Thomas Huth; +Cc: qemu-devel, qemu-stable, Alex Bennée

On Thu, 16 Oct 2025 at 13:08, Thomas Huth <thuth@redhat.com> wrote:
>
> On 10/10/2025 14.14, Peter Maydell wrote:
> >   tests/tcg/multiarch/linux/linux-test.c | 9 +++++++--
> >   1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/tests/tcg/multiarch/linux/linux-test.c b/tests/tcg/multiarch/linux/linux-test.c
> > index 64f57cb287e..bf6e0fda262 100644
> > --- a/tests/tcg/multiarch/linux/linux-test.c
> > +++ b/tests/tcg/multiarch/linux/linux-test.c
> > @@ -155,9 +155,14 @@ static void test_file(void)
>
> Maybe drop the "tbuf.actime = 1001;" earlier in this file, too?

The utime("file2", &tbuf)  call will still set both atime and
mtime, so we want to keep the initialization of that field
so we're not accessing an uninitialized value with the syscall.

> >           error("stat mode");
> >       if ((st.st_mode & 0777) != 0600)
> >           error("stat mode2");
> > -    if (st.st_atime != 1001 ||
> > -        st.st_mtime != 1000)
> > +    /*
> > +     * Only check mtime, not atime: other processes such as
> > +     * virus scanners might race with this test program and get
> > +     * in and update the atime, causing random failures.
>
> I actually saw similar problems when looking at the atimes of the files in
> the functional test cache, so I agree, checking atime cannot work reliably.
>
> Reviewed-by: Thomas Huth <thuth@redhat.com>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tests/tcg/multiarch/linux/linux-test: Don't try to test atime update
  2025-10-10 12:14 [PATCH] tests/tcg/multiarch/linux/linux-test: Don't try to test atime update Peter Maydell
  2025-10-16 10:41 ` Peter Maydell
  2025-10-16 12:08 ` Thomas Huth
@ 2025-10-16 14:34 ` Alex Bennée
  2 siblings, 0 replies; 5+ messages in thread
From: Alex Bennée @ 2025-10-16 14:34 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, qemu-stable

Peter Maydell <peter.maydell@linaro.org> writes:

> The linux-test test includes an attempt to check the utime and stat
> syscalls by setting the atime and mtime of a file to specific values,
> and then calling stat() to check that the values read back correctly.
>
> Unfortunately this is flaky, as it will fail if some other process
> (for instance a virus scanner, backup program, etc) gets in and reads
> the file between the utime() and stat() call, resulting in a host
> syscall sequence like this:

Queued to maintainer/oct-2025, thanks.

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-10-16 14:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-10 12:14 [PATCH] tests/tcg/multiarch/linux/linux-test: Don't try to test atime update Peter Maydell
2025-10-16 10:41 ` Peter Maydell
2025-10-16 12:08 ` Thomas Huth
2025-10-16 12:11   ` Peter Maydell
2025-10-16 14:34 ` Alex Bennée

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).