From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.9]) by sourceware.org (Postfix) with ESMTPS id 01E0F389244B for ; Fri, 24 Jul 2020 12:11:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 01E0F389244B 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 4BCp2x3GNtz1qs3C; Fri, 24 Jul 2020 14:11:37 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4BCp2x1mR6z1qtZY; Fri, 24 Jul 2020 14:11:37 +0200 (CEST) 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 aNC8RSHw3g-5; Fri, 24 Jul 2020 14:11:34 +0200 (CEST) X-Auth-Info: +aHJvIiop1zLKNhSjRGiKPJh4NIKmo/rP5NYcAfi1Ek= Received: from jawa (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (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; Fri, 24 Jul 2020 14:11:34 +0200 (CEST) Date: Fri, 24 Jul 2020 14:11:27 +0200 From: Lukasz Majewski To: Adhemerval Zanella Cc: Joseph Myers , Paul Eggert , Alistair Francis , Arnd Bergmann , Alistair Francis , GNU C Library , Florian Weimer , Carlos O'Donell , Stepan Golosunov , Andreas Schwab , Zack Weinberg Subject: Re: [PATCH v2] y2038: nptl: Convert pthread_{clock|timed}join_np to support 64 bit time Message-ID: <20200724141127.5c2881f9@jawa> In-Reply-To: References: <20200722073732.4071-1-lukma@denx.de> Organization: denx.de X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/GBSigHEgZIyEu=0.EjUh9Tg"; protocol="application/pgp-signature" X-Spam-Status: No, score=-17.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: , X-List-Received-Date: Fri, 24 Jul 2020 12:11:42 -0000 --Sig_/GBSigHEgZIyEu=0.EjUh9Tg Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hi Adhemerval, > On 22/07/2020 04:37, Lukasz Majewski wrote: > > The pthread_clockjoin_np and pthread_timedjoin_np have been > > converted to support 64 bit time. > >=20 > > This change introduces new futex_timed_wait_cancel64 function in > > ./sysdeps/nptl/futex-internal.h, which uses futex_time64 where > > possible and tries to replace low-level preprocessor macros from > > lowlevellock-futex.h > > The pthread_{timed|clock}join_np only accept absolute time. > > Moreover, there is no need to check for NULL passed as *abstime > > pointer as clockwait_tid() always passes struct __timespec64. > >=20 > > For systems with __TIMESIZE !=3D 64 && __WORDSIZE =3D=3D 32: > > - Conversions between 64 bit time to 32 bit are necessary > > - Redirection to __pthread_{clock|timed}join_np64 will provide > > support for 64 bit time > >=20 > > Build tests: > > ./src/scripts/build-many-glibcs.py glibcs > >=20 > > 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 > >=20 > > Above tests were performed with Y2038 redirection applied as well > > as without to test the proper usage of both > > __pthread_{timed|clock}join_np64 and __pthread_{timed|clock}join_np. > >=20 > > --- > > Changes for v2: > > - Update the commit message =20 >=20 > Some comments below regarding the futex-internal additions, the other > changes looks ok. >=20 > > --- > > nptl/pthreadP.h | 16 +++++++++++++++- > > nptl/pthread_clockjoin.c | 19 ++++++++++++++++--- > > nptl/pthread_join_common.c | 19 +++++++++++-------- > > nptl/pthread_timedjoin.c | 18 ++++++++++++++++-- > > sysdeps/nptl/futex-internal.h | 31 +++++++++++++++++++++++++++++++ > > 5 files changed, 89 insertions(+), 14 deletions(-) > >=20 > > diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h > > index 6f94d6be31..99713c8447 100644 > > --- a/nptl/pthreadP.h > > +++ b/nptl/pthreadP.h > > @@ -458,6 +458,20 @@ extern int __pthread_cond_init (pthread_cond_t > > *cond, libc_hidden_proto (__pthread_cond_init) > > extern int __pthread_cond_signal (pthread_cond_t *cond); > > extern int __pthread_cond_wait (pthread_cond_t *cond, > > pthread_mutex_t *mutex); + > > +#if __TIMESIZE =3D=3D 64 > > +# define __pthread_clockjoin_np64 __pthread_clockjoin_np > > +# define __pthread_timedjoin_np64 __pthread_timedjoin_np > > +#else > > +extern int __pthread_clockjoin_np64 (pthread_t threadid, void > > **thread_return, > > + clockid_t clockid, > > + const struct __timespec64 > > *abstime); +libc_hidden_proto (__pthread_clockjoin_np64) > > +extern int __pthread_timedjoin_np64 (pthread_t threadid, void > > **thread_return, > > + const struct __timespec64 > > *abstime); +libc_hidden_proto (__pthread_timedjoin_np64) > > +#endif > > + > > extern int __pthread_cond_timedwait (pthread_cond_t *cond, > > pthread_mutex_t *mutex, > > const struct timespec > > *abstime); @@ -488,7 +502,7 @@ extern int > > __pthread_enable_asynccancel (void) attribute_hidden; extern void > > __pthread_disable_asynccancel (int oldtype) attribute_hidden; > > extern void __pthread_testcancel (void); extern int > > __pthread_clockjoin_ex (pthread_t, void **, clockid_t, > > - const struct timespec *, bool) > > + const struct __timespec64 *, > > bool) attribute_hidden; > > extern int __pthread_sigmask (int, const sigset_t *, sigset_t *); > > libc_hidden_proto (__pthread_sigmask); =20 >=20 > Ok. >=20 > > diff --git a/nptl/pthread_clockjoin.c b/nptl/pthread_clockjoin.c > > index a3e7f37e3b..3cd780f688 100644 > > --- a/nptl/pthread_clockjoin.c > > +++ b/nptl/pthread_clockjoin.c > > @@ -16,14 +16,27 @@ > > License along with the GNU C Library; if not, see > > . */ > > =20 > > +#include > > #include "pthreadP.h" > > =20 > > int > > -__pthread_clockjoin_np (pthread_t threadid, void **thread_return, > > - clockid_t clockid, > > - const struct timespec *abstime) > > +__pthread_clockjoin_np64 (pthread_t threadid, void **thread_return, > > + clockid_t clockid, const struct > > __timespec64 *abstime) { > > return __pthread_clockjoin_ex (threadid, thread_return, > > clockid, abstime, true); > > } > > + > > +#if __TIMESIZE !=3D 64 > > +libc_hidden_def (__pthread_clockjoin_np64) > > + > > +int > > +__pthread_clockjoin_np (pthread_t threadid, void **thread_return, > > + clockid_t clockid, const struct timespec > > *abstime) +{ > > + struct __timespec64 ts64 =3D valid_timespec_to_timespec64 > > (*abstime); + > > + return __pthread_clockjoin_np64 (threadid, thread_return, > > clockid, &ts64); +} > > +#endif > > weak_alias (__pthread_clockjoin_np, pthread_clockjoin_np) =20 >=20 > Ok. >=20 > > diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c > > index a96ceafde4..67d8e2b780 100644 > > --- a/nptl/pthread_join_common.c > > +++ b/nptl/pthread_join_common.c > > @@ -20,6 +20,7 @@ > > #include > > #include > > #include > > +#include > > =20 > > static void > > cleanup (void *arg) > > @@ -37,9 +38,11 @@ cleanup (void *arg) > > afterwards. The kernel up to version 3.16.3 does not use the > > private futex operations for futex wake-up when the clone > > terminates. */ static int > > -clockwait_tid (pid_t *tidp, clockid_t clockid, const struct > > timespec *abstime) +clockwait_tid (pid_t *tidp, clockid_t clockid, > > + const struct __timespec64 *abstime) > > { > > pid_t tid; > > + int ret; > > =20 > > if (! valid_nanoseconds (abstime->tv_nsec)) > > return EINVAL; > > @@ -47,11 +50,11 @@ clockwait_tid (pid_t *tidp, clockid_t clockid, > > const struct timespec *abstime) /* Repeat until thread terminated. > > */ while ((tid =3D *tidp) !=3D 0) > > { > > - struct timespec rt; > > + struct __timespec64 rt; > > =20 > > /* Get the current time. This can only fail if clockid is > > invalid. */ > > - if (__glibc_unlikely (__clock_gettime (clockid, &rt))) > > + if (__glibc_unlikely (__clock_gettime64 (clockid, &rt))) > > return EINVAL; > > =20 > > /* Compute relative timeout. */ > > @@ -70,9 +73,9 @@ clockwait_tid (pid_t *tidp, clockid_t clockid, > > const struct timespec *abstime) /* If *tidp =3D=3D tid, wait until > > thread terminates or the wait times out. The kernel up to version > > 3.16.3 does not use the private futex operations for futex wake-up > > when the clone terminates. */ > > - if (lll_futex_timed_wait_cancel (tidp, tid, &rt, LLL_SHARED) > > - =3D=3D -ETIMEDOUT) > > - return ETIMEDOUT; > > + ret =3D futex_timed_wait_cancel64 (tidp, tid, &rt, LLL_SHARED); > > + if (ret =3D=3D -ETIMEDOUT || ret =3D=3D -EOVERFLOW) > > + return -ret; > > } > > =20 > > return 0; > > @@ -80,8 +83,8 @@ clockwait_tid (pid_t *tidp, clockid_t clockid, > > const struct timespec *abstime)=20 > > int > > __pthread_clockjoin_ex (pthread_t threadid, void **thread_return, > > - clockid_t clockid, > > - const struct timespec *abstime, bool block) > > + clockid_t clockid, > > + const struct __timespec64 *abstime, bool > > block) { > > struct pthread *pd =3D (struct pthread *) threadid; > > =20 >=20 > Ok, this is an internal interface so we free to change it. >=20 > > diff --git a/nptl/pthread_timedjoin.c b/nptl/pthread_timedjoin.c > > index dd7038dcf7..6164ae7060 100644 > > --- a/nptl/pthread_timedjoin.c > > +++ b/nptl/pthread_timedjoin.c > > @@ -16,13 +16,27 @@ > > License along with the GNU C Library; if not, see > > . */ > > =20 > > +#include > > #include "pthreadP.h" > > =20 > > int > > -__pthread_timedjoin_np (pthread_t threadid, void **thread_return, > > - const struct timespec *abstime) > > +__pthread_timedjoin_np64 (pthread_t threadid, void **thread_return, > > + const struct __timespec64 *abstime) > > { > > return __pthread_clockjoin_ex (threadid, thread_return, > > CLOCK_REALTIME, abstime, true); > > } > > + > > +#if __TIMESIZE !=3D 64 > > +libc_hidden_def (__pthread_timedjoin_np64) > > + > > +int > > +__pthread_timedjoin_np (pthread_t threadid, void **thread_return, > > + const struct timespec *abstime) > > +{ > > + struct __timespec64 ts64 =3D valid_timespec_to_timespec64 > > (*abstime); + > > + return __pthread_timedjoin_np64 (threadid, thread_return, &ts64); > > +} > > +#endif > > weak_alias (__pthread_timedjoin_np, pthread_timedjoin_np) =20 >=20 > Ok. >=20 > > diff --git a/sysdeps/nptl/futex-internal.h > > b/sysdeps/nptl/futex-internal.h index d622122ddc..e0a539ae9e 100644 > > --- a/sysdeps/nptl/futex-internal.h > > +++ b/sysdeps/nptl/futex-internal.h > > @@ -467,4 +467,35 @@ futex_unlock_pi (unsigned int *futex_word, int > > private) } > > } > > =20 > > +#ifndef __NR_futex_time64 > > +# define __NR_futex_time64 __NR_futex > > +#endif > > + > > +static __always_inline int > > +futex_timed_wait_cancel64 (pid_t *tidp, pid_t tid, > > + struct __timespec64 *timeout, int > > private) =20 >=20 > Should we set the timeout as 'const'? Afaik the kernel won't modify > its value. Yes, correct - the original pthread_timedjoin_np [1] passes the timeout (abstime) as const. >=20 > > +{ > > + int oldtype =3D CANCEL_ASYNC (); > > + long int ret =3D INTERNAL_SYSCALL (futex_time64, 4, tidp, > > + __lll_private_flag (FUTEX_WAIT, > > private), > > + tid, timeout); =20 >=20 I've followed the convention in the original code. > We have INTERNAL_SYSCALL_CALL, although I don't have a strong > preference here. It allows to not need to handle the reset state on > early return, as done in EOVERFLOW below. In any case use > INTERNAL_SYSCALL_CALL. That would look as: int oldtype =3D LIBC_CANCEL_ASYNC (); long int ret =3D INTERNAL_SYSCALL_CALL (futex_time64, tidp, ..... ); LIBC_CANCEL_RESET (oldtype); And then we could replace CANCEL_RESET() from [*]. (as similar approach is in futex_reltimed_wait_cancelable() function in the same file). > > +#ifndef __ASSUME_TIME64_SYSCALLS > > + if (ret =3D=3D -ENOSYS) > > + { > > + struct timespec ts32; > > + if (! in_time_t_range (timeout->tv_sec)) > > + { > > + CANCEL_RESET (oldtype); ^^^^^^^^^^^^ - [*] > > + return -EOVERFLOW; > > + } > > + ts32 =3D valid_timespec64_to_timespec (*timeout); > > + > > + ret =3D INTERNAL_SYSCALL (futex, 4, tidp, > > + __lll_private_flag (FUTEX_WAIT, > > private), > > + tid, &ts32); =20 >=20 > Use INTERNAL_SYCALL_CALL here. >=20 > > + } > > +#endif > > + CANCEL_RESET (oldtype); ^^^^^^^^^^^^ - [*] > > + return ret; > > +} > > #endif /* futex-internal.h */ > > =20 >=20 > I think we should follow the other futex_ routines regarding the > possible return values, i.e, document the possible return values and > explicit fail with futex_fatal_error for non expected ones. Ok. I will send v3 shortly. Links: [1] - https://linux.die.net/man/3/pthread_timedjoin_np Best regards, Lukasz Majewski -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de --Sig_/GBSigHEgZIyEu=0.EjUh9Tg Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEgAyFJ+N6uu6+XupJAR8vZIA0zr0FAl8az+8ACgkQAR8vZIA0 zr2zzAf/c/rsly5ZOJuJhdZsRW2FJn8bBpgBkQCpPrkdgn36/Y6ksMgAF6Pydq/+ CXVGbX8NfUB5k5PHCCP2gX0dIcUfBjk8ThHzqWoqw1ydOsQUY32XRfvzHu3ULnmB H2NfJDt5fZT0GW2tjt98WrKY48bnV6ns73emhwcT+jvZ/kdiWRZgnMuk9JgBv5Hh 0CB+e0IDKLtR+9RjYb20Z6IbCTwJHL/hrA7NODuKQlXpgYYt7KSnim0mUZFj/cEz 8WPjMZU2RfLwPhPmidPU394cI93oGiaJ158Q5876DY0rE0jofor4iwNCYLLJY16/ IaE3NIcvSWfHBdbnFPmZfvHEtvb/xw== =yhkk -----END PGP SIGNATURE----- --Sig_/GBSigHEgZIyEu=0.EjUh9Tg--