From patchwork Thu Jun 17 11:50:58 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: 43873 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 9A94B3894430 for ; Thu, 17 Jun 2021 12:01:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A94B3894430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931316; bh=3LhDGz8V3/hWP7tcUCOihH5aMt2hU+hMGHTPxACeSyc=; 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=yvq1+N2Jv3NZ3vK2BZY+etVp3jvXpnpmCsBB5Sw5QQV69YDSVVGvwJtoNiAR7FkLj BsnGfy8PLRISwRjGVKFec/Em5LOhkl8lEpgLq1fFzYb7lv6AsuLXkmVUXUGHBOIF3r mEXoggZ4PBMgBDuBXS/bpnU0iRxbPXPoO9ExAydk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 200E53890022 for ; Thu, 17 Jun 2021 11:51:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 200E53890022 Received: by mail-qk1-x730.google.com with SMTP id 5so2755023qkc.8 for ; Thu, 17 Jun 2021 04:51:30 -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=3LhDGz8V3/hWP7tcUCOihH5aMt2hU+hMGHTPxACeSyc=; b=BzjDbOV+X6GATsb21GGknxXQd+NbikyIA8RWjeILgea14BGSUqE5IO7uN8RTLXP5bG VOpLWoJdPseV23cGdYGfncdq9maJOmrnLPaMmRBNua4stpbwNsoBXntbB6Nqp4u/W6CL zczjSV3MQ1jSjmQmvWasxXpZjSjwSjZ6ERA6xXzptPTFs3/h+GwnFxpjWkoTIKYGaZCI phg34ZaoNFTkWYc4gEjeuLqVeRu3t5wxHuyP/KicLLoyOcqSffGS4/lBBEEv7/Vu1up5 lBweuSI4KrCib9l3u1ni5VOj/Kij02OK9x8SPU+cFY0Txzp5bfeCdFWu891WHJVr6HW7 gz0w== X-Gm-Message-State: AOAM530Iuhz3AfUWRXqLK6M/TJFsVdm4qJQGE6/s4W8DwHy9DvGJf8ph tcoCbvdQICO4lQzDNbcKJjWQ5RGlss+GyA== X-Google-Smtp-Source: ABdhPJwe0M8NvR9Ujt/7wCJmGDsmGxWYIimEUNK5j0ur+IEYlGhfQ2a2QR0bw4aJlfsyorPzMTLVAA== X-Received: by 2002:ae9:e84f:: with SMTP id a76mr3429115qkg.366.1623930689583; Thu, 17 Jun 2021 04:51:29 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:28 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 12/18] linux: Only use 64-bit syscall if required for timerfd_settime Date: Thu, 17 Jun 2021 08:50:58 -0300 Message-Id: <20210617115104.1359598-13-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 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+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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. Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel (with and without --enable-kernel=5.1) and on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski --- sysdeps/unix/sysv/linux/Makefile | 2 ++ sysdeps/unix/sysv/linux/timerfd_settime.c | 25 ++++++++++--------- sysdeps/unix/sysv/linux/tst-timerfd.c | 29 +++++++++++++++++++++-- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 982755f980..2e5b5e1dc4 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -145,6 +145,8 @@ endif $(objpfx)tst-ppoll: $(librt) $(objpfx)tst-ppoll-time64: $(librt) +$(objpfx)tst-timerfd: $(librt) +$(objpfx)tst-timerfd-time64: $(librt) # Generate the list of SYS_* macros for the system calls (__NR_* # macros). The file syscall-names.list contains all possible system diff --git a/sysdeps/unix/sysv/linux/timerfd_settime.c b/sysdeps/unix/sysv/linux/timerfd_settime.c index 0dd6fa026e..8f08133a73 100644 --- a/sysdeps/unix/sysv/linux/timerfd_settime.c +++ b/sysdeps/unix/sysv/linux/timerfd_settime.c @@ -29,31 +29,34 @@ __timerfd_settime64 (int fd, int flags, const struct __itimerspec64 *value, #ifndef __NR_timerfd_settime64 # define __NR_timerfd_settime64 __NR_timerfd_settime #endif - int ret = INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value, ovalue); -#ifndef __ASSUME_TIME64_SYSCALLS - if (ret == 0 || errno != ENOSYS) - return ret; - if (! in_time_t_range ((value->it_value).tv_sec) - || ! in_time_t_range ((value->it_interval).tv_sec)) +#ifdef __ASSUME_TIME64_SYSCALLS + return INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value, ovalue); +#else + bool is32bit_value = in_time_t_range (value->it_value.tv_sec); + bool is32bit_interval = in_time_t_range (value->it_interval.tv_sec); + if (!is32bit_value || !is32bit_interval) { + int r = INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value, + ovalue); + if (r == 0 || errno != ENOSYS) + return r; __set_errno (EOVERFLOW); - return -1; + return r; } struct itimerspec its32, oits32; its32.it_interval = valid_timespec64_to_timespec (value->it_interval); its32.it_value = valid_timespec64_to_timespec (value->it_value); - - ret = INLINE_SYSCALL_CALL (timerfd_settime, fd, flags, - &its32, ovalue ? &oits32 : NULL); + int ret = INLINE_SYSCALL_CALL (timerfd_settime, fd, flags, + &its32, ovalue != NULL ? &oits32 : NULL); if (ret == 0 && ovalue != NULL) { ovalue->it_interval = valid_timespec_to_timespec64 (oits32.it_interval); ovalue->it_value = valid_timespec_to_timespec64 (oits32.it_value); } -#endif return ret; +#endif } #if __TIMESIZE != 64 diff --git a/sysdeps/unix/sysv/linux/tst-timerfd.c b/sysdeps/unix/sysv/linux/tst-timerfd.c index 8828399119..27f1263ac6 100644 --- a/sysdeps/unix/sysv/linux/tst-timerfd.c +++ b/sysdeps/unix/sysv/linux/tst-timerfd.c @@ -16,15 +16,18 @@ License along with the GNU C Library; if not, see . */ +#include +#include #include #include +#include #include #include #include #include -static int -do_test (void) +static void +timerfd_test (void) { struct itimerspec settings = { { 0, 0 }, { 2, 0 } }; struct itimerspec val; @@ -52,6 +55,28 @@ do_test (void) /* Check difference between timerfd_gettime calls. */ TEST_COMPARE (support_timespec_check_in_range ((struct timespec) { 1, 0 }, val.it_value, 0.9, 1.0), 1); + + xclose (fd); +} + +static void +timerfd_large_timeout (void) +{ + int fd = timerfd_create (CLOCK_REALTIME, 0); + TEST_VERIFY (fd != -1); + support_create_timer (0, 100000000, false, NULL); + struct itimerspec it = { { 0, 0 }, { TYPE_MAXIMUM (time_t), 0 } }; + TEST_COMPARE (timerfd_settime (fd, 0, &it, NULL), 0); + uint64_t buf; + TEST_COMPARE (read (fd, &buf, sizeof (buf)), -1); + TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); +} + +static int +do_test (void) +{ + timerfd_test (); + timerfd_large_timeout (); return 0; }