From patchwork Thu Jun 17 11:50:59 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: 43874 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 C96B6393A402 for ; Thu, 17 Jun 2021 12:02:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C96B6393A402 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931360; bh=Yu4olqf/q/+zOMm534EVbGi8U5Hm8XEUi/bdAEYRx4U=; 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=VereklP1V410l33dvi5cjHYXn880TPsdhR67c8rSGohFl/dyVErF7wGi9eQ9Yq7RB uE2SNF9csji/18sIx3c5zmFXWEznPh6svIPZAvWe1J0uPbyLxk05KPoFYhTATsRPAY udIOABJbehXejqEUbSOSgSXHSTteHTjCAxqvQW1o= 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 AF3DE3893C44 for ; Thu, 17 Jun 2021 11:51:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AF3DE3893C44 Received: by mail-qk1-x733.google.com with SMTP id q190so158018qkd.2 for ; Thu, 17 Jun 2021 04:51:31 -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=Yu4olqf/q/+zOMm534EVbGi8U5Hm8XEUi/bdAEYRx4U=; b=VvaqsTwuiMJca6bmYczAnwOzjnznvN2h7gShKqXCwOiH3iRc9sNMgUj5/JQ8Sx+24f MU9mPZah+rLr1LzoaMijfoTDuuw9sZUMj/XePJ5636yBbdqSAbJSue9m4UcF3sM/d0Vz wekTSPLZ031M7bdklN+r57jwgJG9qjbnzlh9m2g1mThvz4GeKU+KnLuz0xIDlEi2bXRl ehUqoVlQPLUG/7JkD0iDZ9r/ji+IyLG8ucaw09GyDgJPtsXsUrcdvwW8FbeyKW8J+l7C NUrAYq9v4O1YhK6pl9QS2MqKKU8a48ohE49H7grHl46EMVBGv8iAD9TrkTjYQYN0j0Ly jt7g== X-Gm-Message-State: AOAM533W1DCLL3eUGR8GPq8LnIh6NJy8uNju9+aUoXunPVTl3TitVLxj odKG49lVzBfo24UdAb/P9kZ9LfHXIzakww== X-Google-Smtp-Source: ABdhPJzVWLSRnCsg4BQ9ENa2FoDJO58zync29nt0x05ln1Ab4w0tRAvbCL+F+RUao4rBp3S7mfkrEQ== X-Received: by 2002:a05:620a:2449:: with SMTP id h9mr3286889qkn.315.1623930691168; Thu, 17 Jun 2021 04:51:31 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:30 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 13/18] linux: Only use 64-bit syscall if required for mq_timedreceive Date: Thu, 17 Jun 2021 08:50:59 -0300 Message-Id: <20210617115104.1359598-14-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 --- rt/Makefile | 4 +- rt/tst-mqueue10-time64.c | 1 + rt/tst-mqueue10.c | 62 +++++++++++++++++++++++ sysdeps/unix/sysv/linux/mq_timedreceive.c | 35 +++++++------ 4 files changed, 85 insertions(+), 17 deletions(-) create mode 100644 rt/tst-mqueue10-time64.c create mode 100644 rt/tst-mqueue10.c diff --git a/rt/Makefile b/rt/Makefile index 797f2da51e..3382c7a1d2 100644 --- a/rt/Makefile +++ b/rt/Makefile @@ -48,7 +48,8 @@ tests := tst-shm tst-timer tst-timer2 \ tst-mqueue5 tst-mqueue6 tst-mqueue7 tst-mqueue8 tst-mqueue9 \ tst-timer3 tst-timer4 tst-timer5 \ tst-cpuclock2 tst-cputimer1 tst-cputimer2 tst-cputimer3 \ - tst-shm-cancel + tst-shm-cancel \ + tst-mqueue10 tests-internal := tst-timer-sigmask tests-time64 := \ @@ -58,6 +59,7 @@ tests-time64 := \ tst-mqueue2-time64 \ tst-mqueue4-time64 \ tst-mqueue8-time64 \ + tst-mqueue10-time64 \ tst-timer4-time64 extra-libs := librt diff --git a/rt/tst-mqueue10-time64.c b/rt/tst-mqueue10-time64.c new file mode 100644 index 0000000000..2c8a4ae372 --- /dev/null +++ b/rt/tst-mqueue10-time64.c @@ -0,0 +1 @@ +#include "tst-mqueue10.c" diff --git a/rt/tst-mqueue10.c b/rt/tst-mqueue10.c new file mode 100644 index 0000000000..7fb53a1cae --- /dev/null +++ b/rt/tst-mqueue10.c @@ -0,0 +1,62 @@ +/* Check for large timeout with mq_timedsend and mq_timedreceive. + 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 +#include +#include +#include +#include +#include +#include +#include + +static char name[sizeof "/tst-mqueue2-" + INT_BUFSIZE_BOUND (pid_t)]; + +static void +do_cleanup (void) +{ + mq_unlink (name); +} +#define CLEANUP_HANDLER do_cleanup + +static int +do_test (void) +{ + snprintf (name, sizeof (name), "/tst-mqueue2-%u", getpid ()); + + char msg[8] = { 0x55 }; + + struct mq_attr attr = { .mq_maxmsg = 1, .mq_msgsize = sizeof (msg) }; + mqd_t q = mq_open (name, O_CREAT | O_EXCL | O_RDWR, 0600, &attr); + TEST_VERIFY_EXIT (q != (mqd_t) -1); + + struct timespec ts = { TYPE_MAXIMUM (time_t), 0 }; + + { + timer_t timer = support_create_timer (0, 100000000, false, NULL); + TEST_COMPARE (mq_timedreceive (q, msg, sizeof (msg), NULL, &ts), -1); + TEST_VERIFY (errno == EINTR || errno == EOVERFLOW); + support_delete_timer (timer); + } + + mq_unlink (name); + + return 0; +} + +#include diff --git a/sysdeps/unix/sysv/linux/mq_timedreceive.c b/sysdeps/unix/sysv/linux/mq_timedreceive.c index eb948ccc18..8776977daf 100644 --- a/sysdeps/unix/sysv/linux/mq_timedreceive.c +++ b/sysdeps/unix/sysv/linux/mq_timedreceive.c @@ -29,30 +29,33 @@ __mq_timedreceive_time64 (mqd_t mqdes, char *__restrict msg_ptr, size_t msg_len, #ifndef __NR_mq_timedreceive_time64 # define __NR_mq_timedreceive_time64 __NR_mq_timedreceive #endif - int ret = SYSCALL_CANCEL (mq_timedreceive_time64, mqdes, msg_ptr, msg_len, - msg_prio, abs_timeout); -#ifndef __ASSUME_TIME64_SYSCALLS - if (ret == 0 || errno != ENOSYS) - return ret; +#ifdef __ASSUME_TIME64_SYSCALLS + return SYSCALL_CANCEL (mq_timedreceive_time64, mqdes, msg_ptr, msg_len, + msg_prio, abs_timeout); +#else + bool is32bit = abs_timeout != NULL + ? in_time_t_range (abs_timeout->tv_sec) : true; + if (!is32bit) + { + int r = SYSCALL_CANCEL (mq_timedreceive_time64, mqdes, msg_ptr, msg_len, + msg_prio, abs_timeout); + if (r == 0 || errno != ENOSYS) + return r; + __set_errno (EOVERFLOW); + return -1; + } - struct timespec ts32; + struct timespec ts32, *pts32 = NULL; if (abs_timeout != NULL) { - if (! in_time_t_range (abs_timeout->tv_sec)) - { - __set_errno (EOVERFLOW); - return -1; - } - ts32 = valid_timespec64_to_timespec (*abs_timeout); + pts32 = &ts32; } - ret = SYSCALL_CANCEL (mq_timedreceive, mqdes, msg_ptr, msg_len, msg_prio, - abs_timeout != NULL ? &ts32 : NULL); + return SYSCALL_CANCEL (mq_timedreceive, mqdes, msg_ptr, msg_len, msg_prio, + pts32); #endif - - return ret; } #if __TIMESIZE != 64