From patchwork Thu Jun 17 11:51:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 43876 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 EB0BC3938C2B for ; Thu, 17 Jun 2021 12:04:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB0BC3938C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931455; bh=p/vknGMi9cEu+5RVgPEoKUMJ4h/QkhIH74PMzM58fyI=; 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=b9SUPlnX89Vsl02bjWKAAb/TeCekpt79C+S0AuASW5JRH47/B+CJDD9+kyc7FVEkB utaey84yOHXBAmhWoWl/HiuNxoNuRfJkItQRIbuQUQaqB7MnHh+7s45P7N+QPKL99/ ooU4xKkFBnb+y1eqyIDRc8OKhLwpXIeus4meFhM4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by sourceware.org (Postfix) with ESMTPS id C95EC3893C44 for ; Thu, 17 Jun 2021 11:51:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C95EC3893C44 Received: by mail-qk1-x72e.google.com with SMTP id c138so2778140qkg.5 for ; Thu, 17 Jun 2021 04:51:34 -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=p/vknGMi9cEu+5RVgPEoKUMJ4h/QkhIH74PMzM58fyI=; b=IRbyfoZyYw7IISxNmeDAqF1Y9Ua8JMVdg0wquhEAGm3L5PIeeAqD6U7+xGxgAoAlyQ LE+UqIQnJjHSzdHHGFVPf7E/r9BNwcVCydWQi2hFS0vPh9YyMmgXb4jL/FLhpq4Qbnam TnibEhaoKqDtrpZZF/WPzXnxHU2GuihCW3omo2eGbzykfOFhZCeqwJ9IXpYRLHKAHOim ASQJ6J550mRYwGWztGVe34y9F3N2NL/5gCisTIFwCV/cgtQamfWsyeNs++jfhuTiadDu aaVrC+vyhc/H7oPX68Vsx4c7LwcKQsuLKCeBiYF0KWUVwGs3JS7RUnF7ozb6fCXBYGVf 1GYw== X-Gm-Message-State: AOAM532O1qsEeyGsBWPUWQRu0KO6NlgFp7964iKdKJ3Y/z//QdiVwXNR AmNKzPNJi2ZsZLSzJUQvSt/pG583AZJ6gw== X-Google-Smtp-Source: ABdhPJyesOZV27eQy3vl7sVPS9sqvJ+XLDg+8TocnNNkzS4dHGKnFuGmp5wtkN3r92SkaEoxSUIQ5w== X-Received: by 2002:a05:620a:5b5:: with SMTP id q21mr3360161qkq.58.1623930694280; Thu, 17 Jun 2021 04:51:34 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:34 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 15/18] linux: Only use 64-bit syscall if required for sigtimedwait Date: Thu, 17 Jun 2021 08:51:01 -0300 Message-Id: <20210617115104.1359598-16-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 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. --- sysdeps/unix/sysv/linux/Makefile | 2 ++ sysdeps/unix/sysv/linux/sigtimedwait.c | 26 ++++++++++++++-------- sysdeps/unix/sysv/linux/tst-sigtimedwait.c | 18 +++++++++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 2e5b5e1dc4..9a65fc39c0 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-sigtimedwait: $(librt) +$(objpfx)tst-sigtimedwait-time64: $(librt) $(objpfx)tst-timerfd: $(librt) $(objpfx)tst-timerfd-time64: $(librt) diff --git a/sysdeps/unix/sysv/linux/sigtimedwait.c b/sysdeps/unix/sysv/linux/sigtimedwait.c index 25ed0adb0d..bae9bf44bc 100644 --- a/sysdeps/unix/sysv/linux/sigtimedwait.c +++ b/sysdeps/unix/sysv/linux/sigtimedwait.c @@ -25,20 +25,28 @@ __sigtimedwait64 (const sigset_t *set, siginfo_t *info, #ifndef __NR_rt_sigtimedwait_time64 # define __NR_rt_sigtimedwait_time64 __NR_rt_sigtimedwait #endif - int result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout, - __NSIG_BYTES); -#ifndef __ASSUME_TIME64_SYSCALLS - if (result != 0 && errno == ENOSYS) + int result; +#ifdef __ASSUME_TIME64_SYSCALLS + result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout, + __NSIG_BYTES); +#else + bool is32bit = timeout != NULL + ? in_time_t_range (timeout->tv_sec) : true; + if (!is32bit) + { + result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout, + __NSIG_BYTES); + if (result == 0 || errno != ENOSYS) + return result; + __set_errno (EOVERFLOW); + return -1; + } + else { struct timespec ts32, *pts32 = NULL; if (timeout != NULL) { - if (! in_time_t_range (timeout->tv_sec)) - { - __set_errno (EINVAL); - return -1; - } ts32 = valid_timespec64_to_timespec (*timeout); pts32 = &ts32; } diff --git a/sysdeps/unix/sysv/linux/tst-sigtimedwait.c b/sysdeps/unix/sysv/linux/tst-sigtimedwait.c index 973fb5d301..a8b9893c61 100644 --- a/sysdeps/unix/sysv/linux/tst-sigtimedwait.c +++ b/sysdeps/unix/sysv/linux/tst-sigtimedwait.c @@ -17,11 +17,13 @@ . */ #include +#include #include #include #include #include #include +#include #include static int @@ -47,6 +49,20 @@ test_sigtimedwait_timeout (bool zero_tmo) return 0; } +static void +test_sigtimedwait_large_timeout (void) +{ + support_create_timer (0, 100000000, false, NULL); + struct timespec ts = { TYPE_MAXIMUM (time_t), 0 }; + + sigset_t ss_usr1; + sigemptyset (&ss_usr1); + sigaddset (&ss_usr1, SIGUSR1); + + TEST_COMPARE (sigtimedwait (&ss_usr1, NULL, &ts), -1); + TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); +} + static int do_test (void) { @@ -56,6 +72,8 @@ do_test (void) /* Check if sigtimedwait exits after specified timeout. */ test_sigtimedwait_timeout (false); + test_sigtimedwait_large_timeout (); + return 0; }