From patchwork Fri Apr 9 15:53:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42937 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E0DC398EC05; Fri, 9 Apr 2021 15:53:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E0DC398EC05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617983635; bh=hyQ5knVSBCt2m0RZ+9y43uvM2jIJrNf/R1oUS9Xtqmc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bDvOo67MEl8XGGVmJiIC0DGTt9XXi4/ddxiWzS+7jFayeVAcp3gQtStFTx6MmQg9i Zse6UFnb75yqpd2zSYzE0Tr+Hz51XLAnlIL7uzt7o1mcq6VUGw9VWOWBW2gUiB/D4q wn3J8+wQoszzOW59eiP4amwlOt5WSD1udFsyvYEI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by sourceware.org (Postfix) with ESMTPS id EC139385DC14 for ; Fri, 9 Apr 2021 15:53:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EC139385DC14 Received: by mail-qt1-x82c.google.com with SMTP id g24so4503744qts.6 for ; Fri, 09 Apr 2021 08:53:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=hyQ5knVSBCt2m0RZ+9y43uvM2jIJrNf/R1oUS9Xtqmc=; b=ZvLnF3EAMg075QMUP/BvMapCjQSZPn28pFicDtpIJ66/HZ6qJ6jVIYkh7WmmcDn42R MC7PDWmqVOoXzF0+hsmruvw9zYn/23cAhpPWVGpSIVs7XO+K6I3UL1BkERgKHt9l69rg gW5tNM0gEL9m/W31qaylfx5v8+Us/hDAwqn724J4HqlLh9OeKTcexOaweheZU7MMbrOB 1TcyV2ULXIMqH+WhfxOOUXickrfeifbw828BY0zbN8jVta551vHL7Y8mD2fRp4h7oRDm e5hUdSl58rBtmE/XGNX182e9tP2Hf9pr82bvxyKoQCRep2GxJ2RSivnUf37MonxTRFB/ ZoIg== X-Gm-Message-State: AOAM533kg/EDHCj4e3dGy89Xq/U7GHQ9b6O90cZAX2cHV16oWk2TP7CY pvEvbgQidt2QgAIcFSYPPxKoU0CCwHqk8ZlY X-Google-Smtp-Source: ABdhPJz/1ndH0ii2EpATIm9CED3JnV3RTR2xOMrgkaZBVKbNhSB4z+3zadWwmJHbAHlIvf1I/pyGQQ== X-Received: by 2002:ac8:d0b:: with SMTP id q11mr12962777qti.353.1617983631162; Fri, 09 Apr 2021 08:53:51 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id 79sm2087632qki.37.2021.04.09.08.53.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 08:53:50 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 1/4] libsupport: Add support_select_modifies_timeout Date: Fri, 9 Apr 2021 12:53:43 -0300 Message-Id: <20210409155346.1357023-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It will be used on a select() test. --- support/Makefile | 1 + support/support.h | 4 ++++ support/support_select_modifies_timeout.c | 29 +++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 support/support_select_modifies_timeout.c diff --git a/support/Makefile b/support/Makefile index 900e17f94f..91457d8613 100644 --- a/support/Makefile +++ b/support/Makefile @@ -68,6 +68,7 @@ libsupport-routines = \ support_quote_string \ support_record_failure \ support_run_diff \ + support_select_modifies_timeout \ support_set_small_thread_stack_size \ support_shared_allocate \ support_small_stack_thread_attribute \ diff --git a/support/support.h b/support/support.h index e023d00857..f730611841 100644 --- a/support/support.h +++ b/support/support.h @@ -144,6 +144,10 @@ static __inline bool support_path_support_time64 (const char *path) /* Return true if stat supports nanoseconds resolution. */ extern bool support_stat_nanoseconds (const char *path); +/* Return true if select modify the timeout to reflect the amount of time + no slept. */ +extern bool support_select_modifies_timeout (void); + __END_DECLS #endif /* SUPPORT_H */ diff --git a/support/support_select_modifies_timeout.c b/support/support_select_modifies_timeout.c new file mode 100644 index 0000000000..a4f3bf145c --- /dev/null +++ b/support/support_select_modifies_timeout.c @@ -0,0 +1,29 @@ +/* Return whether select modify the timeout. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +bool +support_select_modifies_timeout (void) +{ +#ifdef __linux__ + return true; +#else + return false; +#endif +} From patchwork Fri Apr 9 15:53:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42938 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A241399C02A; Fri, 9 Apr 2021 15:53:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A241399C02A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617983635; bh=tiWdFgHO3PMVgIssnSKnWz4ET9gGdjtLP4u5/9EpEWk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=gbDhEZC1z5Hvuyd8CHkDPjxTs7qgMvrGDkGenwVlyjKwg6vln4/GjbipfpS6UkkJH MOglpcauQLPsRQsNy5YvYKMNgKu9zh68AYUvJoqZZnw1JTU+hv0Xy8BOJ9GwuW4Drk H7VGr9o9w53qv2OVZJ8nzd6M42YvVNPZQH/hUOkA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by sourceware.org (Postfix) with ESMTPS id E17A3398EC05 for ; Fri, 9 Apr 2021 15:53:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E17A3398EC05 Received: by mail-qt1-x833.google.com with SMTP id c6so4522198qtc.1 for ; Fri, 09 Apr 2021 08:53:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tiWdFgHO3PMVgIssnSKnWz4ET9gGdjtLP4u5/9EpEWk=; b=HdNda+MQ5FfrIqruLhyJ6BaAg4Tjwx/1rJpUlzgmPz7vPphhReupETVNyfMTOJW5oN sQFgxUrVtBOgqbrAdUdMb1T3vlsLkF7MmDvFTUWOVk51fdVq9vu30xhkc486s8Jkrnzh Jd7ZMyyg7EVysItG8OgeNrvTlE2kr8lSpBJ5TBu2ZR2+IzJN/jyXNxsO8nPguPvRCj9Q vypGX2bsT+PcKDXp9FKDXsGdVloonrxIkhbw87r9rpyl4B3kN5mjkByo+ipsBVsbivNJ Ye2sfJr/ixxO2ribG7sIR74z3Zjr/hZj5nB+YctUa0Q27vu07zQd3n+/9UOAbu97RWUk /oTg== X-Gm-Message-State: AOAM532msmGsCNm2u8LlkGkw2AHFserzor35A5BadPrs7C0fAi6gJgyL gqq4NUEN7+Cj6uxPXQ6MHNF74Frv3qLRnEgr X-Google-Smtp-Source: ABdhPJx+qPOkb2qBn3rFi8w2MM9G6cL2aB5oF8wY9g8mZytCV/voT4Q4DMDVnRbSidPTFzJmbOXDqw== X-Received: by 2002:ac8:7776:: with SMTP id h22mr13693513qtu.325.1617983632326; Fri, 09 Apr 2021 08:53:52 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id 79sm2087632qki.37.2021.04.09.08.53.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 08:53:52 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 2/4] libsupport: Add support_select_normalizes_timeout Date: Fri, 9 Apr 2021 12:53:44 -0300 Message-Id: <20210409155346.1357023-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210409155346.1357023-1-adhemerval.zanella@linaro.org> References: <20210409155346.1357023-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It will be used on a select() test. --- support/Makefile | 1 + support/support.h | 4 +++ support/support_select_normalizes_timeout.c | 29 +++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 support/support_select_normalizes_timeout.c diff --git a/support/Makefile b/support/Makefile index 91457d8613..da6dc58d37 100644 --- a/support/Makefile +++ b/support/Makefile @@ -69,6 +69,7 @@ libsupport-routines = \ support_record_failure \ support_run_diff \ support_select_modifies_timeout \ + support_select_normalizes_timeout \ support_set_small_thread_stack_size \ support_shared_allocate \ support_small_stack_thread_attribute \ diff --git a/support/support.h b/support/support.h index f730611841..db264e3db7 100644 --- a/support/support.h +++ b/support/support.h @@ -148,6 +148,10 @@ extern bool support_stat_nanoseconds (const char *path); no slept. */ extern bool support_select_modifies_timeout (void); +/* Return true if select normalize the timeout input by taking in account + tv_usec larger than 1000000. */ +extern bool support_select_normalizes_timeout (void); + __END_DECLS #endif /* SUPPORT_H */ diff --git a/support/support_select_normalizes_timeout.c b/support/support_select_normalizes_timeout.c new file mode 100644 index 0000000000..5dcf5dcbfc --- /dev/null +++ b/support/support_select_normalizes_timeout.c @@ -0,0 +1,29 @@ +/* Return whether select normalizes the timeout. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +bool +support_select_normalizes_timeout (void) +{ +#ifdef __linux__ + return true; +#else + return false; +#endif +} From patchwork Fri Apr 9 15:53:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42939 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2609839960F8; Fri, 9 Apr 2021 15:53:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2609839960F8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617983637; bh=OIk1v3yOyePtKv2ZumNepNCj1LQkffet3mVC64HcMBI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=d56U8HYvxOI1fHMs8evpWIMRvR3zJMB33PM0ko9hpl/CECQ5iY+yYlqzouLepnztf 9q3RPVWPw2WBIILVGAH1IxF5BlLd+BJs9nfQ5U9n7viJ56eeCdj53Jdg7DJREMxEqh xxrbZVcjBCFsW2diIy+sslJuwF2ZsKUkJe+B/BTg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by sourceware.org (Postfix) with ESMTPS id 3E03B39960E5 for ; Fri, 9 Apr 2021 15:53:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3E03B39960E5 Received: by mail-qk1-x72c.google.com with SMTP id z10so6237992qkz.13 for ; Fri, 09 Apr 2021 08:53:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OIk1v3yOyePtKv2ZumNepNCj1LQkffet3mVC64HcMBI=; b=DH2NUovdPQnO9Et2sbnYLsvHv3VDpRz6uRsKVyYCaxcex0hSmJfRKZejtj7E+Bbo+M aImcRiBmm5xX2RQhJGihgQJsRrXR9bP6RisgN6dlU6uHAdg97gQ8Ib0jKzVrL3ze+PRu MWKESzVh/o2HXj24U5mYPgRyCHYYErxrZkBgKXoYNWJv1b6RS+BLMfu15RDwjkqu9dau aE3GWYCZkxfd7nz1ZT+FBMhB7bcKLT2EMjDV7Ap1b2BzS+yFaWwfYCLTEAAcQVKLwuzz GcgYceKMKRK6KTZGHpe+X2XaBbGL6hOJs3nPccrNKSjts+v5++1r+3AXOfBXIP5f0iTH cXGw== X-Gm-Message-State: AOAM533Dce0W/CmwGx8hPtCSZlNkoDqgF3w9EOUi/fqFi79oJAaCsiq7 MjrnMC25erVfBKKGYdLePpcFseHmFMfkkCjz X-Google-Smtp-Source: ABdhPJwNSxubVfd7cDdxS+5eeC2BhpdmMLmXSGCvygwSLCi1Lw8Ltlnnp4xYEAV5deO/zuxfeTWqKA== X-Received: by 2002:a05:620a:110a:: with SMTP id o10mr14984386qkk.281.1617983633462; Fri, 09 Apr 2021 08:53:53 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id 79sm2087632qki.37.2021.04.09.08.53.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 08:53:53 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 3/4] linux: Normalize and return timeout on select (BZ #27651) Date: Fri, 9 Apr 2021 12:53:45 -0300 Message-Id: <20210409155346.1357023-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210409155346.1357023-1-adhemerval.zanella@linaro.org> References: <20210409155346.1357023-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The commit 2433d39b697, which added time64 support to select, changed the function to use __NR_pselect6 (or __NR_pelect6_time64) on all architectures. However, on architectures where the symbol was implemented with __NR_select the kernel normalizes the passed timeout instead of return EINVAL. For instance, the input timeval { 0, 5000000 } is interpreted as { 5, 0 }. And as indicated by BZ #27651, this semantic seems to be expected and changing it results in some performance issues (most likely the program does not check the return code and keeps issuing select with unormalized tv_usec argument). To avoid a different semantic depending whether which syscall the architecture used to issue, select now always normalize the timeout input. This is a slight change for some ABIs (for instance aarch64). Checked on x86_64-linux-gnu and i686-linux-gnu. --- include/time.h | 5 ++++ misc/tst-select.c | 17 ++++++++++++ sunrpc/svcauth_des.c | 1 - sysdeps/unix/sysv/linux/select.c | 44 +++++++++++++++++++++++++------- 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/include/time.h b/include/time.h index caf2af5e74..e0636132a6 100644 --- a/include/time.h +++ b/include/time.h @@ -502,6 +502,11 @@ time_now (void) __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts); return ts.tv_sec; } + +#define NSEC_PER_SEC 1000000000L /* Nanoseconds per second. */ +#define USEC_PER_SEC 1000000L /* Microseconds per second. */ +#define NSEC_PER_USEC 1000L /* Nanoseconds per microsecond. */ + #endif #endif diff --git a/misc/tst-select.c b/misc/tst-select.c index 5ad057cd51..534105b500 100644 --- a/misc/tst-select.c +++ b/misc/tst-select.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,12 @@ do_test_child (void *clousure) int r = select (args->fds[0][0] + 1, &rfds, NULL, NULL, &args->tmo); TEST_COMPARE (r, 0); + if (support_select_modifies_timeout ()) + { + TEST_COMPARE (args->tmo.tv_sec, 0); + TEST_COMPARE (args->tmo.tv_usec, 0); + } + TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts); xwrite (args->fds[1][1], "foo", 3); @@ -69,6 +76,16 @@ do_test (void) sc_allow_none); } + if (support_select_normalizes_timeout ()) + { + /* This is handled as 1 second instead of failing with EINVAL. */ + args.tmo = (struct timeval) { .tv_sec = 0, .tv_usec = 1000000 }; + struct support_capture_subprocess result; + result = support_capture_subprocess (do_test_child, &args); + support_capture_subprocess_check (&result, "tst-select-child", 0, + sc_allow_none); + } + /* Same as before, but simulating polling. */ args.tmo = (struct timeval) { .tv_sec = 0, .tv_usec = 0 }; { diff --git a/sunrpc/svcauth_des.c b/sunrpc/svcauth_des.c index 7607abc818..25a85c9097 100644 --- a/sunrpc/svcauth_des.c +++ b/sunrpc/svcauth_des.c @@ -58,7 +58,6 @@ #define debug(msg) /*printf("svcauth_des: %s\n", msg) */ -#define USEC_PER_SEC ((uint32_t) 1000000L) #define BEFORE(t1, t2) timercmp(t1, t2, <) /* diff --git a/sysdeps/unix/sysv/linux/select.c b/sysdeps/unix/sysv/linux/select.c index 415aa87d3c..8deab751c0 100644 --- a/sysdeps/unix/sysv/linux/select.c +++ b/sysdeps/unix/sysv/linux/select.c @@ -33,12 +33,34 @@ int __select64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct __timeval64 *timeout) { - struct __timespec64 ts64, *pts64 = NULL; - if (timeout != NULL) + __time64_t s = timeout != NULL ? timeout->tv_sec : 0; + int32_t us = timeout != NULL ? timeout->tv_usec : 0; + int32_t ns; + + if (s < 0 || us < 0) + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); + + /* Normalize the timeout, as legacy Linux __NR_select and __NR__newselect. + Different than syscall, it also handle possible overflow. */ + if (us / USEC_PER_SEC > INT64_MAX - s) { - ts64 = timeval64_to_timespec64 (*timeout); - pts64 = &ts64; + s = INT64_MAX; + ns = NSEC_PER_SEC - 1; } + else + { + s += us / USEC_PER_SEC; + us = us % USEC_PER_SEC; + ns = us * NSEC_PER_USEC; + } + + struct __timespec64 ts64, *pts64 = NULL; + if (timeout != NULL) + { + ts64.tv_sec = s; + ts64.tv_nsec = ns; + pts64 = &ts64; + } #ifndef __NR_pselect6_time64 # define __NR_pselect6_time64 __NR_pselect6 @@ -52,10 +74,13 @@ __select64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, (though the pselect() glibc call suppresses this behavior). Since select() on Linux has the same behavior as the pselect6 syscall, we update the timeout here. */ - if (r == 0 || errno != ENOSYS) + if (r >= 0 || errno != ENOSYS) { if (timeout != NULL) - TIMEVAL_TO_TIMESPEC (timeout, &ts64); + { + timeout->tv_sec = ts64.tv_sec; + timeout->tv_usec = ts64.tv_nsec / NSEC_PER_USEC; + } return r; } @@ -64,14 +89,15 @@ __select64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, #ifndef __ASSUME_TIME64_SYSCALLS struct timespec ts32, *pts32 = NULL; - if (timeout != NULL) + if (pts64 != NULL) { - if (! in_time_t_range (timeout->tv_sec)) + if (! in_time_t_range (pts64->tv_sec)) { __set_errno (EINVAL); return -1; } - ts32 = valid_timespec64_to_timespec (ts64); + ts32.tv_sec = s; + ts32.tv_nsec = ns; pts32 = &ts32; } # ifndef __ASSUME_PSELECT From patchwork Fri Apr 9 15:53:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42940 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD98A399C035; Fri, 9 Apr 2021 15:53:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD98A399C035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617983637; bh=mjXRdJtqYUalSFbQkUKRI1hjDkTtjA3hTr6JM/TjKuY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=orQ9vGHc2ql0H68W+dS3XeewRNXI2fM4jxmim7EMiYpRJF5VH7o38T/vtjXqkdZD2 5ylvyvFufaVyTDubthnFfEPiiAaCD5p4Ly0zRAmjBKswjtokRKboYkOSfByN1hTh0/ tXxy6z+U1D2NWeoiFqfXf0YSuSSLAt6i7S336pJc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by sourceware.org (Postfix) with ESMTPS id 2BBAD399C015 for ; Fri, 9 Apr 2021 15:53:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2BBAD399C015 Received: by mail-qt1-x830.google.com with SMTP id g24so4503879qts.6 for ; Fri, 09 Apr 2021 08:53:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mjXRdJtqYUalSFbQkUKRI1hjDkTtjA3hTr6JM/TjKuY=; b=nzeslktFMD+M30H05T4B8cWtWf8PvNlD7bLY72nQ003HFdJ0kv42cIi8qa8wha37D2 5ypSJBO2dlM/a/io5d0DDDIEB1yPOkst/ViSSzQtCSEA90upiC1wHn9faSh3Hmcankf/ erll08FofeOiFMOCqODKxobrxqNZO+ArFjnIpxQ4/6DVbcAjmmX4fcQfjeS2orLeykFO 5aKRnsU1VRAkoBePt3fakjJmclFJ3JO6GU2pUUp46/ntlwf4ZGt/C+FoZb1cPKhtAq/0 0LZyGF/3WjiqUIETBP+YXU7F2S3aUS671ongUzzr6nTTcn5LeTXuIFAuKfxyoX+GjJHY ceEQ== X-Gm-Message-State: AOAM533/LwdTsxsEHXZt10Dm2dM/jFR6dnyPdeszkEYPcvZ60ULIb0Ow tlDNJ3MeXfJmUWbBNuY+Fx/ZVNG7w0LJ4lLy X-Google-Smtp-Source: ABdhPJy7Tc/jEKNKo3a9M414OMZE93GwmZALQkpMvhthqZaXoSMX2Pj2287/TpWQPHK6YcznpwgM2Q== X-Received: by 2002:aed:306c:: with SMTP id 99mr12912509qte.352.1617983634603; Fri, 09 Apr 2021 08:53:54 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id 79sm2087632qki.37.2021.04.09.08.53.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 08:53:54 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 4/4] linux: always update select timeout (BZ #27706) Date: Fri, 9 Apr 2021 12:53:46 -0300 Message-Id: <20210409155346.1357023-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210409155346.1357023-1-adhemerval.zanella@linaro.org> References: <20210409155346.1357023-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The timeout should be updated even on failure for time64 support. Checked on i686-linux-gnu. --- misc/tst-select.c | 30 ++++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/select.c | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/misc/tst-select.c b/misc/tst-select.c index 534105b500..52aa26651f 100644 --- a/misc/tst-select.c +++ b/misc/tst-select.c @@ -23,6 +23,7 @@ #include #include #include +#include struct child_args { @@ -30,6 +31,12 @@ struct child_args struct timeval tmo; }; +static void +alarm_handler (int signum) +{ + /* Do nothing. */ +} + static void do_test_child (void *clousure) { @@ -59,6 +66,22 @@ do_test_child (void *clousure) xwrite (args->fds[1][1], "foo", 3); } +static void +do_test_child_alarm (void *clousure) +{ + struct sigaction act = { .sa_handler = alarm_handler }; + xsigaction (SIGALRM, &act, NULL); + alarm (1); + + struct timeval tv = { .tv_sec = 10, .tv_usec = 0 }; + int r = select (0, NULL, NULL, NULL, &tv); + TEST_COMPARE (r, -1); + TEST_COMPARE (errno, EINTR); + + if (support_select_modifies_timeout ()) + TEST_VERIFY (tv.tv_sec < 10); +} + static int do_test (void) { @@ -98,6 +121,13 @@ do_test (void) xclose (args.fds[0][0]); xclose (args.fds[1][1]); + { + struct support_capture_subprocess result; + result = support_capture_subprocess (do_test_child_alarm, NULL); + support_capture_subprocess_check (&result, "tst-select-child", 0, + sc_allow_none); + } + { fd_set rfds; FD_ZERO (&rfds); diff --git a/sysdeps/unix/sysv/linux/select.c b/sysdeps/unix/sysv/linux/select.c index 8deab751c0..5d87a3d1f9 100644 --- a/sysdeps/unix/sysv/linux/select.c +++ b/sysdeps/unix/sysv/linux/select.c @@ -110,7 +110,7 @@ __select64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, r = SYSCALL_CANCEL (pselect6, nfds, readfds, writefds, exceptfds, pts32, NULL); # endif - if (r >= 0 && timeout != NULL) + if (timeout != NULL) *timeout = valid_timespec_to_timeval64 (ts32); #endif @@ -131,7 +131,7 @@ __select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, ptv64 = &tv64; } int r = __select64 (nfds, readfds, writefds, exceptfds, ptv64); - if (r >= 0 && timeout != NULL) + if (timeout != NULL) /* The remanining timeout will be always less the input TIMEOUT. */ *timeout = valid_timeval64_to_timeval (tv64); return r;