From patchwork Thu Jun 17 11:50:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 43866 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 2428E3894C3F for ; Thu, 17 Jun 2021 11:56:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2428E3894C3F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623930995; bh=9hwRRQ+oYtjo5ntqKEDWt0n6fU+ysZXUF+z91Sm8NMA=; 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=fOvyrLoktQIM3q3Nyf6PJoh4ONaGfMZlBKTPEDl5bQLBZ11zYj3J2XF51EBJxMg4O TjzfGBLqJsIZ/ftIdYOd1rFoqUyGDKL1y/+3B+uwbJxjl12Bi0W7NuaSbLkWfzEggC tZ8iHqeHLoUCQojfTLtCtEEJtHNYQ0E3CpXxGPHs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by sourceware.org (Postfix) with ESMTPS id 0B2E73893C56 for ; Thu, 17 Jun 2021 11:51:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0B2E73893C56 Received: by mail-qk1-x733.google.com with SMTP id 5so2754499qkc.8 for ; Thu, 17 Jun 2021 04:51:17 -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=9hwRRQ+oYtjo5ntqKEDWt0n6fU+ysZXUF+z91Sm8NMA=; b=EB0I2Ydl1x0vulcxrmwvekjFqV/eU/wGU32hHgeTBwInBt7at5u3UoBCNc/zJz5Ju5 Cv0OkucbimbGXjo4V4hyfyJ7VRY5KLgbfwGPTVR8U2wAq5gmTTPwvmMl0qWrp28ORz3C 5e4zcWtE6n/cix0UBrsT80Dj0S+5DzjKhB8VDLyYZWcTnuj24u5xbPDNcTDb3yGoIWuM VpVXg6hWoa0uqh4e8tmnJOYnKyOW068vhmB4dddnbaYkq6iIqcXBwfSov+4a1PPMojoY 1HZ6dV1f35RjV2RxSqSi4eF71ARciif4DiduYM5+jOH3m3871MV+5OGNL9gm8sWVghsD 78ug== X-Gm-Message-State: AOAM531SYW90RF52uWkbhRAPyVuX5R3vNtcxamFEnNyNQAc95tvFMf0n eenqh4+B2ZZFgpMJM9Zs73kw3/SuC29PxA== X-Google-Smtp-Source: ABdhPJxqt73V/Dl9luBLeUEip59KOzhJpBFulbHl83R+GOqX9agVXjWgGHz93vz8dgKR5Cu6BHjfRw== X-Received: by 2002:a37:e53:: with SMTP id 80mr3382372qko.187.1623930676465; Thu, 17 Jun 2021 04:51:16 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:16 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 04/18] linux: Only use 64-bit syscall if required for ppoll Date: Thu, 17 Jun 2021 08:50:50 -0300 Message-Id: <20210617115104.1359598-5-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.3 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 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. This also avoids the need to use supports_time64() (which breaks the usage case of live migration like CRIU or similar). 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 | 9 +++++++ sysdeps/unix/sysv/linux/ppoll.c | 41 +++++++++++------------------ sysdeps/unix/sysv/linux/tst-ppoll.c | 15 +++++++++++ 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 294c366e3b..c36ea0e494 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -137,6 +137,15 @@ tests-time64 += \ CFLAGS-tst-sigcontext-get_pc.c = -fasynchronous-unwind-tables +ifeq (yes,$(build-shared)) +librt = $(common-objpfx)rt/librt.so +else +librt = $(common-objpfx)rt/librt.a +endif + +$(objpfx)tst-ppoll: $(librt) +$(objpfx)tst-ppoll-time64: $(librt) + # Generate the list of SYS_* macros for the system calls (__NR_* # macros). The file syscall-names.list contains all possible system # call names, and the generated header file produces SYS_* macros for diff --git a/sysdeps/unix/sysv/linux/ppoll.c b/sysdeps/unix/sysv/linux/ppoll.c index 624f14f517..e1ad316e2e 100644 --- a/sysdeps/unix/sysv/linux/ppoll.c +++ b/sysdeps/unix/sysv/linux/ppoll.c @@ -21,9 +21,6 @@ #include #include #include -#include -#include - int __ppoll64 (struct pollfd *fds, nfds_t nfds, const struct __timespec64 *timeout, @@ -38,40 +35,34 @@ __ppoll64 (struct pollfd *fds, nfds_t nfds, const struct __timespec64 *timeout, timeout = &tval; } - int ret; - - if (supports_time64 ()) - { #ifndef __NR_ppoll_time64 # define __NR_ppoll_time64 __NR_ppoll #endif + +#ifdef __ASSUME_TIME64_SYSCALLS + return SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask, + __NSIG_BYTES); +#else + bool is32bit = timeout != NULL + ? in_time_t_range (timeout->tv_sec) : true; + int ret; + if (!is32bit) + { ret = SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask, __NSIG_BYTES); - if (ret == 0 || errno != ENOSYS) return ret; - - mark_time64_unsupported (); + __set_errno (EOVERFLOW); + return -1; } -#ifndef __ASSUME_TIME64_SYSCALLS struct timespec ts32; - if (timeout) - { - if (! in_time_t_range (timeout->tv_sec)) - { - __set_errno (EOVERFLOW); - return -1; - } - - ts32 = valid_timespec64_to_timespec (*timeout); - } + if (timeout != NULL) + ts32 = valid_timespec64_to_timespec (*timeout); - ret = SYSCALL_CANCEL (ppoll, fds, nfds, timeout ? &ts32 : NULL, sigmask, - __NSIG_BYTES); + return SYSCALL_CANCEL (ppoll, fds, nfds, timeout ? &ts32 : NULL, sigmask, + __NSIG_BYTES); #endif - - return ret; } #if __TIMESIZE != 64 diff --git a/sysdeps/unix/sysv/linux/tst-ppoll.c b/sysdeps/unix/sysv/linux/tst-ppoll.c index 9fe6ad07ce..e21e2fcc72 100644 --- a/sysdeps/unix/sysv/linux/tst-ppoll.c +++ b/sysdeps/unix/sysv/linux/tst-ppoll.c @@ -19,9 +19,11 @@ #include #include #include +#include #include #include #include +#include #include static int test_ppoll_timeout (bool zero_tmo) @@ -41,6 +43,16 @@ static int test_ppoll_timeout (bool zero_tmo) return 0; } +static void +test_ppoll_large_timeout (void) +{ + support_create_timer (0, 100000000, false, NULL); + struct timespec ts = { TYPE_MAXIMUM (time_t), 0 }; + struct pollfd fds = { -1, 0, 0 }; + TEST_COMPARE (ppoll (&fds, 1, &ts, 0), -1); + TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); +} + static int do_test (void) { @@ -50,6 +62,9 @@ do_test (void) /* Check if ppoll exits after specified timeout. */ test_ppoll_timeout (false); + /* Check if ppoll with large timeout. */ + test_ppoll_large_timeout (); + return 0; }