From patchwork Wed Nov 18 07:58:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 1401999 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CbZwP2bShz9s1l for ; Wed, 18 Nov 2020 18:59:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7163D3840C39; Wed, 18 Nov 2020 07:59:46 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-out.m-online.net (mail-out.m-online.net [IPv6:2001:a60:0:28:0:1:25:1]) by sourceware.org (Postfix) with ESMTPS id BCD77385800A for ; Wed, 18 Nov 2020 07:59:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BCD77385800A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=lukma@denx.de Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4CbZwD2M0Nz1rxYR; Wed, 18 Nov 2020 08:59:40 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4CbZwD0mbDz1spY2; Wed, 18 Nov 2020 08:59:40 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id pdkl4iMU0phm; Wed, 18 Nov 2020 08:59:38 +0100 (CET) X-Auth-Info: LJ2h+TiWmP8QjzN1rTN7EBfxm4r91OBLzM533ixQYYA= Received: from localhost.localdomain (89-64-5-98.dynamic.chello.pl [89.64.5.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Wed, 18 Nov 2020 08:59:38 +0100 (CET) From: Lukasz Majewski To: Joseph Myers , Paul Eggert , Adhemerval Zanella Subject: [PATCH v3] y2038: Convert aio_suspend to support 64 bit time Date: Wed, 18 Nov 2020 08:58:53 +0100 Message-Id: <20201118075853.4438-1-lukma@denx.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Florian Weimer , GNU C Library , Andreas Schwab , Stepan Golosunov , Alistair Francis Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The aio_suspend function has been converted to support 64 bit time. In the __aio_suspend_common64() function not all occurrences of struct timespec, clock_gettime() and pthread_cond_timedwait() have been replaced with their 64 bit counterparts, as i686-gnu port (HURD) don't #define DONT_NEED_AIO_MISC_COND and requires them (as it is not yet supporting 64 bit time for being Y2038 safe). This change uses: - New __futex_reltimed_wait64 (instead of futex_reltimed_wait) - New __futex_reltimed_wait_cancellable64 (instead of futex_reltimed_wait_cancellable) from ./sysdeps/nptl/futex-helpers.h The aio_suspend() accepts relative timeout. The __aio_suspend() is supposed to be run on ports with __TIMESIZE !=64 and __WORDSIZE==32. It internally utilizes __aio_suspend_time64() and hence the conversion from 32 bit struct timespec to 64 bit one is required. For ports supporting 64 bit time the __aio_suspend_time64() will be used either via alias (to __aio_suspend when __TIMESIZE==64) or redirection (when -D_TIME_BITS=64 is passed). Build tests: ./src/scripts/build-many-glibcs.py glibcs --- Changes for v2: - Add missing -EOVERFLOW error handling for __futex_reltimed_wait64 and _futex_reltimed_wait_cancelable64 Changes for v3: - Remove "__" prefix from futex_reltimed_wait64 and futex_reltimed_wait_cancellable64 - Remove some code, as HURD is not defining DONT_NEED_AIO_MISC_COND (i.e. Linux ports are defining it) and add in-code explanation why the code is NOT converted to support 64 bit time. - Rewrite the commit message Reviewed-by: Alistair Francis --- include/aio.h | 8 +++ sysdeps/nptl/aio_misc.h | 4 +- sysdeps/nptl/futex-internal.h | 93 +++++++++++++++++++++++++++++++++++ sysdeps/pthread/aio_suspend.c | 39 +++++++++++++-- 4 files changed, 139 insertions(+), 5 deletions(-) diff --git a/include/aio.h b/include/aio.h index 90c74f9951..c7f4233310 100644 --- a/include/aio.h +++ b/include/aio.h @@ -9,6 +9,14 @@ extern void __aio_init (const struct aioinit *__init); lio_listio and we do not issue events for each individual list element. */ #define LIO_NO_INDIVIDUAL_EVENT 128 + +# if __TIMESIZE == 64 +# define __aio_suspend_time64 __aio_suspend +# else +extern int __aio_suspend_time64 (const struct aiocb *const list[], int nent, + const struct __timespec64 *timeout); +librt_hidden_proto (__aio_suspend_time64) +# endif #endif #endif diff --git a/sysdeps/nptl/aio_misc.h b/sysdeps/nptl/aio_misc.h index 3f195f4794..b9d226c98d 100644 --- a/sysdeps/nptl/aio_misc.h +++ b/sysdeps/nptl/aio_misc.h @@ -45,10 +45,10 @@ do \ { \ if (cancel) \ - status = futex_reltimed_wait_cancelable ( \ + status = futex_reltimed_wait_cancelable64 ( \ (unsigned int *) futexaddr, oldval, timeout, FUTEX_PRIVATE); \ else \ - status = futex_reltimed_wait ((unsigned int *) futexaddr, \ + status = futex_reltimed_wait64 ((unsigned int *) futexaddr, \ oldval, timeout, FUTEX_PRIVATE); \ if (status != EAGAIN) \ break; \ diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h index c27d0cdac8..e351e28d1d 100644 --- a/sysdeps/nptl/futex-internal.h +++ b/sysdeps/nptl/futex-internal.h @@ -609,4 +609,97 @@ __futex_clock_wait_bitset64 (int *futexp, int val, clockid_t clockid, const struct __timespec64 *abstime, int private) attribute_hidden; +static __always_inline int +futex_reltimed_wait64 (unsigned int *futex_word, unsigned int expected, + const struct __timespec64 *reltime, int private) +{ + int err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, + __lll_private_flag (FUTEX_WAIT, private), + expected, reltime); +#ifndef __ASSUME_TIME64_SYSCALLS + if (err == -ENOSYS) + { + if (in_time_t_range (reltime->tv_sec)) + { + struct timespec ts32 = valid_timespec64_to_timespec (*reltime); + + err = INTERNAL_SYSCALL_CALL (futex, futex_word, + __lll_private_flag (FUTEX_WAIT, + private), + expected, &ts32); + } + else + err = -EOVERFLOW; + } +#endif + switch (err) + { + case 0: + case -EAGAIN: + case -EINTR: + case -ETIMEDOUT: + case -EOVERFLOW: /* Passed relative timeout uses 64 bit time_t type, but + underlying kernel does not support 64 bit time_t futex + syscalls. */ + return -err; + + case -EFAULT: /* Must have been caused by a glibc or application bug. */ + case -EINVAL: /* Either due to wrong alignment or due to the timeout not + being normalized. Must have been caused by a glibc or + application bug. */ + case -ENOSYS: /* Must have been caused by a glibc bug. */ + /* No other errors are documented at this time. */ + default: + futex_fatal_error (); + } +} + +/* Like futex_reltimed_wait but is a POSIX cancellation point. */ +static __always_inline int +futex_reltimed_wait_cancelable64 (unsigned int *futex_word, + unsigned int expected, + const struct __timespec64 *reltime, + int private) +{ + int err = INTERNAL_SYSCALL_CANCEL (futex_time64, futex_word, + __lll_private_flag (FUTEX_WAIT, private), + expected, reltime); +#ifndef __ASSUME_TIME64_SYSCALLS + if (err == -ENOSYS) + { + if (in_time_t_range (reltime->tv_sec)) + { + struct timespec ts32 = valid_timespec64_to_timespec (*reltime); + + err = INTERNAL_SYSCALL_CANCEL (futex, futex_word, + __lll_private_flag (FUTEX_WAIT, + private), + expected, &ts32); + } + else + err = -EOVERFLOW; + } +#endif + switch (err) + { + case 0: + case -EAGAIN: + case -EINTR: + case -ETIMEDOUT: + case -EOVERFLOW: /* Passed relative timeout uses 64 bit time_t type, but + underlying kernel does not support 64 bit time_t futex + syscalls. */ + return -err; + + case -EFAULT: /* Must have been caused by a glibc or application bug. */ + case -EINVAL: /* Either due to wrong alignment or due to the timeout not + being normalized. Must have been caused by a glibc or + application bug. */ + case -ENOSYS: /* Must have been caused by a glibc bug. */ + /* No other errors are documented at this time. */ + default: + futex_fatal_error (); + } +} + #endif /* futex-internal.h */ diff --git a/sysdeps/pthread/aio_suspend.c b/sysdeps/pthread/aio_suspend.c index ad03f13558..eebe10536e 100644 --- a/sysdeps/pthread/aio_suspend.c +++ b/sysdeps/pthread/aio_suspend.c @@ -94,7 +94,7 @@ cleanup (void *arg) #ifdef DONT_NEED_AIO_MISC_COND static int __attribute__ ((noinline)) -do_aio_misc_wait (unsigned int *cntr, const struct timespec *timeout) +do_aio_misc_wait (unsigned int *cntr, const struct __timespec64 *timeout) { int result = 0; @@ -105,8 +105,8 @@ do_aio_misc_wait (unsigned int *cntr, const struct timespec *timeout) #endif int -aio_suspend (const struct aiocb *const list[], int nent, - const struct timespec *timeout) +__aio_suspend_common64 (const struct aiocb *const list[], int nent, + const struct __timespec64 *timeout) { if (__glibc_unlikely (nent < 0)) { @@ -183,6 +183,14 @@ aio_suspend (const struct aiocb *const list[], int nent, { /* We have to convert the relative timeout value into an absolute time value with pthread_cond_timedwait expects. */ + /* Y2038: The below code is used by ports which do NOT + #define DONT_NEED_AIO_MISC_COND flag (e.g. i686-gnu) + Ports which define it use futex syscalls supporting 64 bit + time. As a result below code don't need to be adjusted to + support 64 bit time as it is advised to either add support + for DONT_NEED_AIO_MISC_COND flag or provide + __pthread_cond_timedwait64() implementation and use struct + __timespec64 and __clock_gettime64(). */ struct timespec now; struct timespec abstime; @@ -250,4 +258,29 @@ aio_suspend (const struct aiocb *const list[], int nent, return result; } +int +__aio_suspend_time64 (const struct aiocb *const list[], int nent, + const struct __timespec64 *timeout) +{ + return __aio_suspend_common64 (list, nent, timeout); +} + +#if __TIMESIZE != 64 +librt_hidden_def (__aio_suspend_time64) + +int +__aio_suspend(const struct aiocb *const list[], int nent, + const struct timespec *timeout) +{ + struct __timespec64 ts64; + + if (timeout != NULL) + { + ts64 = valid_timespec_to_timespec64 (*timeout); + } + + return __aio_suspend_time64 (list, nent, timeout != NULL ? &ts64 : NULL); +} +#endif +weak_alias (__aio_suspend, aio_suspend) weak_alias (aio_suspend, aio_suspend64)