From patchwork Thu Jun 17 11:51:02 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: 43877 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 23B7C3896C29 for ; Thu, 17 Jun 2021 12:04:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 23B7C3896C29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623931499; bh=M4MW3vSSsGi+lkE3F0xq35Lp7GhotaDGe3fAiS70ci0=; 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=UY/zkBnFqfCNFgnYB26hgcNRVcCZhpETGwM0LIVgZzoFhDHYOCyHghRSdbUYT02kT BEeXQxK0rvUeTpaCG/kIt/sRjDR6YWLVuCpyf+ovDU1pAokKbc+MA0HdXFY4ROo4AQ ExQ0si4mfL1d6GbOrbvr6WMfLyaFgSwNxSRC/oZw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by sourceware.org (Postfix) with ESMTPS id 5CA953893670 for ; Thu, 17 Jun 2021 11:51:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5CA953893670 Received: by mail-qv1-xf2a.google.com with SMTP id x6so1466383qvx.4 for ; Thu, 17 Jun 2021 04:51:36 -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=M4MW3vSSsGi+lkE3F0xq35Lp7GhotaDGe3fAiS70ci0=; b=e1R15oJE4qkDhFWVfqFUsGduCUqX3CJoyMxaH9BB/rIa/8oeJUlAAzKU+Yan9tRmKJ P2+C1hzw0e5MmWi7BWs72I6Oz0ubuEvzc9Fq48bE3c57hi9AMyGWjHoWpmgiCHUfFKAX 71uv18SwYm3FiHJnperjnUAEl/DUB8oggSFV67i+65vKbnQHFcwIgkjX3C8S0F4/X5/X tfJmhEpeOZB5ITOX0RvTmORkRNptbxSLcwecuQKd5MD6Cmcrb/pAvS6oYnXatRAZFW2m 5jutuBUVUXJVIZzva5vr3p48MkIvSAiyZ4rScGAKroVymvuHnUDYkSWASHXdMdp+w32h Wutw== X-Gm-Message-State: AOAM533FCod+qXsfjR8wH0873mzhBfaEDHWLXkiSfn8gLeiQYqaSI7RX n/B9jB68fmCXaXX6xDj+PwUhjm4qqCcdRQ== X-Google-Smtp-Source: ABdhPJyacWbzwkTf3iBdoizXm+t5KmYZy1u13heQSRQzsQ9uQ6XrulsvXApnjWxxJ12Dhar+HIO7nw== X-Received: by 2002:ad4:5561:: with SMTP id w1mr5530743qvy.47.1623930695855; Thu, 17 Jun 2021 04:51:35 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id p12sm3016435qtw.61.2021.06.17.04.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:51:35 -0700 (PDT) To: libc-alpha@sourceware.org, Lukasz Majewski , Carlos O'Donell Subject: [PATCH 16/18] linux: Only use 64-bit syscall if required for utimensat family Date: Thu, 17 Jun 2021 08:51:02 -0300 Message-Id: <20210617115104.1359598-17-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, 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. The large timeout are already tests by io/tst-utimensat-skeleton.c. 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/utimensat.c | 35 ++++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/sysdeps/unix/sysv/linux/utimensat.c b/sysdeps/unix/sysv/linux/utimensat.c index 909a29762b..e79e4351d6 100644 --- a/sysdeps/unix/sysv/linux/utimensat.c +++ b/sysdeps/unix/sysv/linux/utimensat.c @@ -31,34 +31,43 @@ __utimensat64_helper (int fd, const char *file, #ifndef __NR_utimensat_time64 # define __NR_utimensat_time64 __NR_utimensat #endif - int ret = INLINE_SYSCALL_CALL (utimensat_time64, fd, file, &tsp64[0], flags); -#ifndef __ASSUME_TIME64_SYSCALLS - if (ret == 0 || errno != ENOSYS) - return ret; +#ifdef __ASSUME_TIME64_SYSCALLS + return INLINE_SYSCALL_CALL (utimensat_time64, fd, file, &tsp64[0], flags); +#else /* For UTIME_NOW and UTIME_OMIT the value of tv_sec field is ignored. */ -# define TS_VALID(ns) \ - ((((ns).tv_nsec == UTIME_NOW || (ns).tv_nsec == UTIME_OMIT) \ - || in_time_t_range ((ns).tv_sec))) +# define TS_SPECIAL(ts) \ + ((ts).tv_nsec == UTIME_NOW || (ts).tv_nsec == UTIME_OMIT) - if (tsp64 != NULL - && (!TS_VALID (tsp64[0]) || !TS_VALID (tsp64[1]))) + bool is32bit_t0 = tsp64 != NULL + ? TS_SPECIAL (tsp64[0]) + || in_time_t_range (tsp64[0].tv_sec) + : true; + bool is32bit_t1 = tsp64 != NULL + ? TS_SPECIAL (tsp64[1]) + || in_time_t_range (tsp64[1].tv_sec) + : true; + + if (!is32bit_t0 || !is32bit_t1) { + int r = INLINE_SYSCALL_CALL (utimensat_time64, fd, file, &tsp64[0], + flags); + if (r == 0 || errno != ENOSYS) + return r; __set_errno (EOVERFLOW); return -1; } - struct timespec tsp32[2]; + struct timespec tsp32[2], *ptsp32 = NULL; if (tsp64) { tsp32[0] = valid_timespec64_to_timespec (tsp64[0]); tsp32[1] = valid_timespec64_to_timespec (tsp64[1]); + ptsp32 = tsp32; } - ret = INLINE_SYSCALL_CALL (utimensat, fd, file, tsp64 ? &tsp32[0] : NULL, - flags); + return INLINE_SYSCALL_CALL (utimensat, fd, file, ptsp32, flags); #endif - return ret; } libc_hidden_def (__utimensat64_helper)