From patchwork Tue Jun 25 00:08:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1121606 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-102999-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="hf6dTOsd"; dkim=pass (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="IieAI3EW"; 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 45Xmml0gH7z9s3l for ; Tue, 25 Jun 2019 10:11:50 +1000 (AEST) 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:in-reply-to :references:mime-version:content-transfer-encoding; q=dns; s= default; b=fXlVHh+ErsYQuGj6XabK496C89YG6bchq7E1q3ckvjpK8BXeFpLNy FjZfoc0FFzlolhguy0UNE48ET7LIlIQBQlJB0kur2J8P/p4Nd+m3qeUvvdhixVFQ bItRk2H8LIRZR6jfa2i72fYJM89byoWGhtYTr+4lDrUktLW/V5a/1M= 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:in-reply-to :references:mime-version:content-transfer-encoding; s=default; bh=r3NcZxjrWKZUNUPcjYnKeYWrmfA=; b=hf6dTOsdhRVALQSSRhbHOGdP8VGu JnaRNOcQ569LO+JLF7m+YaR3TH5v5S009Ct2/TPBZXzPPOkATuo1T3Kd18QX0/xt k0cUGOf5dBdR9mRs+yU21zAn3COFsG0FG5/pbgjItwnoE+9EbPPDiR9Gyyhdn88X 8UCUPFaYdr711dc= Received: (qmail 17783 invoked by alias); 25 Jun 2019 00:11:24 -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 17730 invoked by uid 89); 25 Jun 2019 00:11:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=hour X-HELO: esa4.hgst.iphmx.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1561421483; x=1592957483; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rsMB1VG6QXIj3yq+YKZXHkgV8Sy3Q56YAXwL/5zhAAE=; b=IieAI3EWayczh8JY3eR43dbXSxO7nIAnGE1a4ohqwvWXs7zFQd7I7gnn e1BanExVHK87Ds3sR50ao10EgNJpRyjG3YAYZNYJ1CM53yVpbEM6tQ050 yELBBigm87WmkBxkHRyrGQ6K80Gt4i2lg1jk88TJTlxKWrLmOntWmKAWN CMUO37CpQIUUaHrn1QXoDQHxWM2T/9vlboamY+Phtjiuk6p8VECj9wuDZ yl6cz6LL2HmPVJUwJn3opFn6oXk1BGKMduA8eYmbSrVYSAOiVIIktbABQ NFc0cdAxXbhup96I3AwUIJ76mf+bs1t5tkxRos+fgehh1/6Wnb8t9Q19u Q==; IronPort-SDR: 5vWzNiXFiuHEjWl3nkzPdi7SdlA4DG734FakzqWNCGAgBr4H5UH1JbImR6kgOVpcHKSnOdPQih fFlx6Xbi2ec07f/gVsNDFSKMGivLsPj4d8K2bE341ij9KPrCG9WVggPNCV3sF5NInxQ8Nh4z5g gzdb0sUO5D+V4qv4EV7mqqrVkMOgl4DC2IzxLhYnsgtmNdsQzo3SDqHUoEcqE3VcOKmNMk2wCQ BtkLd7O+Bcqhup66Qi983lpStAvjq38w3lN7riNXkoEqBAQu+v748x1IUMqVRvALS+m8qXXDeO Ny7MK+sPVNvjEEe2Db5PJCUi IronPort-SDR: ShHySskeDXDN2h+4L23CWsA9cWMrFEZN2Hc6vbjYjJEQpuTxHOCg4+Q5Nfy1b16pZshmnDmMbG 29eCzO6ytKhpjGBtmzltF8K8l1NeQczO75FNs8YegkRBdrqn+v9dfh766ZPihwCceP/3fTOD3L fx9FI9MuJHbbV1ctSmZjeUj9hHnlqc9mTD/MOUnLwA4Y3Gr0X2Llu/mzB/uXVOSGG0EQ+cwZne 91Q9Zu8oUD3vSLH6I0l4Vhs2mnqPebsIM6zHBwvkqtjRVtO49FrrQsmUBETIPF9k/WY50sIxTg 3sg= From: Alistair Francis To: libc-alpha@sourceware.org Cc: arnd@arndb.de, adhemerval.zanella@linaro.org, fweimer@redhat.com, palmer@sifive.com, macro@wdc.com, zongbox@gmail.com, zong@andestech.com, alistair.francis@wdc.com, alistair23@gmail.com Subject: [RFC v2 03/20] y2038: linux: Provide __clock_settime64 implementation Date: Mon, 24 Jun 2019 17:08:52 -0700 Message-Id: <4a1304510a5c9b5c2f6432bfdc5c9fd1740a081f.1561421042.git.alistair.francis@wdc.com> In-Reply-To: References: MIME-Version: 1.0 From: Lukasz Majewski 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. The __ASSUME_TIME64_SYSCALLS flag indicates if the Linux kernel supports 64 bit version of clock_settime (i.e. clock_settime64). If this flag is not defined, the fallback with legacy clock_settime supporting 32 bit time is used. When working on 32 bit systems without Y2038 time support the clock_settime64 returns error when one wants to set time with wrong (overflowed) tv_sec value. Moreover, the correctness of tv_nsec is also checked. 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. Tests: - The code has been tested with x86_64/x86 (native compilation): make PARALLELMFLAGS="-j8" && make xcheck PARALLELMFLAGS="-j8" - 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 on kernels with and without 64 bit time support. 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-rc1+ Linux) --- include/time.h | 8 ++++++ sysdeps/unix/sysv/linux/clock_settime.c | 37 ++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/include/time.h b/include/time.h index 1b38d019c8..7155b2e4db 100644 --- a/include/time.h +++ b/include/time.h @@ -127,6 +127,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 d837e3019c..7274f01846 100644 --- a/sysdeps/unix/sysv/linux/clock_settime.c +++ b/sysdeps/unix/sysv/linux/clock_settime.c @@ -19,11 +19,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) @@ -32,6 +30,37 @@ __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, &ts32); + return INLINE_SYSCALL_CALL (clock_settime, clock_id, &ts32); +#endif } weak_alias (__clock_settime, clock_settime) + +#if __TIMESIZE != 64 +int +__clock_settime (clockid_t clock_id, const struct timespec *tp) +{ + struct __timespec64 ts64; + + valid_timespec_to_timespec64 (tp, &ts64); + return __clock_settime64 (clock_id, &ts64); +} +#endif