Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1298809ybg; Fri, 18 Oct 2019 15:27:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7hLyE6TumTQXq9+O15406VnE4yEGU65A30D4Npt4jCXvEZCQjVy3hTfxzhb0B3zGyLTe7 X-Received: by 2002:a05:6402:3c5:: with SMTP id t5mr12012757edw.125.1571437620540; Fri, 18 Oct 2019 15:27:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571437620; cv=none; d=google.com; s=arc-20160816; b=rW8WjlSgP3lOQWb8XIHz22OMsMTUw3gtMhfUU1vCSXPfhXd3tIXCPovfvVsBy0Hyph lkqZa9XJuwNc2oXjslRvJKMRCdUtCK/rwyI7AePCO1FFC1LXrhQQeJd+zqHeqJgHcQEe xkG4s5Jzz0GiVPP/tE9xWBAkqUJNNd8T6rXDCjuhRJStnaZIikAxIk4G9KH+OlD2ZfGs 5nkXjVvdK42q9d4ZA2YTpFHZRpvenmunnllO1XO2nY6F7Lmg2rI8DSH0Iugc2CmtdNqz DvbxUUmaWtNQTpGH2SaiPiWudTlnOBVPn3P0JoiKAVFVVOrX7TbpZPp1MR0Plj8z+27V vc+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=ucTp4pYNsoXIVC4j9OusGhsOmcXWf7rr6MoAdvFKtu4=; b=f3TDKnPLZ7CI48Q299wv2xZGDioya4SiNr37ZDsaqD5XYA4wapTD5h3zmp4AkAKPa9 I1s9RL/nVdJt2v11uSQcIQ5YjSDzW+kce5RPEmznreoNQIagXFe8wfYLY4LuB5P7uoqk WY8oPy2es/TvN4hRphEHFThittpAPn5lRTZ9CHLz4mzQ3PBKXtgdiCMJ0DSnWTImKfrK K/dAG8Od/HHQEbNg4cQKvEOVIENoM/4otL+6ruvj1gSCWe1etX4XEuN5ojUONeFUgd0E q0/B/tLCWrSpvqCNdpXSEN84rghgpiWvX2I7Mn7XPDpS4+2cHDSB7aPGBOxl4kywZWVb dhIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=CfRbqYmy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v19si4247005eja.352.2019.10.18.15.26.37; Fri, 18 Oct 2019 15:27:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=CfRbqYmy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407144AbfJREz2 (ORCPT + 99 others); Fri, 18 Oct 2019 00:55:28 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:32939 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726103AbfJREz1 (ORCPT ); Fri, 18 Oct 2019 00:55:27 -0400 Received: by mail-pf1-f196.google.com with SMTP id q10so3088576pfl.0; Thu, 17 Oct 2019 21:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=ucTp4pYNsoXIVC4j9OusGhsOmcXWf7rr6MoAdvFKtu4=; b=CfRbqYmycchsM1bJlVBRGEXaNsWo9LlbTr2NcLF7r1E4npsvAZAH5jd4uh3EpePLd5 ufr+cUV7VAX39CfjOthSGrd8LF6VP60ThHzbx7hhKguPAUPX3VFIQ5DSNZjjGtsX8Az9 fyL5HFvwPvE4/BpTzU/czRQaKcUE5AZPsxtj5m6ILQftjNw5CmEbccaSjS4jVzmEtuJS Di6XKPjFXwR4+vVOK5SO4TzIQ/ANsljiFWP8dsFftOju0dwfTqqn18Ivjcq5QCsittKl +OW7o1R7IXY7w2qGgF5hzwCF4gCWh5CxiIRIQWu3jt3XR3GRw7xlxvRbun6FKx6qwgof zSFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=ucTp4pYNsoXIVC4j9OusGhsOmcXWf7rr6MoAdvFKtu4=; b=PD5OLkAOB64o/kBfg44Zlsz9+TtqBM3IlhP5mPNzVJgIOxIuVMqaqjnB+m79JYIJ8U Stng45FZfa8wFObE6C71f/NxmhNSCPG7GAyoLzX1uVFJrugrNQivFlEqxwht8s2dvOo2 psDrt47Kl2mThmjqJ/AWruUgMg3fnGq4cZxRy2dsE4iwTSD2l7lwdaFK7QSS3IFHdZhG RaqLfWRk53Kc+s+DwcWNFPrmMdR0jSYqPfOR1rjxrMQdYgpvls+EBXIIueFr93fzUYuI dtINcsW+vBu7GbBw741rSUxn9KH31IRF821G2nqpV58E8dZctABnyIQjd6NlDb3WqYFh eAAw== X-Gm-Message-State: APjAAAXv+zRIGGoSr22PX6zHzgPQ8LIxfA9GKMkSHgSfvY2aeIb7qsWb t+KnuoWSBPb3ekPoLPoW0xtnrn8h+vg= X-Received: by 2002:a17:90a:80c2:: with SMTP id k2mr8322228pjw.92.1571367467557; Thu, 17 Oct 2019 19:57:47 -0700 (PDT) Received: from software.domain.org ([66.42.68.162]) by smtp.gmail.com with ESMTPSA id a7sm3451692pjv.0.2019.10.17.19.57.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Oct 2019 19:57:46 -0700 (PDT) From: Huacai Chen To: Andy Lutomirski Cc: Thomas Gleixner , Vincenzo Frascino , chenhuacai@gmail.com, linux-kernel@vger.kernel.org, Huacai Chen , stable@vger.kernel.org, Arnd Bergmann , Paul Burton , linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] lib/vdso: Use __arch_use_vsyscall() to indicate fallback Date: Fri, 18 Oct 2019 11:00:19 +0800 Message-Id: <1571367619-13573-1-git-send-email-chenhc@lemote.com> X-Mailer: git-send-email 2.7.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In do_hres(), we currently use whether the return value of __arch_get_ hw_counter() is negtive to indicate fallback, but this is not a good idea. Because: 1, ARM64 returns ULL_MAX but MIPS returns 0 when clock_mode is invalid; 2, For a 64bit counter, a "negtive" value of counter is actually valid. To solve this problem, we use U64_MAX as the only "invalid" return value -- this is still not fully correct, but has no problem in most cases. Moreover, all vdso time-related functions should rely on the return value of __arch_use_vsyscall(), because update_vdso_data() and update_vsyscall_tz() also rely on it. So, in the core functions of __cvdso_gettimeofday(), __cvdso_clock_gettime() and __cvdso_clock_ getres(), if __arch_use_vsyscall() returns false, we use the fallback functions directly. Fixes: 00b26474c2f1613d7ab894c5 ("lib/vdso: Provide generic VDSO implementation") Cc: stable@vger.kernel.org Cc: Arnd Bergmann Cc: Paul Burton Cc: linux-mips@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Huacai Chen --- arch/arm64/include/asm/vdso/vsyscall.h | 2 +- arch/mips/include/asm/vdso/vsyscall.h | 2 +- include/asm-generic/vdso/vsyscall.h | 2 +- lib/vdso/gettimeofday.c | 12 +++++++++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/vdso/vsyscall.h b/arch/arm64/include/asm/vdso/vsyscall.h index 0c731bf..406e6de 100644 --- a/arch/arm64/include/asm/vdso/vsyscall.h +++ b/arch/arm64/include/asm/vdso/vsyscall.h @@ -31,7 +31,7 @@ int __arm64_get_clock_mode(struct timekeeper *tk) #define __arch_get_clock_mode __arm64_get_clock_mode static __always_inline -int __arm64_use_vsyscall(struct vdso_data *vdata) +int __arm64_use_vsyscall(const struct vdso_data *vdata) { return !vdata[CS_HRES_COARSE].clock_mode; } diff --git a/arch/mips/include/asm/vdso/vsyscall.h b/arch/mips/include/asm/vdso/vsyscall.h index 1953147..8b10dd7 100644 --- a/arch/mips/include/asm/vdso/vsyscall.h +++ b/arch/mips/include/asm/vdso/vsyscall.h @@ -29,7 +29,7 @@ int __mips_get_clock_mode(struct timekeeper *tk) #define __arch_get_clock_mode __mips_get_clock_mode static __always_inline -int __mips_use_vsyscall(struct vdso_data *vdata) +int __mips_use_vsyscall(const struct vdso_data *vdata) { return (vdata[CS_HRES_COARSE].clock_mode != VDSO_CLOCK_NONE); } diff --git a/include/asm-generic/vdso/vsyscall.h b/include/asm-generic/vdso/vsyscall.h index e94b1978..ac05a625 100644 --- a/include/asm-generic/vdso/vsyscall.h +++ b/include/asm-generic/vdso/vsyscall.h @@ -26,7 +26,7 @@ static __always_inline int __arch_get_clock_mode(struct timekeeper *tk) #endif /* __arch_get_clock_mode */ #ifndef __arch_use_vsyscall -static __always_inline int __arch_use_vsyscall(struct vdso_data *vdata) +static __always_inline int __arch_use_vsyscall(const struct vdso_data *vdata) { return 1; } diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c index e630e7f..4ad062e 100644 --- a/lib/vdso/gettimeofday.c +++ b/lib/vdso/gettimeofday.c @@ -9,6 +9,7 @@ #include #include #include +#include /* * The generic vDSO implementation requires that gettimeofday.h @@ -50,7 +51,7 @@ static int do_hres(const struct vdso_data *vd, clockid_t clk, cycles = __arch_get_hw_counter(vd->clock_mode); ns = vdso_ts->nsec; last = vd->cycle_last; - if (unlikely((s64)cycles < 0)) + if (unlikely(cycles == U64_MAX)) return -1; ns += vdso_calc_delta(cycles, last, vd->mask, vd->mult); @@ -91,6 +92,9 @@ __cvdso_clock_gettime_common(clockid_t clock, struct __kernel_timespec *ts) if (unlikely((u32) clock >= MAX_CLOCKS)) return -1; + if (!__arch_use_vsyscall(vd)) + return -1; + /* * Convert the clockid to a bitmask and use it to check which * clocks are handled in the VDSO directly. @@ -145,6 +149,9 @@ __cvdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz) { const struct vdso_data *vd = __arch_get_vdso_data(); + if (!__arch_use_vsyscall(vd)) + return gettimeofday_fallback(tv, tz); + if (likely(tv != NULL)) { struct __kernel_timespec ts; @@ -189,6 +196,9 @@ int __cvdso_clock_getres_common(clockid_t clock, struct __kernel_timespec *res) if (unlikely((u32) clock >= MAX_CLOCKS)) return -1; + if (!__arch_use_vsyscall(vd)) + return -1; + hrtimer_res = READ_ONCE(vd[CS_HRES_COARSE].hrtimer_res); /* * Convert the clockid to a bitmask and use it to check which -- 2.7.0