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

From: Vincenzo Frascino
Date: Thu Nov 28 2019 - 10:46:47 EST



On 28/11/2019 15:41, H. Nikolaus Schaller wrote:
>
>> Am 28.11.2019 um 16:07 schrieb Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx>:
>>
>> On Thu, Nov 28, 2019 at 02:48:46PM +0100, H. Nikolaus Schaller wrote:
>>>
>>> What still does not fit into the picture is the errno = 1 i.e. EPERM.
>>> Maybe I have to study the libc code that tries to read the ELF symbols
>>> you have mentioned. It may fail for unknown reasons.
>>
>> to understand vdso you might look at arch/mips/vdso and lib/vdso
>> kernel sources.
>
> Yes that is what I know, but I do not know how glibc can return an EPERM
> through VDSO.
>
>>
>> And if I understand it correctly you neither have a working high resolution
>> timer usable bei do_hres() in lib/vdso/gettimeofday.c or a working
>> gettimeofday_fallback(), which is enabled via CONFIG_MIPS_CLOCK_VSYSCALL
>> and needs either CSRC_R4K or CLKSRC_MIPS_GIC.
>
> Well, on kernel v4.19 or using v5.4 with Jessie, gettimeofday() works.
>
> So this may only be part of the reason it starts to fail with commit
> 24640f233b466051ad3a5d2786d2951e43026c9d.
>
> MIPS_CLOCK_VSYSCALL is neither defined nor undefined in the defconfig.
> And removed if I manually add it to my defconfig.
> And yes, it depends on either CSRC_R4K || CLKSRC_MIPS_GIC by arch/mips/Kconfig.
>
> Maybe this was just forgotten to properly handle for the ci20_defconfig
> or jz4780?
>
> What does CSRC_R4K resp. CLKSRC_MIPS_GIC ecactly mean? Does the jz4780 have this
> feature?
>

I think I know what is going on, it is the way on which libc does the fallback.
Could you please try the patch below the scissors and let me know if it works?
If it does I will create a proper one.

> BR and thanks,
> Nikolaus
>

--
Regards,
Vincenzo

--->8---


From e15157402c750298a5c82a08c934c19e71f24fce Mon Sep 17 00:00:00 2001
From: Vincenzo Frascino <vincenzo.frascino@xxxxxxx>
Date: Thu, 28 Nov 2019 15:37:31 +0000
Subject: [PATCH] Mips32 gettimeofday fix

Signed-off-by: Vincenzo Frascino <vincenzo.frascino@xxxxxxx>
---
arch/mips/include/asm/vdso/gettimeofday.h | 11 +----------
arch/mips/vdso/vgettimeofday.c | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/arch/mips/include/asm/vdso/gettimeofday.h
b/arch/mips/include/asm/vdso/gettimeofday.h
index b08825531e9f..f4fc11a4d324 100644
--- a/arch/mips/include/asm/vdso/gettimeofday.h
+++ b/arch/mips/include/asm/vdso/gettimeofday.h
@@ -48,16 +48,7 @@ static __always_inline long gettimeofday_fallback(
return error ? -ret : ret;
}

-#else
-
-static __always_inline long gettimeofday_fallback(
- struct __kernel_old_timeval *_tv,
- struct timezone *_tz)
-{
- return -1;
-}
-
-#endif
+#endif /* CONFIG_MIPS_CLOCK_VSYSCALL */

static __always_inline long clock_gettime_fallback(
clockid_t _clkid,
diff --git a/arch/mips/vdso/vgettimeofday.c b/arch/mips/vdso/vgettimeofday.c
index 6ebdc37c89fc..6b83b6376a4b 100644
--- a/arch/mips/vdso/vgettimeofday.c
+++ b/arch/mips/vdso/vgettimeofday.c
@@ -17,12 +17,22 @@ int __vdso_clock_gettime(clockid_t clock,
return __cvdso_clock_gettime32(clock, ts);
}

+#ifdef CONFIG_MIPS_CLOCK_VSYSCALL
+
+/*
+ * This is behind the ifdef so that we don't provide the symbol when there's no
+ * possibility of there being a usable clocksource, because there's nothing we
+ * can do without it. When libc fails the symbol lookup it should fall back on
+ * the standard syscall path.
+ */
int __vdso_gettimeofday(struct __kernel_old_timeval *tv,
struct timezone *tz)
{
return __cvdso_gettimeofday(tv, tz);
}

+#endif /* CONFIG_MIPS_CLOCK_VSYSCALL */
+
int __vdso_clock_getres(clockid_t clock_id,
struct old_timespec32 *res)
{
@@ -43,12 +53,22 @@ int __vdso_clock_gettime(clockid_t clock,
return __cvdso_clock_gettime(clock, ts);
}

+#ifdef CONFIG_MIPS_CLOCK_VSYSCALL
+
+/*
+ * This is behind the ifdef so that we don't provide the symbol when there's no
+ * possibility of there being a usable clocksource, because there's nothing we
+ * can do without it. When libc fails the symbol lookup it should fall back on
+ * the standard syscall path.
+ */
int __vdso_gettimeofday(struct __kernel_old_timeval *tv,
struct timezone *tz)
{
return __cvdso_gettimeofday(tv, tz);
}

+#endif /* CONFIG_MIPS_CLOCK_VSYSCALL */
+
int __vdso_clock_getres(clockid_t clock_id,
struct __kernel_timespec *res)
{
--
2.24.0

Attachment: pEpkey.asc
Description: application/pgp-keys