From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by sourceware.org (Postfix) with ESMTPS id 424B338930D8 for ; Mon, 21 Jun 2021 07:43:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 424B338930D8 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=denx.de Received: from ktm (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 0BA24801FD; Mon, 21 Jun 2021 09:42:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1624261379; bh=9Eoz1yifIZFdj+0KD4AUBF1FTuiXKfLh6YdHgIAsgo0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=eooAZtONlt3eWfIYRDNHgnXCuiGnF494d2CrdqYGYQcCdGPXtn9HPhOW+oAFb6HRG qf3h5Y4Do1sG1dsKxwIMe3psrEgQrrpl5ieJ5ca78YE0pjpjipTJ6UPB8LNq4zq1m3 1faMUFwzroQ9D22QJXX+UZY2lXZCand+oys5l7WR2VNbuycMSi8zJlUR/akgBtutB3 UMls6N8q6NgWaBykb4vS6M8y6EZCDDtiGGw0p6bs4Bbc31JBrqs5GV0JZ6jHiKper5 iIN2n2AeLkd5PGqyyrL8jFq9Jf9dhpbovqDCVXIOYjIxf/FUsueXzWZWvEakdRB6xt wrc4o+iqlqsXw== Date: Mon, 21 Jun 2021 09:42:58 +0200 From: Lukasz Majewski To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, Carlos O'Donell Subject: Re: [PATCH 05/18] linux: Only use 64-bit syscall if required for pselect Message-ID: <20210621094258.373528a3@ktm> In-Reply-To: <20210617115104.1359598-6-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> <20210617115104.1359598-6-adhemerval.zanella@linaro.org> Organization: denx.de X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/6BZ1nvdLYZRSMLtP7ILB84z"; protocol="application/pgp-signature" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_NONE, SPF_PASS, 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: Mon, 21 Jun 2021 07:43:02 -0000 --Sig_/6BZ1nvdLYZRSMLtP7ILB84z Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Thu, 17 Jun 2021 08:50:51 -0300 Adhemerval Zanella wrote: > For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit > syscall if the provided timeout fits in a 32-bit one. The 64-bit > usage should be rare since the timeout is a relative one. This also > avoids the need to use supports_time64() (which breaks the usage case > of live migration like CRIU or similar). >=20 > Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel > (with and without --enable-kernel=3D5.1) and on x86_64-linux-gnu. > --- > misc/Makefile | 9 ++ > misc/tst-pselect.c | 120 > ++++++++---------- .../unix/sysv/linux/microblaze/pselect32.c | > 3 +- sysdeps/unix/sysv/linux/pselect.c | 47 ++++--- > sysdeps/unix/sysv/linux/pselect32.c | 6 - > 5 files changed, 95 insertions(+), 90 deletions(-) >=20 > diff --git a/misc/Makefile b/misc/Makefile > index f34ab09fe3..fa40bf0e11 100644 > --- a/misc/Makefile > +++ b/misc/Makefile > @@ -148,6 +148,12 @@ CFLAGS-brk.op =3D $(no-stack-protector) > =20 > include ../Rules > =20 > +ifeq (yes,$(build-shared)) > +librt =3D $(common-objpfx)rt/librt.so > +else > +librt =3D $(common-objpfx)rt/librt.a > +endif > + > $(objpfx)libg.a: $(dep-dummy-lib); $(make-dummy-lib) > =20 > $(objpfx)tst-tsearch: $(libm) > @@ -162,3 +168,6 @@ tst-allocate_once-ENV =3D > MALLOC_TRACE=3D$(objpfx)tst-allocate_once.mtrace > $(objpfx)tst-allocate_once-mem.out: $(objpfx)tst-allocate_once.out > $(common-objpfx)malloc/mtrace $(objpfx)tst-allocate_once.mtrace > $@; > \ $(evaluate-test) + > +$(objpfx)tst-pselect: $(librt) > +$(objpfx)tst-pselect-time64: $(librt) > diff --git a/misc/tst-pselect.c b/misc/tst-pselect.c > index c89176b058..f8c404c275 100644 > --- a/misc/tst-pselect.c > +++ b/misc/tst-pselect.c > @@ -16,14 +16,14 @@ > . */ > =20 > #include > -#include > -#include > -#include > -#include > -#include > +#include > +#include > +#include > +#include > +#include > +#include > #include > =20 > - > static volatile int handler_called; > =20 > static void > @@ -33,59 +33,43 @@ handler (int sig) > } > =20 > =20 > -static int > -do_test (void) > +static void > +test_pselect_basic (void) > { > struct sigaction sa; > sa.sa_handler =3D handler; > sa.sa_flags =3D 0; > sigemptyset (&sa.sa_mask); > =20 > - if (sigaction (SIGUSR1, &sa, NULL) !=3D 0) > - { > - puts ("sigaction failed"); > - return 1; > - } > + xsigaction (SIGUSR1, &sa, NULL); > =20 > sa.sa_handler =3D SIG_IGN; > - if (sigaction (SIGCHLD, &sa, NULL) !=3D 0) > - { > - puts ("2nd sigaction failed"); > - return 1; > - } > + xsigaction (SIGCHLD, &sa, NULL); > =20 > sigset_t ss_usr1; > sigemptyset (&ss_usr1); > sigaddset (&ss_usr1, SIGUSR1); > - if (sigprocmask (SIG_BLOCK, &ss_usr1, NULL) !=3D 0) > - { > - puts ("sigprocmask failed"); > - return 1; > - } > + TEST_COMPARE (sigprocmask (SIG_BLOCK, &ss_usr1, NULL), 0); > =20 > int fds[2][2]; > - > - if (pipe (fds[0]) !=3D 0 || pipe (fds[1]) !=3D 0) > - { > - puts ("pipe failed"); > - return 1; > - } > + xpipe (fds[0]); > + xpipe (fds[1]); > =20 > fd_set rfds; > FD_ZERO (&rfds); > =20 > sigset_t ss; > - sigprocmask (SIG_SETMASK, NULL, &ss); > + TEST_COMPARE (sigprocmask (SIG_SETMASK, NULL, &ss), 0); > sigdelset (&ss, SIGUSR1); > =20 > struct timespec to =3D { .tv_sec =3D 0, .tv_nsec =3D 500000000 }; > =20 > pid_t parent =3D getpid (); > - pid_t p =3D fork (); > + pid_t p =3D xfork (); > if (p =3D=3D 0) > { > - close (fds[0][1]); > - close (fds[1][0]); > + xclose (fds[0][1]); > + xclose (fds[1][0]); > =20 > FD_SET (fds[0][0], &rfds); > =20 > @@ -93,55 +77,63 @@ do_test (void) > do > { > if (getppid () !=3D parent) > - exit (2); > + FAIL_EXIT1 ("getppid()=3D%d !=3D parent=3D%d", getppid(), > parent);=20 > errno =3D 0; > e =3D pselect (fds[0][0] + 1, &rfds, NULL, NULL, &to, &ss); > } > while (e =3D=3D 0); > =20 > - if (e !=3D -1) > - { > - puts ("child: pselect did not fail"); > - return 0; > - } > - if (errno !=3D EINTR) > - { > - puts ("child: pselect did not set errno to EINTR"); > - return 0; > - } > + TEST_COMPARE (e, -1); > + TEST_COMPARE (errno, EINTR); > =20 > TEMP_FAILURE_RETRY (write (fds[1][1], "foo", 3)); > =20 > exit (0); > } > =20 > - close (fds[0][0]); > - close (fds[1][1]); > + xclose (fds[0][0]); > + xclose (fds[1][1]); > =20 > FD_SET (fds[1][0], &rfds); > =20 > - kill (p, SIGUSR1); > + TEST_COMPARE (kill (p, SIGUSR1), 0); > =20 > int e =3D pselect (fds[1][0] + 1, &rfds, NULL, NULL, NULL, &ss); > - if (e =3D=3D -1) > - { > - puts ("parent: pselect failed"); > - return 1; > - } > - if (e !=3D 1) > - { > - puts ("parent: pselect did not report readable fd"); > - return 1; > - } > - if (!FD_ISSET (fds[1][0], &rfds)) > - { > - puts ("parent: pselect reports wrong fd"); > - return 1; > - } > + TEST_COMPARE (e, 1); > + TEST_VERIFY (FD_ISSET (fds[1][0], &rfds)); > +} > + > +static void > +test_pselect_large_timeout (void) > +{ > + support_create_timer (0, 100000000, false, NULL); > + > + int fds[2]; > + xpipe (fds); > + > + fd_set rfds; > + FD_ZERO (&rfds); > + FD_SET (fds[0], &rfds); > + > + sigset_t ss; > + TEST_COMPARE (sigprocmask (SIG_SETMASK, NULL, &ss), 0); > + sigdelset (&ss, SIGALRM); > + > + struct timespec ts =3D { TYPE_MAXIMUM (time_t), 0 }; > + > + TEST_COMPARE (pselect (fds[0] + 1, &rfds, NULL, NULL, &ts, &ss), > -1); > + TEST_VERIFY (errno =3D=3D EINTR || errno =3D=3D EOVERFLOW); > +} > + > +static int > +do_test (void) > +{ > + test_pselect_basic (); > + > + test_pselect_large_timeout (); > =20 > return 0; > } > =20 > -#define TEST_FUNCTION do_test () > -#include "../test-skeleton.c" > +#include > diff --git a/sysdeps/unix/sysv/linux/microblaze/pselect32.c > b/sysdeps/unix/sysv/linux/microblaze/pselect32.c index > a4f436462b..70b7b52a48 100644 --- > a/sysdeps/unix/sysv/linux/microblaze/pselect32.c +++ > b/sysdeps/unix/sysv/linux/microblaze/pselect32.c @@ -35,8 +35,7 @@ > __pselect32 (int nfds, fd_set *readfds, fd_set *writefds, struct > timeval tv32, *ptv32 =3D NULL; if (timeout !=3D NULL) > { > - if (! in_time_t_range (timeout->tv_sec) > - || ! valid_nanoseconds (timeout->tv_nsec)) > + if (! valid_nanoseconds (timeout->tv_nsec)) > { > __set_errno (EINVAL); > return -1; > diff --git a/sysdeps/unix/sysv/linux/pselect.c > b/sysdeps/unix/sysv/linux/pselect.c index 5e8a0cc2dc..79e8584ea7 > 100644 --- a/sysdeps/unix/sysv/linux/pselect.c > +++ b/sysdeps/unix/sysv/linux/pselect.c > @@ -18,7 +18,23 @@ > =20 > #include > #include > -#include > + > +static int > +pselect64_syscall (int nfds, fd_set *readfds, fd_set *writefds, > + fd_set *exceptfds, const struct __timespec64 > *timeout, > + const sigset_t *sigmask) > +{ > +#ifndef __NR_pselect6_time64 > +# define __NR_pselect6_time64 __NR_pselect6 > +#endif > + /* NB: This is required by ARGIFY used in x32 internal_syscallN. > */ > + __syscall_ulong_t data[2] =3D > + { > + (uintptr_t) sigmask, __NSIG_BYTES > + }; > + return SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds, > exceptfds, > + timeout, data); > +} > =20 > int > __pselect64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set > *exceptfds, @@ -37,30 +53,25 @@ __pselect64 (int nfds, fd_set > *readfds, fd_set *writefds, fd_set *exceptfds, we can only pass in 6 > directly. If there is an architecture with support for more > parameters a new version of this file needs to be created. */ > - > -#ifndef __NR_pselect6_time64 > -# define __NR_pselect6_time64 __NR_pselect6 > -#endif > +#ifdef __ASSUME_TIME64_SYSCALLS > + return pselect64_syscall (nfds, readfds, writefds, exceptfds, > timeout, > + sigmask); > +#else > + bool is32bit =3D timeout !=3D NULL > + ? in_time_t_range (timeout->tv_sec) : true; > int r; > - if (supports_time64 ()) > + if (!is32bit) > { > - /* NB: This is required by ARGIFY used in x32 > internal_syscallN. */ > - __syscall_ulong_t data[2] =3D > - { > - (uintptr_t) sigmask, __NSIG_BYTES > - }; > - r =3D SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds, > exceptfds, > - timeout, data); > + r =3D pselect64_syscall (nfds, readfds, writefds, exceptfds, > timeout, > + sigmask); > if (r =3D=3D 0 || errno !=3D ENOSYS) > return r; > - > - mark_time64_unsupported (); > + __set_errno (EOVERFLOW); > + return -1; > } > =20 > -#ifndef __ASSUME_TIME64_SYSCALLS > - r =3D __pselect32 (nfds, readfds, writefds, exceptfds, timeout, > sigmask); > + return __pselect32 (nfds, readfds, writefds, exceptfds, timeout, > sigmask); #endif > - return r; > } > =20 > #if __TIMESIZE !=3D 64 > diff --git a/sysdeps/unix/sysv/linux/pselect32.c > b/sysdeps/unix/sysv/linux/pselect32.c index eb59b51cdf..48724d8727 > 100644 --- a/sysdeps/unix/sysv/linux/pselect32.c > +++ b/sysdeps/unix/sysv/linux/pselect32.c > @@ -29,12 +29,6 @@ __pselect32 (int nfds, fd_set *readfds, fd_set > *writefds, struct timespec ts32, *pts32 =3D NULL; > if (timeout !=3D NULL) > { > - if (! in_time_t_range (timeout->tv_sec)) > - { > - __set_errno (EINVAL); > - return -1; > - } > - > ts32 =3D valid_timespec64_to_timespec (*timeout); > pts32 =3D &ts32; > } Reviewed-by: Lukasz Majewski 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_/6BZ1nvdLYZRSMLtP7ILB84z Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEgAyFJ+N6uu6+XupJAR8vZIA0zr0FAmDQQwIACgkQAR8vZIA0 zr2AzggArTRxbUYHa9KRbHcqH4IpiWAWVPhoT0/kspqijovfObLBvTjnHnTbg99H 9AfXCbrmuXfuiWpCDC/SqAX0J5lkcss+GWy32vwd/w6yPi1J0mkIHHdkYqPHT4WH Q3OptBUQYyX9TFR5IFcXrCSYq60jXr5gZBBcBya1HTSetXXooU3Pv8zwyw41ayDy c8zrmfXOXKx4vYibJagKOcdpdZ5CTfLsbccTaKoYJ1gHt2YhuuvbE/dztkG2Csif DXMg1J4vVG526GIXgAv9zmVqfi6+QiA4d/XUzTVXO2vuv7RYa/K7BagiFD5D6LOz AYKSBYWZUyky90y7feaDILIYb5QRjQ== =S7Av -----END PGP SIGNATURE----- --Sig_/6BZ1nvdLYZRSMLtP7ILB84z--