From patchwork Tue Dec 17 21:47:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 181913 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp6349451ile; Tue, 17 Dec 2019 13:48:00 -0800 (PST) X-Google-Smtp-Source: APXvYqwDhym9DHtM3g0IkBvEd0I6e5oh5jfq1fm2EqvxvGUYeaJhX6yg0sHIOv861aQOKlVn5T0P X-Received: by 2002:aca:7244:: with SMTP id p65mr2752652oic.50.1576619280343; Tue, 17 Dec 2019 13:48:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576619280; cv=none; d=google.com; s=arc-20160816; b=feo72Oy2Y+mpWK69Qgt+5+jy+fQreSdQ/yef5R09w03AfrFnZIRmZhdXxfZv/yFtT1 ZBUbXwNIlka+27pivCFRUDFRWfU05VwrGwk3xtmhTvy6LCQRa0A1LgIP9SB8oZvfuC++ GPhODHjyn/fAYYDBAzy/cb8ZW+1Hs5Togw9rd6tUs9HV9G5w6mAiVI5xD66S+57PrfDY 1pehBnTmo/XxVEzIUxhuth9b4CRrjiOsvpXtyg+mQPwT+DhdKo0+Lp1BgYN4m9oni6lK e5FD2WVxTpnqIxRYeX9WPnAXEGNY+e2fczNUpFCGLGQOcIue7yHqub96a+PyV9sa7eSy QG+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:dkim-signature:delivered-to:sender :list-help:list-post:list-archive:list-subscribe:list-unsubscribe :list-id:precedence:mailing-list:dkim-signature:domainkey-signature; bh=kIHlcsXGLCcPQnKGQWbOLUsjqn84Fl8/BNjdtDz1aCY=; b=UaMeOXkrREhxixtBSVNJOYT4E6mBq26WtXUAwu12/IT73/YqzUA7yX8Yrj1UNw+8Hp nGL5YxIfHd3sGp7w/gLTjy7tiGoM7hna/laTudqKQ0MqrzXQAOjbraxKgbxNDB1csZ7Y BjtvsNYWpAVNvhEzQtqBlBQ8k3O51F6r3XgrmnANx3yhVXAvB9WzP+UWE6rHJJ142zQ3 +bxwQWfFu/ica/UA5MARchScmKaxV5N9KbKaMwCVW3YHmjmhJ/0NvjZxEjiDggcgCymT z1gEXvrdT0lik3WKjftf9ZGFSG1kNKsiMzwihwuQwSn7XXjU6Pw8sUi7/+dPAtJc6dWP 3nZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=iDxJfOu6; dkim=pass header.i=@linaro.org header.s=google header.b=RCovwVcM; spf=pass (google.com: domain of libc-alpha-return-108164-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-108164-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id q18si12964932otc.189.2019.12.17.13.48.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Dec 2019 13:48:00 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-108164-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=iDxJfOu6; dkim=pass header.i=@linaro.org header.s=google header.b=RCovwVcM; spf=pass (google.com: domain of libc-alpha-return-108164-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-108164-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=f0dkkPcCeECtydZqVFUSGv7AxhmrI8yaMTjJhg1HOV45XLJ3sUCu7 MR2OqnHXALS6zqbDdMR2gM+Wi0bnAMqhYIxMgrkylZhwUm8RHpPmwVK6/Zw9LnX9 GTVuOczPIuu8NZw2+Bp416BAT/BZ1zdXPLB6miFwX/Km1YG0OMTNiA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=s9+6BQuaDd60knysckFoueYlUow=; b=iDxJfOu6fv+2K4JwdgwaHwjsFgtR cWoy+KeF9+tgneRnFwNqrmAaDvHogHYeyinB5y7pIz5KsTeKbcpMKpWj66kpzMy5 1Tn06++3OFSBQhys+JsWE/noDStgijnj9VuQRSuBD6M9OaUzGFk0JKX6GqyN8aS5 EwpeVhOZ48D6+bk= Received: (qmail 109476 invoked by alias); 17 Dec 2019 21:47:40 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 109410 invoked by uid 89); 17 Dec 2019 21:47:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=1822, inline_vsyscall, sysdepvdsoh, INLINE_VSYSCALL X-HELO: mail-pl1-f195.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=kIHlcsXGLCcPQnKGQWbOLUsjqn84Fl8/BNjdtDz1aCY=; b=RCovwVcMEAdhEO/9+gBaZVDgWLqCbHNJQfZsa14AIY8JA2igAJmiiZRm5NCNSP2QvL OUQWtrZTRDq+tUZZhYRlxn2b4/9RuAlHnWdBrD+6B1iJ18MCKNUnc+xr+2UarFxXChs6 lMTeHvfyJZNqfK1mdC5UeF4qNFKcZPhtXOYu90FoPWAnJHOZWNAiQToNoKDfUITSMUpi xlGHGF2NdK31jpAbmURzVkeanHelYU0BXdNpcnj/gCrUFtuNiijDw6+wCdHc2beGs+0Z TnUwk2aBUoHXvmdzHbPbAJTOjNXlqBTBAot6JzaeJOhRLWtvXkRYOYrToObuRa9BXSG1 NRPw== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 01/16] linux: Fix vDSO macros build with time64 interfaces Date: Tue, 17 Dec 2019 18:47:13 -0300 Message-Id: <20191217214728.2886-1-adhemerval.zanella@linaro.org> Changes from previous version: - Reinstate syscall fallback on INLINE_VSYSCALL, it simplifies when the macro is used multiple times (as for clock_gettime and clock_getres). -- As indicated on libc-help [1] the ec138c67cb commit broke 32-bit builds when configured with --enable-kernel=5.1 or higher. The scenario 10 from [2] might also occur in this configuration and INLINE_VSYSCALL will try to use the vDSO symbol and HAVE_CLOCK_GETTIME64_VSYSCALL does not set HAVE_VSYSCALL prior its usage. Also, there is no easy way to just enable the code to use one vDSO sysmbo since the macro INLINE_VSYSCALL is redefined if HAVE_VSYSCALL is set. Instead of adding more pre-processor handling and making the code even more convoluted, this patch removes the requirement of defining HAVE_VSYSCALL before including sysdep-vdso.h to enable vDSO usage. The INLINE_VSYSCALL is now expected to be issued inside a HAVE_*_VSYSCALL check, since it will try to use the internal vDSO pointers. Both clock_getres and clock_gettime vDSO code for time64_t were removed since there is no vDSO setup code for the symbol (an architecture can not set HAVE_CLOCK_GETTIME64_VSYSCALL). Checked on i686-linux-gnu (default and with --enable-kernel=5.1), x86_64-linux-gnu, aarch64-linux-gnu, and powerpc64le-linux-gnu. I also checked against a build to mips64-linux-gnu and sparc64-linux-gnu. [1] https://sourceware.org/ml/libc-help/2019-12/msg00014.html --- .../unix/sysv/linux/aarch64/gettimeofday.c | 4 -- sysdeps/unix/sysv/linux/clock_getres.c | 36 +++++++++++------- sysdeps/unix/sysv/linux/clock_gettime.c | 38 +++++++++++-------- sysdeps/unix/sysv/linux/getcpu.c | 9 +---- .../unix/sysv/linux/powerpc/gettimeofday.c | 4 -- sysdeps/unix/sysv/linux/powerpc/time.c | 4 -- sysdeps/unix/sysv/linux/sched_getcpu.c | 15 +++----- sysdeps/unix/sysv/linux/sysdep-vdso.h | 34 +---------------- sysdeps/unix/sysv/linux/x86/gettimeofday.c | 4 -- sysdeps/unix/sysv/linux/x86/time.c | 8 ++-- 10 files changed, 58 insertions(+), 98 deletions(-) -- 2.17.1 diff --git a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c index 7e772e05ce..143c5c1507 100644 --- a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c @@ -22,10 +22,6 @@ #include #include - -#ifdef HAVE_GETTIMEOFDAY_VSYSCALL -# define HAVE_VSYSCALL -#endif #include /* Used as a fallback in the ifunc resolver if VDSO is not available diff --git a/sysdeps/unix/sysv/linux/clock_getres.c b/sysdeps/unix/sysv/linux/clock_getres.c index 9497f78787..52671fa641 100644 --- a/sysdeps/unix/sysv/linux/clock_getres.c +++ b/sysdeps/unix/sysv/linux/clock_getres.c @@ -20,9 +20,6 @@ #include #include -#ifdef HAVE_CLOCK_GETRES_VSYSCALL -# define HAVE_VSYSCALL -#endif #include #include #include @@ -32,23 +29,34 @@ int __clock_getres64 (clockid_t clock_id, struct __timespec64 *res) { #ifdef __ASSUME_TIME64_SYSCALLS -# ifndef __NR_clock_getres_time64 - return INLINE_VSYSCALL (clock_getres, 2, clock_id, res); + /* 64 bit ABIs or Newer 32-bit ABIs that only support 64-bit time_t. */ +# ifdef __NR_clock_getres_time64 + return INLINE_SYSCALL_CALL (clock_getres_time64, clock_id, res); # else - return INLINE_SYSCALL (clock_getres_time64, 2, clock_id, res); +# ifdef HAVE_CLOCK_GETRES_VSYSCALL + return INLINE_VSYSCALL (clock_getres, 2, clock_id, res); +# else + return INLINE_SYSCALL_CALL (clock_getres, clock_id, res); +# endif # endif #else + int r; + /* Old 32-bit ABI with possible 64-bit time_t support. */ # ifdef __NR_clock_getres_time64 - int ret = INLINE_SYSCALL (clock_getres_time64, 2, clock_id, res); - if (ret == 0 || errno != ENOSYS) - return ret; + r = INLINE_SYSCALL_CALL (clock_getres_time64, clock_id, res); + if (r == 0 || errno != ENOSYS) + return r; # endif + /* Fallback code that uses 32-bit support. */ struct timespec ts32; - int retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, &ts32); - if (! retval && res) +# ifdef HAVE_CLOCK_GETRES_VSYSCALL + r = INLINE_VSYSCALL (clock_getres, 2, clock_id, &ts32); +# else + r = INLINE_SYSCALL_CALL (clock_getres, clock_id, &ts32); +# endif + if (r == 0) *res = valid_timespec_to_timespec64 (ts32); - - return retval; + return r; #endif } @@ -60,7 +68,7 @@ __clock_getres (clockid_t clock_id, struct timespec *res) int retval; retval = __clock_getres64 (clock_id, &ts64); - if (! retval && res) + if (retval == 0 && res != NULL) *res = valid_timespec64_to_timespec (ts64); return retval; diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c index 875c4fe905..e895812704 100644 --- a/sysdeps/unix/sysv/linux/clock_gettime.c +++ b/sysdeps/unix/sysv/linux/clock_gettime.c @@ -21,10 +21,6 @@ #include #include #include "kernel-posix-cpu-timers.h" - -#ifdef HAVE_CLOCK_GETTIME_VSYSCALL -# define HAVE_VSYSCALL -#endif #include #include @@ -34,22 +30,34 @@ int __clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp) { #ifdef __ASSUME_TIME64_SYSCALLS -# ifndef __NR_clock_gettime64 -# define __NR_clock_gettime64 __NR_clock_gettime -# define __vdso_clock_gettime64 __vdso_clock_gettime + /* 64 bit ABIs or Newer 32-bit ABIs that only support 64-bit time_t. */ +# ifdef __NR_clock_gettime64 + return INLINE_SYSCALL_CALL (clock_gettime64, clock_id, tp); +# else +# 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 - return INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); #else -# if defined HAVE_CLOCK_GETTIME64_VSYSCALL - int ret64 = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); - if (ret64 == 0 || errno != ENOSYS) - return ret64; + int r; + /* Old 32-bit ABI with possible 64-bit time_t support. */ +# ifdef __NR_clock_gettime64 + r = INLINE_SYSCALL_CALL (clock_gettime64, clock_id, tp); + if (r == 0 || errno != ENOSYS) + return r; # endif + /* Fallback code that uses 32-bit support. */ struct timespec tp32; - int ret = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32); - if (ret == 0) +# ifdef HAVE_CLOCK_GETTIME_VSYSCALL + r = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32); +# else + r = INLINE_SYSCALL_CALL (clock_gettime, clock_id, &tp32); +# endif + if (r == 0) *tp = valid_timespec_to_timespec64 (tp32); - return ret; + return r; #endif } diff --git a/sysdeps/unix/sysv/linux/getcpu.c b/sysdeps/unix/sysv/linux/getcpu.c index fdd27203af..efb4bb7627 100644 --- a/sysdeps/unix/sysv/linux/getcpu.c +++ b/sysdeps/unix/sysv/linux/getcpu.c @@ -18,20 +18,15 @@ #include #include #include - -#ifdef HAVE_GETCPU_VSYSCALL -# define HAVE_VSYSCALL -#endif #include int __getcpu (unsigned int *cpu, unsigned int *node) { -#ifdef __NR_getcpu +#ifdef HAVE_GETCPU_VSYSCALL return INLINE_VSYSCALL (getcpu, 3, cpu, node, NULL); #else - __set_errno (ENOSYS); - return -1; + return INLINE_SYSCALL_CALL (getcpu, cpu, node, NULL); #endif } weak_alias (__getcpu, getcpu) diff --git a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c index 18d8f7cb7a..c40793fe64 100644 --- a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c @@ -17,10 +17,6 @@ #include #include - -#ifdef HAVE_GETTIMEOFDAY_VSYSCALL -# define HAVE_VSYSCALL -#endif #include static int diff --git a/sysdeps/unix/sysv/linux/powerpc/time.c b/sysdeps/unix/sysv/linux/powerpc/time.c index 80a4c73416..f2b4c76be8 100644 --- a/sysdeps/unix/sysv/linux/powerpc/time.c +++ b/sysdeps/unix/sysv/linux/powerpc/time.c @@ -18,10 +18,6 @@ #include #include - -#ifdef HAVE_TIME_VSYSCALL -# define HAVE_VSYSCALL -#endif #include static time_t diff --git a/sysdeps/unix/sysv/linux/sched_getcpu.c b/sysdeps/unix/sysv/linux/sched_getcpu.c index 65dd9fdda7..68ba7f3734 100644 --- a/sysdeps/unix/sysv/linux/sched_getcpu.c +++ b/sysdeps/unix/sysv/linux/sched_getcpu.c @@ -18,22 +18,17 @@ #include #include #include - -#ifdef HAVE_GETCPU_VSYSCALL -# define HAVE_VSYSCALL -#endif #include int sched_getcpu (void) { -#ifdef __NR_getcpu unsigned int cpu; - int r = INLINE_VSYSCALL (getcpu, 3, &cpu, NULL, NULL); - - return r == -1 ? r : cpu; + int r = -1; +#ifdef HAVE_GETCPU_VSYSCALL + r = INLINE_VSYSCALL (getcpu, 3, &cpu, NULL, NULL); #else - __set_errno (ENOSYS); - return -1; + r = INLINE_SYSCALL_CALL (getcpu, &cpu, NULL, NULL); #endif + return r == -1 ? r : cpu; } diff --git a/sysdeps/unix/sysv/linux/sysdep-vdso.h b/sysdeps/unix/sysv/linux/sysdep-vdso.h index cf614fbf8b..76a211e39b 100644 --- a/sysdeps/unix/sysv/linux/sysdep-vdso.h +++ b/sysdeps/unix/sysv/linux/sysdep-vdso.h @@ -20,17 +20,14 @@ # define SYSDEP_VDSO_LINUX_H #include +#include #ifndef INTERNAL_VSYSCALL_CALL # define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \ funcptr (args) #endif -#ifdef HAVE_VSYSCALL - -# include - -# define INLINE_VSYSCALL(name, nr, args...) \ +#define INLINE_VSYSCALL(name, nr, args...) \ ({ \ __label__ out; \ __label__ iserr; \ @@ -59,31 +56,4 @@ sc_ret; \ }) -# define INTERNAL_VSYSCALL(name, err, nr, args...) \ - ({ \ - __label__ out; \ - long v_ret; \ - \ - __typeof (__vdso_##name) vdsop = __vdso_##name; \ - PTR_DEMANGLE (vdsop); \ - if (vdsop != NULL) \ - { \ - v_ret = INTERNAL_VSYSCALL_CALL (vdsop, err, nr, ##args); \ - if (!INTERNAL_SYSCALL_ERROR_P (v_ret, err) \ - || INTERNAL_SYSCALL_ERRNO (v_ret, err) != ENOSYS) \ - goto out; \ - } \ - v_ret = INTERNAL_SYSCALL (name, err, nr, ##args); \ - out: \ - v_ret; \ - }) -#else - -# define INLINE_VSYSCALL(name, nr, args...) \ - INLINE_SYSCALL (name, nr, ##args) -# define INTERNAL_VSYSCALL(name, err, nr, args...) \ - INTERNAL_SYSCALL (name, err, nr, ##args) - -#endif /* USE_VSYSCALL && defined HAVE_VSYSCALL */ - #endif /* SYSDEP_VDSO_LINUX_H */ diff --git a/sysdeps/unix/sysv/linux/x86/gettimeofday.c b/sysdeps/unix/sysv/linux/x86/gettimeofday.c index 190127d31e..8015c40210 100644 --- a/sysdeps/unix/sysv/linux/x86/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/x86/gettimeofday.c @@ -18,10 +18,6 @@ #include #include - -#ifdef HAVE_GETTIMEOFDAY_VSYSCALL -# define HAVE_VSYSCALL -#endif #include static int diff --git a/sysdeps/unix/sysv/linux/x86/time.c b/sysdeps/unix/sysv/linux/x86/time.c index 4a03c46d21..85a9fc8a08 100644 --- a/sysdeps/unix/sysv/linux/x86/time.c +++ b/sysdeps/unix/sysv/linux/x86/time.c @@ -18,16 +18,16 @@ #include #include - -#ifdef HAVE_TIME_VSYSCALL -# define HAVE_VSYSCALL -#endif #include static time_t time_vsyscall (time_t *t) { +#ifdef HAVE_TIME_VSYSCALL return INLINE_VSYSCALL (time, 1, t); +#else + return INLINE_SYSCALL_CALL (time, t); +#endif } #ifdef SHARED