From patchwork Sat Jul 10 17:15:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 44306 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 842ED384A07D for ; Sat, 10 Jul 2021 17:16:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 842ED384A07D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625937412; bh=JUEB9ZfhNRgHz9cLPRP6S5KGwOJcTLTBN7YPLCng0MA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=QVP67QOqOWbAO1aARi1bJoYsXJ09xpHokhIk/sJIHqYntbJvMf1OGTxH3CY8hPIRb Pu5bImW3E4l/4tDsPHaW+Dw5S+FJPeeTBg/kNckVAWoAN+nQInL0N524IbUx/sLuwJ wl66uiv4lAOdxt3j+gVBiw/+aFVuGXfou9lsxc/g= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 3E2533847838 for ; Sat, 10 Jul 2021 17:15:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3E2533847838 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-257-Uv7PDXxoMKS_VHCnFx9qIQ-1; Sat, 10 Jul 2021 13:15:22 -0400 X-MC-Unique: Uv7PDXxoMKS_VHCnFx9qIQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 843E11084F55 for ; Sat, 10 Jul 2021 17:15:21 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-103.rdu2.redhat.com [10.10.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 879151970E for ; Sat, 10 Jul 2021 17:15:20 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH] Linux: Use 32-bit vDSO for clock_gettime, gettimeofday, time (bug 28071) Date: Sat, 10 Jul 2021 19:15:12 +0200 Message-ID: <87czrqf5un.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The previous approach defeats the vDSO optimization on older kernels because a failing clock_gettime64 system call is performed on every function call. It also results in a clobbered errno value, exposing an OpenJDK bug (JDK-8270244). The existing layering is preserved for __ASSUME_TIME64_SYSCALLS. Otherwise, 32-bit time and gettimeofday use 32-bit clock_gettime, and clock_gettime is implemented using the vDSO. Tested on i686-linux-gnu (with a time64 and non-time64 kernel), x86_64-linux-gnu. Built with build-many-glibcs.py. --- sysdeps/unix/sysv/linux/Makefile | 9 +++- sysdeps/unix/sysv/linux/clock_gettime.c | 8 +++ sysdeps/unix/sysv/linux/gettimeofday.c | 21 +++++--- sysdeps/unix/sysv/linux/time.c | 22 ++++++--- .../unix/sysv/linux/tst-clock_gettime-clobber.c | 57 ++++++++++++++++++++++ sysdeps/unix/sysv/linux/tst-gettimeofday-clobber.c | 37 ++++++++++++++ sysdeps/unix/sysv/linux/tst-time-clobber.c | 36 ++++++++++++++ 7 files changed, 173 insertions(+), 17 deletions(-) diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 7d43dc95f2..9f00e53de4 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -213,7 +213,14 @@ ifeq ($(subdir),time) sysdep_headers += sys/timex.h bits/timex.h sysdep_routines += ntp_gettime ntp_gettimex -endif + +tests += \ + tst-clock_gettime-clobber \ + tst-gettimeofday-clobber \ + tst-time-clobber \ + # tests + +endif# $(subdir) == time ifeq ($(subdir),signal) tests-special += $(objpfx)tst-signal-numbers.out diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c index cfe9370455..86a72ecf5a 100644 --- a/sysdeps/unix/sysv/linux/clock_gettime.c +++ b/sysdeps/unix/sysv/linux/clock_gettime.c @@ -64,6 +64,7 @@ libc_hidden_def (__clock_gettime64) int __clock_gettime (clockid_t clock_id, struct timespec *tp) { +# ifdef __ASSUME_TIME64_SYSCALLS int ret; struct __timespec64 tp64; @@ -81,6 +82,13 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp) } return ret; +# else /* !__ASSUME_TIME64_SYSCALLS */ +# ifdef HAVE_CLOCK_GETTIME_VSYSCALL + return INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); +# else + return INLINE_SYSCALL_CALL (clock_gettime, clock_id, tp); +# endif +# endif /* !__ASSUME_TIME64_SYSCALLS */ } #endif libc_hidden_def (__clock_gettime) diff --git a/sysdeps/unix/sysv/linux/gettimeofday.c b/sysdeps/unix/sysv/linux/gettimeofday.c index 4197be5656..1b353956ea 100644 --- a/sysdeps/unix/sysv/linux/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/gettimeofday.c @@ -16,18 +16,17 @@ License along with the GNU C Library; if not, see . */ +#include +#include #include #include +#include /* Optimize the function call by setting the PLT directly to vDSO symbol. */ #ifdef USE_IFUNC_GETTIMEOFDAY # include -# include # ifdef SHARED -# include -# include - static int __gettimeofday_syscall (struct timeval *restrict tv, void *restrict tz) { @@ -54,7 +53,7 @@ __gettimeofday (struct timeval *restrict tv, void *restrict tz) } # endif weak_alias (__gettimeofday, gettimeofday) -#else /* USE_IFUNC_GETTIMEOFDAY */ +#else /* !USE_IFUNC_GETTIMEOFDAY */ /* Conversion of gettimeofday function to support 64 bit time on archs with __WORDSIZE == 32 and __TIMESIZE == 32/64 */ #include @@ -73,9 +72,12 @@ __gettimeofday64 (struct __timeval64 *restrict tv, void *restrict tz) return 0; } -# if __TIMESIZE != 64 +# if __TIMESIZE == 64 +weak_alias (__gettimeofday, gettimeofday) +# else /* __TIMESIZE != 64 */ libc_hidden_def (__gettimeofday64) +# ifdef __ASSUME_TIME64_SYSCALL int __gettimeofday (struct timeval *restrict tv, void *restrict tz) { @@ -92,6 +94,9 @@ __gettimeofday (struct timeval *restrict tv, void *restrict tz) *tv = valid_timeval64_to_timeval (tv64); return 0; } -# endif weak_alias (__gettimeofday, gettimeofday) -#endif +# else /* !__ASSUME_TIME64_SYSCALL */ +# include