From patchwork Tue Oct 8 11:00:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 1173200 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105727-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="gvk1bxdd"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46nZCN4R9Yz9sP7 for ; Tue, 8 Oct 2019 22:01:04 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; q=dns; s=default; b=vIq vokKAER0J2eMHUvL9XBD012875BGHKqbiA6cjk6QqZlpSpRqf51u6IGgRazf7rYX nt1AyCYn8T4ivQk3x5jAX3gduqeU09KcV0U6ljc5xwtW50hNY7AaVrlm+DOM457E zRi4RdnN52yiwE5lssfYB9E5fIqtHSO6XQ/gUVUM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=default; bh=DbKgbHU1X f+SHZq+0jvHzW5bPeQ=; b=gvk1bxdd5kiXU244GbS93LnQ03O35AUBXS8Lgi7Kn IyoRHuYchMyam2DFFcjPAKmPC7sLZDelb32/A6Usj3uQJOdFTlTysLRffgEBQRYn 6popGeJc5oGXTcbd4eEGy3Bd8WbrC/cEAzMhZfQ7VLXaikq5lIbriSPneIIKvXoC 1Q= Received: (qmail 48373 invoked by alias); 8 Oct 2019 11:00:57 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 48296 invoked by uid 89); 8 Oct 2019 11:00:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy=newest, UD:sh, contemporary X-HELO: mail-out.m-online.net From: Lukasz Majewski To: Joseph Myers Cc: Paul Eggert , Alistair Francis , Alistair Francis , GNU C Library , Adhemerval Zanella , Florian Weimer , Carlos O'Donell , Stepan Golosunov , Florian Weimer , Zack Weinberg , Lukasz Majewski Subject: [PATCH v9] y2038: linux: Provide __clock_settime64 implementation Date: Tue, 8 Oct 2019 13:00:16 +0200 Message-Id: <20191008110016.13646-1-lukma@denx.de> MIME-Version: 1.0 This patch provides new __clock_settime64 explicit 64 bit function for setting the time. Moreover, a 32 bit version - __clock_settime - has been refactored to internally use __clock_settime64. The __clock_settime is now supposed to be used on systems still supporting 32 bit time (__TIMESIZE != 64) - hence the necessary conversion to 64 bit struct timespec. The new clock_settime64 syscall available from Linux 5.1+ has been used, when applicable. In this patch the internal padding (tv_pad) of struct __timespec64 is left untouched (on systems with __WORDSIZE == 32) as Linux kernel ignores upper 32 bits of tv_nsec. Build tests: - The code has been tested on x86_64/x86 (native compilation): make PARALLELMFLAGS="-j8" && make xcheck PARALLELMFLAGS="-j8" - The glibc has been build tested (make PARALLELMFLAGS="-j8") for x86 (i386), x86_64-x32, and armv7 Run-time tests: - Run specific tests on ARM/x86 32bit systems (qemu): https://github.com/lmajewski/meta-y2038 and run tests: https://github.com/lmajewski/y2038-tests/commits/master - Use of cross-test-ssh.sh for ARM (armv7): make PARALLELMFLAGS="-j8" test-wrapper='./cross-test-ssh.sh root@192.168.7.2' xcheck Linux kernel, headers and minimal kernel version for glibc build test matrix: - Linux v5.1 (with clock_settime64) and glibc build with v5.1 as minimal kernel version (--enable-kernel="5.1.0") The __ASSUME_TIME64_SYSCALLS flag defined. - Linux v5.1 and default minimal kernel version The __ASSUME_TIME64_SYSCALLS not defined, but kernel supports __clock_settime64 syscalls. - Linux v4.19 (no clock_settime64 support) with default minimal kernel version for contemporary glibc This kernel doesn't support __clock_settime64 syscalls, so the fallback to clock_settime is tested. The above tests were performed with Y2038 redirection applied as well as without (so the __TIMESIZE != 64 execution path is checked as well). No regressions were observed. * include/time.h (__clock_settime64): Add __clock_settime alias according to __TIMESIZE define * sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime): Refactor this function to be used only on 32 bit machines as a wrapper on __clock_settime64. * sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime64): Add * sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime64): Use clock_settime64 kernel syscall (available from 5.1+ Linux) --- Changes for v9: - Add information regarding test scenarios - Adjust the code to use struct __timespec64 helper functions Changes for v8: - None Changes for v7: - Revert changes to __clock_settime - as a result it now behaves as in v5 (It is a wrapper on __clock_settime64). - Fix the code to apply on newest master (after moving clock_settime to libc from librt). Changes for v6: - In the __clock_settime function do not call __clock_settime64 - just use the clock_settime 32 bit ABI syscall. Such approach will facilitate updating systems with __WORDSIZE==32 to be Y2038 safe by disabling for example clock_settime 32 bit syscall in the Linux kernel. Changes for v5: - Use __ASSUME_TIME64_SYSCALLS to indicate Linux kernel support for 64 bit time. - Move the in_time_t_range() check to __clock_settime64 - Alias __NR_clock_settime64 to __NR_clock_settime if the former is not defined in the headers. Changes for v4: - __ASSUME_TIME64_SYSCALLS for fall back path - Use __SYSCALL_WORDSIZE to exclude 'x32' from execution path (so it will use x86_64 syscall - Rewrite the commit message Changes for v3: - Rename __ASSUME_64BIT_TIME to __ASSUME_TIME64_SYSCALLS - Refactor in-code comment (add information regarding Linux kernel ignorance of padding - Do not use __TIMESIZE to select main execution path (for Y2038 systems __TIMESIZE would be changed from 32 to 64 bits at some point to indicate full Y2038 support Changes for v2: - Add support for __ASSUME_64BIT_TIME flag when Linux kernel provides syscalls supporting 64 bit time on 32 bit systems - Provide fallback to 32 bit version of clock_settime when clock_settime64 is not available - Do not copy *tp to timespec - this seems like an overkill as in clock_settime() the 32 bit struct timespec is copied to internal 64 bit struct __timespec64 --- include/time.h | 8 ++++++ sysdeps/unix/sysv/linux/clock_settime.c | 36 ++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/include/time.h b/include/time.h index f6dc731ac6..d93b16a781 100644 --- a/include/time.h +++ b/include/time.h @@ -125,6 +125,14 @@ extern __time64_t __timegm64 (struct tm *__tp) __THROW; libc_hidden_proto (__timegm64) #endif +#if __TIMESIZE == 64 +# define __clock_settime64 __clock_settime +#else +extern int __clock_settime64 (clockid_t clock_id, + const struct __timespec64 *tp); +libc_hidden_proto (__clock_settime64) +#endif + /* Compute the `struct tm' representation of T, offset OFFSET seconds east of UTC, and store year, yday, mon, mday, wday, hour, min, sec into *TP. diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c index f76178e0f6..fb48de5d50 100644 --- a/sysdeps/unix/sysv/linux/clock_settime.c +++ b/sysdeps/unix/sysv/linux/clock_settime.c @@ -20,11 +20,9 @@ #include #include -#include "kernel-posix-cpu-timers.h" - /* Set CLOCK to value TP. */ int -__clock_settime (clockid_t clock_id, const struct timespec *tp) +__clock_settime64 (clockid_t clock_id, const struct __timespec64 *tp) { /* Make sure the time cvalue is OK. */ if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000) @@ -33,8 +31,38 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp) return -1; } - return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp); +#ifdef __ASSUME_TIME64_SYSCALLS +# ifndef __NR_clock_settime64 +# define __NR_clock_settime64 __NR_clock_settime +# endif + return INLINE_SYSCALL_CALL (clock_settime64, clock_id, tp); +#else +# ifdef __NR_clock_settime64 + int ret = INLINE_SYSCALL_CALL (clock_settime64, clock_id, tp); + if (ret == 0 || errno != ENOSYS) + return ret; +# endif + if (! in_time_t_range (tp->tv_sec)) + { + __set_errno (EOVERFLOW); + return -1; + } + + struct timespec ts32 = valid_timespec64_to_timespec (*tp); + return INLINE_SYSCALL_CALL (clock_settime, clock_id, &ts32); +#endif } + +#if __TIMESIZE != 64 +int +__clock_settime (clockid_t clock_id, const struct timespec *tp) +{ + struct __timespec64 ts64 = valid_timespec_to_timespec64 (*tp); + + return __clock_settime64 (clock_id, &ts64); +} +#endif + libc_hidden_def (__clock_settime) versioned_symbol (libc, __clock_settime, clock_settime, GLIBC_2_17);