Re: MIPS: bug: gettimeofday syscall broken on CI20 board

From: H. Nikolaus Schaller
Date: Wed Nov 27 2019 - 09:29:31 EST


Hi Vincenco,

> Am 27.11.2019 um 14:53 schrieb H. Nikolaus Schaller <hns@xxxxxxxxxxxxx>:
>
> Hi Vincenzo,
>
>> Am 26.11.2019 um 11:52 schrieb Vincenzo Frascino <vincenzo.frascino@xxxxxxx>:
>>
>> I do not have a CI20 hence I can't do the test myself: could you please write a
>> small application that invokes gettimeofday() as per above and report the
>> behavior (I am even interested in the value returned). If we can reproduce the
>> problem in a smaller environment it is easier to debug and get to the solution.
>>
>> [1] http://users.isc.org/~each/doxygen/bind9/isc_2unix_2time_8c-source.html
>>
>> Let me know.
>
> I have done this and it seems as if tv_usec reports something that is beyond 1e6 us
> or remains unchanged by the syscall. tv_sec seems to be set correctly. And,
> gettimeofday() reports -1.
>
> hwclock isn't set on 45.4 kernel because I have no ethernet connection due to the bug.
>
> BR,
> Nikolaus
>
>
> Here is the log
>
> a) with 5.4 kernel
>
> root@letux:~# cat gettime.c
> #include <stdio.h>
> #include <time.h>
> #include <sys/time.h>
>
> int main(void)
> {
> struct timeval tv;
> int r = gettimeofday(&tv, NULL);
> time_t t;
> int rt = time(&t);
>
> printf("r = %d\n", r);
> printf("tv.sec = %ld\n", tv.tv_sec);
> printf("tv.usec = %d\n", tv.tv_usec);
> printf("rt = %d\n", rt);
> printf("t = %ld\n", t);
> }

I realized that this does not allow to distinguish between
uninitialized struct timeval tv and return values. And it
would be nice to print errno. So I have used a new version:

#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <errno.h>

int main(void)
{
struct timeval tv = { 1, 1 };
int r;
time_t t;
int rt;

r = gettimeofday(&tv, NULL);
printf("r = %d errno=%d\n", r, errno);
printf("tv.sec = %ld\n", tv.tv_sec);
printf("tv.usec = %d\n", tv.tv_usec);

rt = time(&t);
printf("rt = %d errno=%d\n", rt, errno);
printf("t = %ld\n", t);
}

> root@letux:~# make gettime
> cc gettime.c -o gettime
> root@letux:~# ./gettime
> r = -1
> tv.sec = 1431857456
> tv.usec = 2012065500
> rt = 1478206565
> t = 1478206565

root@letux:~# ./gettime
r = -1 errno=1
tv.sec = 1
tv.usec = 1
rt = 1478193516 errno=1
t = 1478193516
root@letux:~#

which means that there is an -EPERM and &tv is not touched.
Well, I did run this as root.

So it may be a completely different reason than changing the
VDSO structure.

> b) same system booted with 4.19 kernel:
>
> root@letux:~# ./gettime
> r = 0
> tv.sec = 1574862135
> tv.usec = 27974
> rt = 1574862135
> t = 1574862135

root@letux:~# ./gettime
r = 0 errno=0
tv.sec = 1574863040
tv.usec = 874858
rt = 1574863040 errno=0
t = 1574863040
root@letux:~#


> root@letux:~# uname -a
> Linux letux 4.19.86-letux-l400+ #1450 PREEMPT Sun Nov 24 17:17:19 CET 2019 mips GNU/Linux

Please let me know what I should try next.

BR and thanks,
Nikolaus