From patchwork Mon Aug 17 20:40:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 52479 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id BF3BF2156D for ; Mon, 17 Aug 2015 20:41:19 +0000 (UTC) Received: by labd1 with SMTP id d1sf50753195lab.0 for ; Mon, 17 Aug 2015 13:41:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=kRMLANWlRZ9QyPNhOxJGSrQ88iGweW8pJvHUXvcNIKw=; b=X8du9RAedhUGtzEMegFVmbF4muqUsvzcep8s7YwdX4MPamHfAODtLqtr4lfWX/6aCs CiWx+Ed2f7CDNxzwVkhhINB4wus5T7v3IV3rHMj2+tL81KYWW/G7Rv+D+O6wMU/SiNOK nheqz/sr+q9BTLxdLtSnBtIzpd7FpY9NxQS8cz0QYtMxDYdZlnAOC99KLXhgw0jFkR3r MwWZ5bdnz2q8wLsUoz57i/Qwb/JlswFE3yq54x7+NLZ5T+zTOdZB5ayGa/idP2b4XzX1 N1ZI3JHgBagdt3Fq/mhQjK8VJbddNZ8nq5gx1FR7+4kxvQobRjtdAig0DdmNL5czCV/j F5RA== X-Gm-Message-State: ALoCoQlEIOUls8848oX7yR15Vqeouz9c3Zs8jn2H5wMlMKpJV2xrohdwbkRhUCnwcGRGbH7Bqe6G X-Received: by 10.152.9.99 with SMTP id y3mr799248laa.10.1439844078737; Mon, 17 Aug 2015 13:41:18 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.110 with SMTP id v14ls684652lal.19.gmail; Mon, 17 Aug 2015 13:41:18 -0700 (PDT) X-Received: by 10.112.17.70 with SMTP id m6mr2625674lbd.113.1439844078584; Mon, 17 Aug 2015 13:41:18 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id l5si12378712lam.36.2015.08.17.13.41.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Aug 2015 13:41:18 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lagz9 with SMTP id z9so86826511lag.3 for ; Mon, 17 Aug 2015 13:41:18 -0700 (PDT) X-Received: by 10.112.125.34 with SMTP id mn2mr2348522lbb.76.1439844078476; Mon, 17 Aug 2015 13:41:18 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.162.200 with SMTP id yc8csp85888lbb; Mon, 17 Aug 2015 13:41:17 -0700 (PDT) X-Received: by 10.68.181.34 with SMTP id dt2mr5977300pbc.7.1439844073084; Mon, 17 Aug 2015 13:41:13 -0700 (PDT) Received: from mail-pa0-f50.google.com (mail-pa0-f50.google.com. [209.85.220.50]) by mx.google.com with ESMTPS id ir7si26240802pbc.206.2015.08.17.13.41.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Aug 2015 13:41:13 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.50 as permitted sender) client-ip=209.85.220.50; Received: by pawq9 with SMTP id q9so18141214paw.3 for ; Mon, 17 Aug 2015 13:41:12 -0700 (PDT) X-Received: by 10.68.116.142 with SMTP id jw14mr6090258pbb.147.1439844072000; Mon, 17 Aug 2015 13:41:12 -0700 (PDT) Received: from localhost.localdomain (c-76-115-103-22.hsd1.or.comcast.net. [76.115.103.22]) by smtp.gmail.com with ESMTPSA id gu2sm85199pbc.1.2015.08.17.13.41.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Aug 2015 13:41:11 -0700 (PDT) From: John Stultz To: lkml Cc: Wang YanQing , Prarit Bhargava , Richard Cochran , Ingo Molnar , Thomas Gleixner , John Stultz Subject: [PATCH 3/9] time: Always make sure wall_to_monotonic isn't positive Date: Mon, 17 Aug 2015 13:40:57 -0700 Message-Id: <1439844063-7957-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1439844063-7957-1-git-send-email-john.stultz@linaro.org> References: <1439844063-7957-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Wang YanQing Two issues were found on an IMX6 development board without an enabled RTC device(resulting in the boot time and monotonic time being initialized to 0). Issue 1:exportfs -a generate: "exportfs: /opt/nfs/arm does not support NFS export" Issue 2:cat /proc/stat: "btime 4294967236" The same issues can be reproduced on x86 after running the following code: int main(void) { struct timeval val; int ret; val.tv_sec = 0; val.tv_usec = 0; ret = settimeofday(&val, NULL); return 0; } Two issues are different symptoms of same problem: The reason is a positive wall_to_monotonic pushes boot time back to the time before Epoch, and getboottime will return negative value. In symptom 1: negative boot time cause get_expiry() to overflow time_t when input expire time is 2147483647, then cache_flush() always clears entries just added in ip_map_parse. In symptom 2: show_stat() uses "unsigned long" to print negative btime value returned by getboottime. This patch fix the problem by prohibiting time from being set to a value which would cause a negative boot time. As a result one can't set the CLOCK_REALTIME time prior to (1970 + system uptime). Cc: Prarit Bhargava Cc: Richard Cochran Cc: Ingo Molnar Cc: Thomas Gleixner Signed-off-by: Wang YanQing [jstultz: reworded commit message] Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index bca3667..4cdb771 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -911,6 +911,7 @@ int do_settimeofday64(const struct timespec64 *ts) struct timekeeper *tk = &tk_core.timekeeper; struct timespec64 ts_delta, xt; unsigned long flags; + int ret = 0; if (!timespec64_valid_strict(ts)) return -EINVAL; @@ -924,10 +925,15 @@ int do_settimeofday64(const struct timespec64 *ts) ts_delta.tv_sec = ts->tv_sec - xt.tv_sec; ts_delta.tv_nsec = ts->tv_nsec - xt.tv_nsec; + if (timespec64_compare(&tk->wall_to_monotonic, &ts_delta) > 0) { + ret = -EINVAL; + goto out; + } + tk_set_wall_to_mono(tk, timespec64_sub(tk->wall_to_monotonic, ts_delta)); tk_set_xtime(tk, ts); - +out: timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET); write_seqcount_end(&tk_core.seq); @@ -936,7 +942,7 @@ int do_settimeofday64(const struct timespec64 *ts) /* signal hrtimers about time change */ clock_was_set(); - return 0; + return ret; } EXPORT_SYMBOL(do_settimeofday64); @@ -965,7 +971,8 @@ int timekeeping_inject_offset(struct timespec *ts) /* Make sure the proposed value is valid */ tmp = timespec64_add(tk_xtime(tk), ts64); - if (!timespec64_valid_strict(&tmp)) { + if (timespec64_compare(&tk->wall_to_monotonic, &ts64) > 0 || + !timespec64_valid_strict(&tmp)) { ret = -EINVAL; goto error; }