From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by sourceware.org (Postfix) with ESMTPS id 44F3F388A41A for ; Mon, 21 Jun 2021 07:44:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 44F3F388A41A 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 343FE828BC; Mon, 21 Jun 2021 09:44:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1624261440; bh=uQy1fqrWFf3LGKDBwnJa4aiL7xmkKLLfGWDVH8MTqrg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NJgEuXLIzjCMfgPGbdqZfjcSrKFJGVGbDb5H5zLoK4/Xzq+YdMtPcUOJallvgNu9M PobRSRXk5YyRuLBdu0Vl/7lrui4hOPobWsHFsdCeGvq33gftkMqjf8SuPuGP8YfODY cd9Aw3im15s1LuO2ejoZEfKi7t/Cl/pG35LegL7TlrMkq/FoLdnkL0qmHsLRrh1APT bMzRfxcPbrfj4d0/eiXdA8hGyThTXP9r8gyzeO2C8J+wug1P4IP++vsZhvp5JkZR37 WKnlF2i1NGw4ems5bvWGyr8HVzFqXvGdDWTG+kBi0DMB/nbF1Q95Q9vWynUbGFcZw4 2Caop8Xm5sqyw== Date: Mon, 21 Jun 2021 09:43:59 +0200 From: Lukasz Majewski To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, Carlos O'Donell Subject: Re: [PATCH 11/18] linux: Only use 64-bit syscall if required for semtimedop Message-ID: <20210621094359.3b89871b@ktm> In-Reply-To: <20210617115104.1359598-12-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> <20210617115104.1359598-12-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_/a8sQ42NwzeENgU3G3qbJ5xg"; 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.7 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:44:03 -0000 --Sig_/a8sQ42NwzeENgU3G3qbJ5xg Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Thu, 17 Jun 2021 08:50:57 -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. >=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. > --- > sysdeps/unix/sysv/linux/semtimedop.c | 54 > ++++++++++++++++------------ sysvipc/Makefile | > 9 +++++ sysvipc/test-sysvsem.c | 22 +++++++++--- > 3 files changed, 57 insertions(+), 28 deletions(-) >=20 > diff --git a/sysdeps/unix/sysv/linux/semtimedop.c > b/sysdeps/unix/sysv/linux/semtimedop.c index b732b6db48..65a8c080f7 > 100644 --- a/sysdeps/unix/sysv/linux/semtimedop.c > +++ b/sysdeps/unix/sysv/linux/semtimedop.c > @@ -21,44 +21,52 @@ > #include > #include > =20 > +static int > +semtimedop_syscall (int semid, struct sembuf *sops, size_t nsops, > + const struct __timespec64 *timeout) > +{ > +#ifdef __NR_semtimedop_time64 > + return INLINE_SYSCALL_CALL (semtimedop_time64, semid, sops, nsops, > timeout); +#elif defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS && defined > __NR_semtimedop > + return INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, > timeout); +#else > + return INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, > + SEMTIMEDOP_IPC_ARGS (nsops, sops, > timeout)); +#endif > +} > + > /* Perform user-defined atomical operation of array of semaphores. > */ int > __semtimedop64 (int semid, struct sembuf *sops, size_t nsops, > const struct __timespec64 *timeout) > { > - int r; > -#if defined __NR_semtimedop_time64 > - r =3D INLINE_SYSCALL_CALL (semtimedop_time64, semid, sops, nsops, > timeout); -#elif defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS && defined > __NR_semtimedop > - r =3D INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, timeout); > +#ifdef __ASSUME_TIME64_SYSCALLS > + return semtimedop_syscall (semid, sops, nsops, timeout); > #else > - r =3D INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, > - SEMTIMEDOP_IPC_ARGS (nsops, sops, > timeout)); -#endif > - > -#ifndef __ASSUME_TIME64_SYSCALLS > - if (r =3D=3D 0 || errno !=3D ENOSYS) > - return r; > + bool is32bit =3D timeout !=3D NULL > + ? in_time_t_range (timeout->tv_sec) : true; > + if (!is32bit) > + { > + int r =3D semtimedop_syscall (semid, sops, nsops, timeout); > + if (r =3D=3D 0 || errno !=3D ENOSYS) > + return r; > + __set_errno (EOVERFLOW); > + return -1; > + } > =20 > 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; > } > -# if defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS > - r =3D INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, pts32); > +# ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS > + return INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, pts32); > # else > - r =3D INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, > - SEMTIMEDOP_IPC_ARGS (nsops, sops, pts32)); > + return INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, > + SEMTIMEDOP_IPC_ARGS (nsops, sops, > pts32)); # endif > -#endif /* __ASSUME_TIME64_SYSCALLS */ > - return r; > +#endif > } > #if __TIMESIZE !=3D 64 > libc_hidden_def (__semtimedop64) > diff --git a/sysvipc/Makefile b/sysvipc/Makefile > index 86911803b5..d2acb6a70b 100644 > --- a/sysvipc/Makefile > +++ b/sysvipc/Makefile > @@ -38,3 +38,12 @@ include ../Rules > =20 > CFLAGS-msgrcv.c +=3D -fexceptions -fasynchronous-unwind-tables > CFLAGS-msgsnd.c +=3D -fexceptions -fasynchronous-unwind-tables > + > +ifeq (yes,$(build-shared)) > +librt =3D $(common-objpfx)rt/librt.so > +else > +librt =3D $(common-objpfx)rt/librt.a > +endif > + > +$(objpfx)test-sysvsem: $(librt) > +$(objpfx)test-sysvsem-time64: $(librt) > diff --git a/sysvipc/test-sysvsem.c b/sysvipc/test-sysvsem.c > index 092418205d..d9034c3dae 100644 > --- a/sysvipc/test-sysvsem.c > +++ b/sysvipc/test-sysvsem.c > @@ -16,6 +16,7 @@ > License along with the GNU C Library; if not, see > . */ > =20 > +#include > #include > #include > #include > @@ -30,6 +31,8 @@ > #include > #include > #include > +#include > +#include > =20 > /* These are for the temporary file we generate. */ > static char *name; > @@ -112,11 +115,20 @@ do_test (void) > #ifdef _GNU_SOURCE > /* Set a time for half a second. The semaphore operation should > timeout with EAGAIN. */ > - struct timespec ts =3D { 0 /* sec */, 500000000 /* nsec */ }; > - if (semtimedop (semid, &sb2, 1, &ts) !=3D -1 > - || (errno !=3D EAGAIN && errno !=3D ENOSYS)) > - FAIL_EXIT1 ("semtimedop succeed or returned errno !=3D > {EAGAIN,ENOSYS} " > - "(errno=3D%i)", errno); > + { > + struct timespec ts =3D { 0 /* sec */, 500000000 /* nsec */ }; > + if (semtimedop (semid, &sb2, 1, &ts) !=3D -1 > + || (errno !=3D EAGAIN && errno !=3D ENOSYS)) > + FAIL_EXIT1 ("semtimedop succeed or returned errno !=3D > {EAGAIN,ENOSYS} " > + "(errno=3D%i)", errno); > + } > + > + { > + support_create_timer (0, 100000000, false, NULL); > + struct timespec ts =3D { TYPE_MAXIMUM (time_t), 0 }; > + TEST_COMPARE (semtimedop (semid, &sb2, 1, &ts), -1); > + TEST_VERIFY (errno =3D=3D EINTR || errno =3D=3D EOVERFLOW); > + } > #endif > =20 > /* Finally free up the semnaphore resource. */ 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_/a8sQ42NwzeENgU3G3qbJ5xg Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEgAyFJ+N6uu6+XupJAR8vZIA0zr0FAmDQQz8ACgkQAR8vZIA0 zr27JggAothCKGmTsGMAqMjfvjPnrqnu0acuGwFR3DiCQD8hLKyOMsakMSfQs/lU PwltKMDrHN8nuAXRvEshxJH0GTGqJD0rXCUB2xununTFDTQYlr8tOACTM+KI6hPE b8u5+pb4bmlc6JQHrxZAfBYgnX1OJDUz1Untb04lTw8tCtfepf9G4D4lAUbDV7PH bO2/4nkP3ChXO+QH7xPD6rgXqv65E+kwSXcWYXB1X0dI3jTkUgsCm8a4KqUBg2T5 OU62BY6prmXvmY9NNt0gHiCoB+7JudX557LaH+1vIRvj+LzEa5oQxN05Xq3cGZlb mT5Ers07E5Zqj6kB58ZTOmyEFpD4yg== =e+HP -----END PGP SIGNATURE----- --Sig_/a8sQ42NwzeENgU3G3qbJ5xg--