Re: [PATCH] time/fs - file's time race with vgettimeofday

From: Oleg Nesterov
Date: Fri Jul 02 2010 - 12:22:31 EST


On 07/02, Oleg Nesterov wrote:
>
> But, get_seconds() is also used by sys_time(), and we should have the
> same problem with another trivial test-case:
>
> #include <stdio.h>
> #include <sys/time.h>
> #include <time.h>
>
> int main(void)
> {
> struct timeval tv;
> int sec;
>
> do {
> gettimeofday(&tv, NULL);
> sec = time(NULL);
> } while (tv.tv_sec <= sec);
>
> printf("gtod: %ld.%06ld\n", tv.tv_sec, tv.tv_usec);
> printf("time: %d.000000\n", sec);
> return 0;
> }
>
> However, this test-case can't trigger the problem. Confused.

Aha. libc's time() doesn't use sys_time(), it uses __vsyscall(1)
vtime()->do_vgettimeofday().

This one quickly triggers the "time goes backward" case.

#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <sys/syscall.h>

int main(void)
{
struct timeval tv;
int sec;

do {
gettimeofday(&tv, NULL);
sec = syscall(__NR_time, NULL);
} while (tv.tv_sec <= sec);

printf("gtod: %ld.%06ld\n", tv.tv_sec, tv.tv_usec);
printf("time: %d.000000\n", sec);
return 0;
}

Not that I think this "problem" should be fixed, just curious.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/