diff mbox series

[v2,2/8] lib: vdso: Build 32 bit specific functions in the right context

Message ID 20190830135902.20861-3-vincenzo.frascino@arm.com (mailing list archive)
State Not Applicable
Headers show
Series vdso: Complete the conversion to 32bit syscalls | expand

Commit Message

Vincenzo Frascino Aug. 30, 2019, 1:58 p.m. UTC
clock_gettime32 and clock_getres_time32 should be compiled only with a
32 bit vdso library.

Exclude these symbols when BUILD_VDSO32 is not defined.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Reviewed-by: Andy Lutomirski <luto@kernel.org>
---
 lib/vdso/gettimeofday.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Thomas Gleixner Jan. 13, 2020, 10:28 p.m. UTC | #1
Vincenzo Frascino <vincenzo.frascino@arm.com> writes:

> clock_gettime32 and clock_getres_time32 should be compiled only with a
> 32 bit vdso library.
>
> Exclude these symbols when BUILD_VDSO32 is not defined.

This breaks the ARM build with:

arch/arm/vdso/vgettimeofday.c: In function ‘__vdso_clock_gettime’:
arch/arm/vdso/vgettimeofday.c:15:9: error: implicit declaration of function ‘__cvdso_clock_gettime32’; did you mean ‘__cvdso_clock_gettime’? [-Werror=implicit-function-declaration]
  return __cvdso_clock_gettime32(clock, ts);
         ^~~~~~~~~~~~~~~~~~~~~~~
         __cvdso_clock_gettime
arch/arm/vdso/vgettimeofday.c: In function ‘__vdso_clock_getres’:
arch/arm/vdso/vgettimeofday.c:33:9: error: implicit declaration of function ‘__cvdso_clock_getres_time32’; did you mean ‘__cvdso_clock_getres_common’? [-Werror=implicit-function-declaration]
  return __cvdso_clock_getres_time32(clock_id, res);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
         __cvdso_clock_getres_common
cc1: some warnings being treated as errors

The patch below 'fixes' at least the build. Can someone please confirm
the correctness?

Thanks,

        tglx

8<----------------
--- a/arch/arm/vdso/Makefile
+++ b/arch/arm/vdso/Makefile
@@ -14,7 +14,7 @@ targets := $(obj-vdso) vdso.so vdso.so.d
 obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
 
 ccflags-y := -fPIC -fno-common -fno-builtin -fno-stack-protector
-ccflags-y += -DDISABLE_BRANCH_PROFILING
+ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO32
 
 ldflags-$(CONFIG_CPU_ENDIAN_BE8) := --be8
 ldflags-y := -Bsymbolic --no-undefined -soname=linux-vdso.so.1 \
Thomas Gleixner Jan. 14, 2020, 9:33 a.m. UTC | #2
Thomas Gleixner <tglx@linutronix.de> writes:

> Vincenzo Frascino <vincenzo.frascino@arm.com> writes:
>
>> clock_gettime32 and clock_getres_time32 should be compiled only with a
>> 32 bit vdso library.
>>
>> Exclude these symbols when BUILD_VDSO32 is not defined.
>
> This breaks the ARM build with:
>
> arch/arm/vdso/vgettimeofday.c: In function ‘__vdso_clock_gettime’:
> arch/arm/vdso/vgettimeofday.c:15:9: error: implicit declaration of function ‘__cvdso_clock_gettime32’; did you mean ‘__cvdso_clock_gettime’? [-Werror=implicit-function-declaration]
>   return __cvdso_clock_gettime32(clock, ts);
>          ^~~~~~~~~~~~~~~~~~~~~~~
>          __cvdso_clock_gettime
> arch/arm/vdso/vgettimeofday.c: In function ‘__vdso_clock_getres’:
> arch/arm/vdso/vgettimeofday.c:33:9: error: implicit declaration of function ‘__cvdso_clock_getres_time32’; did you mean ‘__cvdso_clock_getres_common’? [-Werror=implicit-function-declaration]
>   return __cvdso_clock_getres_time32(clock_id, res);
>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>          __cvdso_clock_getres_common
> cc1: some warnings being treated as errors
>
> The patch below 'fixes' at least the build. Can someone please confirm
> the correctness?

Bah, it's not fixing it. That's what you get when you compile the wrong
tree...
Vincenzo Frascino Jan. 14, 2020, 10:15 a.m. UTC | #3
Hi Thomas,

On 14/01/2020 09:33, Thomas Gleixner wrote:
> Thomas Gleixner <tglx@linutronix.de> writes:
> 
[...]

> 
> Bah, it's not fixing it. That's what you get when you compile the wrong
> tree...
> 

I am having a look at it. Thanks.
Thomas Gleixner Jan. 14, 2020, 10:37 a.m. UTC | #4
Vincenzo Frascino <vincenzo.frascino@arm.com> writes:
>
> On 14/01/2020 09:33, Thomas Gleixner wrote:
>> Thomas Gleixner <tglx@linutronix.de> writes:
>> 
> [...]
>
>> 
>> Bah, it's not fixing it. That's what you get when you compile the wrong
>> tree...

This part is required to cover the BUILD_VDSO32 guard, but then when the
fallback thing is removed it fails again because the 32bit fallbacks are
missing.

The patch below makes it build again.

Thanks,

        tglx

8<----------------
--- a/arch/arm/include/asm/vdso/gettimeofday.h
+++ b/arch/arm/include/asm/vdso/gettimeofday.h
@@ -52,6 +52,24 @@ static __always_inline long clock_gettim
 	return ret;
 }
 
+static __always_inline long clock_gettime32_fallback(
+					clockid_t _clkid,
+					struct old_timespec32 *_ts)
+{
+	register struct old_timespec32 *ts asm("r1") = _ts;
+	register clockid_t clkid asm("r0") = _clkid;
+	register long ret asm ("r0");
+	register long nr asm("r7") = __NR_clock_gettime;
+
+	asm volatile(
+	"	swi #0\n"
+	: "=r" (ret)
+	: "r" (clkid), "r" (ts), "r" (nr)
+	: "memory");
+
+	return ret;
+}
+
 static __always_inline int clock_getres_fallback(
 					clockid_t _clkid,
 					struct __kernel_timespec *_ts)
@@ -63,6 +81,24 @@ static __always_inline int clock_getres_
 
 	asm volatile(
 	"       swi #0\n"
+	: "=r" (ret)
+	: "r" (clkid), "r" (ts), "r" (nr)
+	: "memory");
+
+	return ret;
+}
+
+static __always_inline int clock_getres32_fallback(
+					clockid_t _clkid,
+					struct old_timespec32 *_ts)
+{
+	register struct old_timespec32 *ts asm("r1") = _ts;
+	register clockid_t clkid asm("r0") = _clkid;
+	register long ret asm ("r0");
+	register long nr asm("r7") = __NR_clock_getres;
+
+	asm volatile(
+	"       swi #0\n"
 	: "=r" (ret)
 	: "r" (clkid), "r" (ts), "r" (nr)
 	: "memory");
Vincenzo Frascino Jan. 14, 2020, 10:41 a.m. UTC | #5
Hi Thomas,

On 14/01/2020 10:37, Thomas Gleixner wrote:
> Vincenzo Frascino <vincenzo.frascino@arm.com> writes:
>>
>> On 14/01/2020 09:33, Thomas Gleixner wrote:
>>> Thomas Gleixner <tglx@linutronix.de> writes:
>>>
>> [...]
>>
>>>
>>> Bah, it's not fixing it. That's what you get when you compile the wrong
>>> tree...
> 
> This part is required to cover the BUILD_VDSO32 guard, but then when the
> fallback thing is removed it fails again because the 32bit fallbacks are
> missing.
> 
> The patch below makes it build again.
> 

I agree. I am testing it now :) Do you prefer to create the patch or shall I do
it once I finish testing?
Vincenzo Frascino Jan. 14, 2020, 11:15 a.m. UTC | #6
Hi Thomas,

On 14/01/2020 10:37, Thomas Gleixner wrote:
> Vincenzo Frascino <vincenzo.frascino@arm.com> writes:
>>
>> On 14/01/2020 09:33, Thomas Gleixner wrote:
>>> Thomas Gleixner <tglx@linutronix.de> writes:
>>>
>> [...]
>>
>>>
>>> Bah, it's not fixing it. That's what you get when you compile the wrong
>>> tree...
> 
> This part is required to cover the BUILD_VDSO32 guard, but then when the
> fallback thing is removed it fails again because the 32bit fallbacks are
> missing.
> 
> The patch below makes it build again.
I completed the testing and everything seems fine. For completeness I am
reporting the test results below:

clock-gettime-monotonic: syscall: 938 nsec/call
clock-gettime-monotonic:    libc: 278 nsec/call
clock-gettime-monotonic:    vdso: 270 nsec/call
clock-getres-monotonic: syscall: 678 nsec/call
clock-getres-monotonic:    libc: 692 nsec/call
clock-getres-monotonic:    vdso: 33 nsec/call
clock-gettime-monotonic-coarse: syscall: 840 nsec/call
clock-gettime-monotonic-coarse:    libc: 184 nsec/call
clock-gettime-monotonic-coarse:    vdso: 172 nsec/call
clock-getres-monotonic-coarse: syscall: 710 nsec/call
clock-getres-monotonic-coarse:    libc: 733 nsec/call
clock-getres-monotonic-coarse:    vdso: 35 nsec/call
clock-gettime-monotonic-raw: syscall: 894 nsec/call
clock-gettime-monotonic-raw:    libc: 278 nsec/call
clock-gettime-monotonic-raw:    vdso: 270 nsec/call
clock-getres-monotonic-raw: syscall: 669 nsec/call
clock-getres-monotonic-raw:    libc: 696 nsec/call
clock-getres-monotonic-raw:    vdso: 35 nsec/call
clock-gettime-tai: syscall: 933 nsec/call
clock-gettime-tai:    libc: 277 nsec/call
clock-gettime-tai:    vdso: 264 nsec/call
clock-getres-tai: syscall: 674 nsec/call
clock-getres-tai:    libc: 696 nsec/call
clock-getres-tai:    vdso: 33 nsec/call
clock-gettime-boottime: syscall: 934 nsec/call
clock-gettime-boottime:    libc: 278 nsec/call
clock-gettime-boottime:    vdso: 270 nsec/call
clock-getres-boottime: syscall: 677 nsec/call
clock-getres-boottime:    libc: 690 nsec/call
clock-getres-boottime:    vdso: 33 nsec/call
clock-gettime-realtime: syscall: 901 nsec/call
clock-gettime-realtime:    libc: 278 nsec/call
clock-gettime-realtime:    vdso: 272 nsec/call
clock-getres-realtime: syscall: 677 nsec/call
clock-getres-realtime:    libc: 701 nsec/call
clock-getres-realtime:    vdso: 33 nsec/call
clock-gettime-realtime-coarse: syscall: 838 nsec/call
clock-gettime-realtime-coarse:    libc: 184 nsec/call
clock-gettime-realtime-coarse:    vdso: 172 nsec/call
clock-getres-realtime-coarse: syscall: 713 nsec/call
clock-getres-realtime-coarse:    libc: 736 nsec/call
clock-getres-realtime-coarse:    vdso: 35 nsec/call
getcpu: syscall: 620 nsec/call
getcpu:    libc: 648 nsec/call
gettimeofday: syscall: 1022 nsec/call
gettimeofday:    libc: 280 nsec/call
gettimeofday:    vdso: 272 nsec/call
diff mbox series

Patch

diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c
index e630e7ff57f1..a86e89e6dedc 100644
--- a/lib/vdso/gettimeofday.c
+++ b/lib/vdso/gettimeofday.c
@@ -117,6 +117,7 @@  __cvdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts)
 	return 0;
 }
 
+#ifdef BUILD_VDSO32
 static __maybe_unused int
 __cvdso_clock_gettime32(clockid_t clock, struct old_timespec32 *res)
 {
@@ -139,6 +140,7 @@  __cvdso_clock_gettime32(clockid_t clock, struct old_timespec32 *res)
 	}
 	return ret;
 }
+#endif /* BUILD_VDSO32 */
 
 static __maybe_unused int
 __cvdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
@@ -229,6 +231,7 @@  int __cvdso_clock_getres(clockid_t clock, struct __kernel_timespec *res)
 	return 0;
 }
 
+#ifdef BUILD_VDSO32
 static __maybe_unused int
 __cvdso_clock_getres_time32(clockid_t clock, struct old_timespec32 *res)
 {
@@ -251,4 +254,5 @@  __cvdso_clock_getres_time32(clockid_t clock, struct old_timespec32 *res)
 	}
 	return ret;
 }
+#endif /* BUILD_VDSO32 */
 #endif /* VDSO_HAS_CLOCK_GETRES */