Return-Path: Received: from mail-sn1nam02on0111.outbound.protection.outlook.com ([104.47.36.111]:14488 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932766AbeDIAhM (ORCPT ); Sun, 8 Apr 2018 20:37:12 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Goran Ferenc , Miodrag Dinic , Aleksandar Markovic , Douglas Leung , James Hogan , Paul Burton , Petar Jovanovic , Raghu Gandham , "linux-mips@linux-mips.org" , Ralf Baechle , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 088/162] MIPS: VDSO: Add implementation of clock_gettime() fallback Date: Mon, 9 Apr 2018 00:28:48 +0000 Message-ID: <20180409002738.163941-88-alexander.levin@microsoft.com> References: <20180409002738.163941-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002738.163941-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Goran Ferenc [ Upstream commit 180902e08f051f72c89ffa366f4e4f7a8e9c753e ] This patch adds clock_gettime_fallback() function that wraps assembly invocation of clock_gettime() syscall using __NR_clock_gettime. This function is used if pure VDSO implementation of clock_gettime() does not succeed for any reason. For example, it is called if the clkid parameter of clock_gettime() is not one of the clkids listed in the switch-case block of the function __vdso_clock_gettime() (one such case for clkid is CLOCK_BOOTIME). If syscall invocation via __NR_clock_gettime fails, register a3 will be set. So, after the syscall, register a3 is tested and the return value is negated if it's set. Signed-off-by: Goran Ferenc Signed-off-by: Miodrag Dinic Signed-off-by: Aleksandar Markovic Cc: Douglas Leung Cc: James Hogan Cc: Paul Burton Cc: Petar Jovanovic Cc: Raghu Gandham Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/16639/ Signed-off-by: Ralf Baechle Signed-off-by: Sasha Levin --- arch/mips/vdso/gettimeofday.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/arch/mips/vdso/gettimeofday.c b/arch/mips/vdso/gettimeofday.c index fd7d433970bf..5f6337545ee2 100644 --- a/arch/mips/vdso/gettimeofday.c +++ b/arch/mips/vdso/gettimeofday.c @@ -20,6 +20,24 @@ #include #include =20 +static __always_inline long clock_gettime_fallback(clockid_t _clkid, + struct timespec *_ts) +{ + register struct timespec *ts asm("a1") =3D _ts; + register clockid_t clkid asm("a0") =3D _clkid; + register long ret asm("v0"); + register long nr asm("v0") =3D __NR_clock_gettime; + register long error asm("a3"); + + asm volatile( + " syscall\n" + : "=3Dr" (ret), "=3Dr" (error) + : "r" (clkid), "r" (ts), "r" (nr) + : "memory"); + + return error ? -ret : ret; +} + static __always_inline int do_realtime_coarse(struct timespec *ts, const union mips_vdso_data *data) { @@ -207,7 +225,7 @@ int __vdso_gettimeofday(struct timeval *tv, struct time= zone *tz) int __vdso_clock_gettime(clockid_t clkid, struct timespec *ts) { const union mips_vdso_data *data =3D get_vdso_data(); - int ret; + int ret =3D -1; =20 switch (clkid) { case CLOCK_REALTIME_COARSE: @@ -223,10 +241,11 @@ int __vdso_clock_gettime(clockid_t clkid, struct time= spec *ts) ret =3D do_monotonic(ts, data); break; default: - ret =3D -ENOSYS; break; } =20 - /* If we return -ENOSYS libc should fall back to a syscall. */ + if (ret) + ret =3D clock_gettime_fallback(clkid, ts); + return ret; } --=20 2.15.1