From patchwork Thu Oct 30 11:15:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 39816 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DC60E202FE for ; Thu, 30 Oct 2014 11:17:02 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id l4sf2771479lbv.5 for ; Thu, 30 Oct 2014 04:17:01 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=vVHhodzr+S3bu0zmiasq4ZsyEXTncea25OM1G39jzPs=; b=EQwHOgthW1wFZAERw/QWuIT3LMBs2M8fFUY9/bD0ZqNWkU/dEvFdgxrEuf77k5USNV b2nUjuvmZ1DyCb5+3/qdU5HMkc3YUFneiuIEMps64fXMEx2A5Z+9BtYgRofqV3nHPWTN C/RipTyd5X4jElX85IPaOel7uZzDtS2O82MNqQpb3ktgJZe04w/TW7NZUnuv/JXC0DfR 8EUVrusQcb0BHGXAdcETebuVIJLk11tDQEYYKdpCq07RLp6kvgyYC9we6l4mgQFRisT5 Be4ttSzksHd141oOwZysCs/YCGZkEmbmBnAb3e8y827gmCn/ZraQDq3woxEwSTMbrEij P3WQ== X-Gm-Message-State: ALoCoQlKS6uhuStfhuHNKyRPejDeCeWxtB7zkHDFRImMCjXiqIXA1sCSBq8KJgC2RJli6cdBGiQF X-Received: by 10.180.19.226 with SMTP id i2mr2186512wie.5.1414667821308; Thu, 30 Oct 2014 04:17:01 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.66 with SMTP id h2ls267155laa.58.gmail; Thu, 30 Oct 2014 04:17:01 -0700 (PDT) X-Received: by 10.112.47.37 with SMTP id a5mr18072825lbn.31.1414667820984; Thu, 30 Oct 2014 04:17:00 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id bg6si11542865lbc.42.2014.10.30.04.17.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Oct 2014 04:17:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id f15so4540456lbj.27 for ; Thu, 30 Oct 2014 04:17:00 -0700 (PDT) X-Received: by 10.112.77.74 with SMTP id q10mr17933566lbw.66.1414667820860; Thu, 30 Oct 2014 04:17:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp22306lbz; Thu, 30 Oct 2014 04:16:59 -0700 (PDT) X-Received: by 10.70.37.8 with SMTP id u8mr16826721pdj.9.1414667819018; Thu, 30 Oct 2014 04:16:59 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id of4si6365876pbc.79.2014.10.30.04.16.57 for ; Thu, 30 Oct 2014 04:16:59 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759301AbaJ3LQy (ORCPT + 26 others); Thu, 30 Oct 2014 07:16:54 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:47498 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759182AbaJ3LQx (ORCPT ); Thu, 30 Oct 2014 07:16:53 -0400 Received: by mail-pa0-f43.google.com with SMTP id eu11so5282691pac.2 for ; Thu, 30 Oct 2014 04:16:52 -0700 (PDT) X-Received: by 10.70.34.175 with SMTP id a15mr16488060pdj.123.1414667812620; Thu, 30 Oct 2014 04:16:52 -0700 (PDT) Received: from wangdeqiang.com ([210.21.227.66]) by mx.google.com with ESMTPSA id i10sm6874826pdr.21.2014.10.30.04.16.47 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Oct 2014 04:16:52 -0700 (PDT) From: "pang.xunlei" To: linux-kernel@vger.kernel.org Cc: rtc-linux@googlegroups.com, xen-devel@lists.xenproject.org, John Stultz , Thomas Gleixner , Alessandro Zummo , Stefano Stabellini , "pang.xunlei" Subject: [RFC PATCH v2 01/11] time: Add do_settimeofday64() safe version(using timespec64) Date: Thu, 30 Oct 2014 19:15:35 +0800 Message-Id: <1414667745-7703-2-git-send-email-pang.xunlei@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1414667745-7703-1-git-send-email-pang.xunlei@linaro.org> References: <1414667745-7703-1-git-send-email-pang.xunlei@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pang.xunlei@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.217.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The kernel uses 32-bit signed value(time_t) for seconds elapsed 1970-01-01:00:00:00, thus it will overflow at 2038-01-19 03:14:08 on 32-bit systems. We call this "2038 safety" issue. As part of addressing 2038 saftey for in-kernel uses, this patch adds safe do_settimeofday64() using timespec64. After this patch, do_settimeofday() should be replaced by do_settimeofday64() one by one. Eventually, do_settimeofday() will be removed from the kernel when it has no users. Signed-off-by: pang.xunlei --- include/linux/timekeeping.h | 1 + kernel/time/timekeeping.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 1caa6b0..afc61c3 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -10,6 +10,7 @@ extern int timekeeping_suspended; * Get and set timeofday */ extern void do_gettimeofday(struct timeval *tv); +extern int do_settimeofday64(const struct timespec64 *ts); extern int do_settimeofday(const struct timespec *tv); extern int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz); diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index ec1791f..f0dcbc0 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -703,18 +703,19 @@ void do_gettimeofday(struct timeval *tv) EXPORT_SYMBOL(do_gettimeofday); /** - * do_settimeofday - Sets the time of day - * @tv: pointer to the timespec variable containing the new time + * do_settimeofday64 - Sets the time of day + * @ts: pointer to the timespec64 variable containing the new time * * Sets the time of day to the new time and update NTP and notify hrtimers + * Safe version for 2038 safety. */ -int do_settimeofday(const struct timespec *tv) +int do_settimeofday64(const struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; - struct timespec64 ts_delta, xt, tmp; + struct timespec64 ts_delta, xt; unsigned long flags; - if (!timespec_valid_strict(tv)) + if (!timespec64_valid_strict(ts)) return -EINVAL; raw_spin_lock_irqsave(&timekeeper_lock, flags); @@ -723,13 +724,12 @@ int do_settimeofday(const struct timespec *tv) timekeeping_forward_now(tk); xt = tk_xtime(tk); - ts_delta.tv_sec = tv->tv_sec - xt.tv_sec; - ts_delta.tv_nsec = tv->tv_nsec - xt.tv_nsec; + ts_delta.tv_sec = ts->tv_sec - xt.tv_sec; + ts_delta.tv_nsec = ts->tv_nsec - xt.tv_nsec; tk_set_wall_to_mono(tk, timespec64_sub(tk->wall_to_monotonic, ts_delta)); - tmp = timespec_to_timespec64(*tv); - tk_set_xtime(tk, &tmp); + tk_set_xtime(tk, ts); timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET); @@ -741,6 +741,22 @@ int do_settimeofday(const struct timespec *tv) return 0; } +EXPORT_SYMBOL(do_settimeofday64); + +/** + * do_settimeofday - Sets the time of day + * @tv: pointer to the timespec variable containing the new time + * + * Sets the time of day to the new time and update NTP and notify hrtimers + * TODO: [2038 safety] should be replaced by do_settimeofday64(). + */ +int do_settimeofday(const struct timespec *tv) +{ + struct timespec64 ts64; + + ts64 = timespec_to_timespec64(*tv); + return do_settimeofday64(&ts64); +} EXPORT_SYMBOL(do_settimeofday); /**