From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 56FA01F55B for ; Tue, 19 May 2020 19:07:46 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 49B553954836; Tue, 19 May 2020 19:07:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49B553954836 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1589915265; bh=CrUkY7zT77cX/ZKQcjE+P1x7ky2vbs0eU/GjjYcPllY=; h=To:References:Subject:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=YG5g9vF1EXluelKIYIM8kbNtFIdnAlubaKNa8d2Xl58FNGHUxy4fIuTiyitbXBn3J IA9wBbfWdvL54a2pKg98Mz7vi5O9MkT0eM8RNtVMFfjE7W124D44DFPwgy6oLyuzvX C7+w6/WNlh1VHfvqM19bU2PQNwHkgkUecosS1RZc= Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by sourceware.org (Postfix) with ESMTPS id 7319C395447D for ; Tue, 19 May 2020 19:07:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7319C395447D Received: by mail-qt1-x843.google.com with SMTP id c24so533119qtw.7 for ; Tue, 19 May 2020 12:07:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=CrUkY7zT77cX/ZKQcjE+P1x7ky2vbs0eU/GjjYcPllY=; b=Zyo/nrECX/wT9IWipUI7WNAvAdg89xs3uCTzNlSQyUJ+QH3Jve/xCYSyjuljd0W4wn cUDQyqauWfKCZ3ZlEvOWANWQFeS25aKtTHvzCLaC/h5SZyqGF0ADl0af+Wmu5MvIfpAb 7FS4YoKoSWUKz7hPY+1QPF0ojQamg6/R45g5m9d9L9PxVn6AsfRx7svOFcW8V2OpCcC7 HwSo+hrCLHN42UEZKW6HP4mMT0g4SIGtNqIDtLkgHJmX3f5BAR0h/mBJT9AHePzkpKhR rwMhDNsBAq0UbzmmD8psKt1N5N2l74oDpe0D3kE4/y0mq0T0OWHCxqNvyICadSmoq0NV AR+A== X-Gm-Message-State: AOAM530vyaLahpQLvYMkCTM3Ssw9AGv8XvUQarDUMC6pxOqtyELtEqGB lHZvMu6ttQIVbwiMxSoc7fmpIQ== X-Google-Smtp-Source: ABdhPJzAc+PkxJzb0dx525TJXx84MvLAB+Yk1BKaN4DZYY6wN2f+Rzb7xQrfswcChE8sjEb2Pqp2uA== X-Received: by 2002:aed:3ed0:: with SMTP id o16mr1392786qtf.154.1589915260712; Tue, 19 May 2020 12:07:40 -0700 (PDT) Received: from [192.168.1.4] ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id n9sm364227qkn.10.2020.05.19.12.07.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 May 2020 12:07:40 -0700 (PDT) To: Lukasz Majewski , Joseph Myers References: <20200508145640.16336-1-lukma@denx.de> <20200508145640.16336-2-lukma@denx.de> Autocrypt: addr=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bxvUZzIJp3spAao7jLsQj1DbD2s5+S1BW09A0mI/1DjB6EhNN+4bDB SJCOv/ReK3tFJXuj/HbyDrOdoMt8aIFbe7YFLEExHpSk+HgN05Lg5TyTro8oW7TSMTk+8a5M kzaH4UGXTTBDP/g5cfL3RFPl79ubXwARAQABiQIfBBgBCAAJBQJXFRpKAhsMAAoJEKqx7BSn lIjvI/8P/jg0jl4Tbvg3B5kT6PxJOXHYu9OoyaHLcay6Cd+ZrOd1VQQCbOcgLFbf4Yr+rE9l mYsY67AUgq2QKmVVbn9pjvGsEaz8UmfDnz5epUhDxC6yRRvY4hreMXZhPZ1pbMa6A0a/WOSt AgFj5V6Z4dXGTM/lNManr0HjXxbUYv2WfbNt3/07Db9T+GZkpUotC6iknsTA4rJi6u2ls0W9 1UIvW4o01vb4nZRCj4rni0g6eWoQCGoVDk/xFfy7ZliR5B+3Z3EWRJcQskip/QAHjbLa3pml xAZ484fVxgeESOoaeC9TiBIp0NfH8akWOI0HpBCiBD5xaCTvR7ujUWMvhsX2n881r/hNlR9g fcE6q00qHSPAEgGr1bnFv74/1vbKtjeXLCcRKk3Ulw0bY1OoDxWQr86T2fZGJ/HIZuVVBf3+ gaYJF92GXFynHnea14nFFuFgOni0Mi1zDxYH/8yGGBXvo14KWd8JOW0NJPaCDFJkdS5hu0VY 7vJwKcyHJGxsCLU+Et0mryX8qZwqibJIzu7kUJQdQDljbRPDFd/xmGUFCQiQAncSilYOcxNU EMVCXPAQTteqkvA+gNqSaK1NM9tY0eQ4iJpo+aoX8HAcn4sZzt2pfUB9vQMTBJ2d4+m/qO6+ cFTAceXmIoFsN8+gFN3i8Is3u12u8xGudcBPvpoy4OoG Subject: Re: [PATCH v2 1/7] y2038: linux: Provide __clock_adjtime64 implementation Message-ID: <4450aefc-079f-d73d-5c70-ce8ed54b777b@linaro.org> Date: Tue, 19 May 2020 16:07:36 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200508145640.16336-2-lukma@denx.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit 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: , From: Adhemerval Zanella via Libc-alpha Reply-To: Adhemerval Zanella Cc: Florian Weimer , GNU C Library , Alistair Francis , Andreas Schwab Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On 08/05/2020 11:56, Lukasz Majewski wrote: > This patch replaces auto generated wrapper (as described in > sysdeps/unix/sysv/linux/syscalls.list) for clock_adjtime with one which adds > extra support for reading 64 bit time values on machines with __TIMESIZE != 64. > > To achieve this goal new __clock_adjtime64 explicit 64 bit function for > adjusting Linux clock has been added. > Moreover, a 32 bit version - __clock_adjtime has been refactored to internally > use __clock_adjtime64. > > The __clock_adjtime is now supposed to be used on systems still supporting 32 > bit time (__TIMESIZE != 64) - hence the necessary conversions between 64 bit > struct __timespec64 and struct timespec. > > The new __clock_adjtime64 syscall available from Linux 5.1+ has been used, when > applicable. > Up till v5.4 in the Linux kernel there was a bug preventing this call from > obtaining correct struct's timex time.tv_sec time after time_t overflow > (i.e. not being Y2038 safe). > > Build tests: > - ./src/scripts/build-many-glibcs.py glibcs > > Run-time tests: > - Run specific tests on ARM/x86 32bit systems (qemu): > https://github.com/lmajewski/meta-y2038 and run tests: > https://github.com/lmajewski/y2038-tests/commits/master > > Linux kernel, headers and minimal kernel version for glibc build test matrix: > - Linux v5.1 (with clock_adjtime64) and glibc build with v5.1 as > minimal kernel version (--enable-kernel="5.1.0") > The __ASSUME_TIME64_SYSCALLS flag defined. > > - Linux v5.1 and default minimal kernel version > The __ASSUME_TIME64_SYSCALLS not defined, but kernel supports clock_adjtime64 > syscall. > > - Linux v4.19 (no clock_adjtime64 support) with default minimal kernel version > for contemporary glibc (3.2.0) > This kernel doesn't support clock_adjtime64 syscall, so the fallback to > clock_adjtime is tested. > > Above tests were performed with Y2038 redirection applied as well as without > (so the __TIMESIZE != 64 execution path is checked as well). > > No regressions were observed. > > Changes for v2: > - Fix wrong indentation > - Remove the check for (ret >= TIME_OK && ret <= TIME_ERROR) in the > clock_adjtime64 call - just check if syscall returned ENOSYS > - Add 64 bit time overflow for ADJ_SETOFFSET set in modes Ok with the changes below. Reviewed-by: Adhemerval Zanella > --- > sysdeps/unix/sysv/linux/Makefile | 2 +- > sysdeps/unix/sysv/linux/clock_adjtime.c | 71 +++++++++++++++++++++ > sysdeps/unix/sysv/linux/include/sys/timex.h | 3 + > sysdeps/unix/sysv/linux/syscalls.list | 1 - > 4 files changed, 75 insertions(+), 2 deletions(-) > create mode 100644 sysdeps/unix/sysv/linux/clock_adjtime.c > > diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile > index 0326f92c40..2f2fd5d4d0 100644 > --- a/sysdeps/unix/sysv/linux/Makefile > +++ b/sysdeps/unix/sysv/linux/Makefile > @@ -60,7 +60,7 @@ sysdep_routines += adjtimex clone umount umount2 readahead sysctl \ > personality epoll_wait tee vmsplice splice \ > open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \ > timerfd_gettime timerfd_settime prctl \ > - process_vm_readv process_vm_writev > + process_vm_readv process_vm_writev clock_adjtime > > CFLAGS-gethostid.c = -fexceptions > CFLAGS-tee.c = -fexceptions -fasynchronous-unwind-tables Ok. > diff --git a/sysdeps/unix/sysv/linux/clock_adjtime.c b/sysdeps/unix/sysv/linux/clock_adjtime.c > new file mode 100644 > index 0000000000..5c02031bb5 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/clock_adjtime.c > @@ -0,0 +1,71 @@ > +/* clock_adjtime -- tune kernel clock I think we usually add a final period in one line description. > + Copyright (C) 2020 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; see the file COPYING.LIB. If > + not, see . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +int > +__clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64) > +{ > +#ifdef __ASSUME_TIME64_SYSCALLS > +# ifndef __NR_clock_adjtime64 > +# define __NR_clock_adjtime64 __NR_clock_adjtime > +# endif > + return INLINE_SYSCALL_CALL (clock_adjtime64, clock_id, tx64); > +#else > + int ret = INLINE_SYSCALL_CALL (clock_adjtime64, clock_id, tx64); > + if (errno != ENOSYS) > + return ret; > + > + if (tx64->modes & ADJ_SETOFFSET > + && ! in_time_t_range (tx64->time.tv_sec)) > + { > + __set_errno (EOVERFLOW); > + return -1; > + } > + > + struct timex tx32 = valid_timex64_to_timex (*tx64); > + int retval = INLINE_SYSCALL_CALL (clock_adjtime, clock_id, &tx32); > + *tx64 = valid_timex_to_timex64 (tx32);> + > + return retval; The function might still return EINVAL for invalid clocks, ENODEV for invalid dynamic ones, EOPNOTSUPP if the clock does not support adjustment, or EPERM if buf.modes is neither 0 nor ADJ_OFFSET_SS_READ and the caller does not have sufficient privilege. So we still need to check the syscall return value prior setting the tx64 value: int retval = INLINE_SYSCALL_CALL (clock_adjtime, clock_id, &tx32); if (retval >= 0) *tx64 = valid_timex_to_timex64 (tx32); return retval; Ok with this change. > +#endif > +} > + > +#if __TIMESIZE != 64 > +libc_hidden_def (__clock_adjtime64) > + > +int > +__clock_adjtime (const clockid_t clock_id, struct timex *tx) > +{ > + struct __timex64 tx64; > + int retval; > + > + tx64 = valid_timex_to_timex64 (*tx); > + retval = __clock_adjtime64 (clock_id, &tx64); Same as before, we need to check its return value prior setting TX: retval = __clock_adjtime64 (clock_id, &tx64); if (retval >= 0) *tx = valid_timex64_to_timex (tx64); return retval; Ok with this change. > + *tx = valid_timex64_to_timex (tx64); > + > + return retval; > +} > +#endif > +libc_hidden_def (__clock_adjtime); > +strong_alias (__clock_adjtime, clock_adjtime) Ok. > diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h > index 3efe7cd306..2848c5cf76 100644 > --- a/sysdeps/unix/sysv/linux/include/sys/timex.h > +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h > @@ -30,6 +30,7 @@ libc_hidden_proto (__adjtimex) > /* Local definition of 64 bit time supporting timex struct */ > # if __TIMESIZE == 64 > # define __timex64 timex > +# define __clock_adjtime64 __clock_adjtime > # else > > struct __timex64 > @@ -71,6 +72,8 @@ struct __timex64 > int :32; > int :32; > }; > +extern int __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64); > +libc_hidden_proto (__clock_adjtime64); > # endif > > /* Convert a known valid struct timex into a struct __timex64. */ Ok. > diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list > index 1d8893d1b8..01ec2bfa95 100644 > --- a/sysdeps/unix/sysv/linux/syscalls.list > +++ b/sysdeps/unix/sysv/linux/syscalls.list > @@ -4,7 +4,6 @@ alarm - alarm i:i alarm > bdflush EXTRA bdflush i:ii __compat_bdflush bdflush@GLIBC_2.0:GLIBC_2.23 > capget EXTRA capget i:pp capget > capset EXTRA capset i:pp capset > -clock_adjtime EXTRA clock_adjtime i:ip __clock_adjtime clock_adjtime > create_module EXTRA create_module 3 __compat_create_module create_module@GLIBC_2.0:GLIBC_2.23 > delete_module EXTRA delete_module 3 delete_module > epoll_create EXTRA epoll_create i:i epoll_create > Ok.