From patchwork Wed Mar 11 03:15:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 45616 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B7075214C2 for ; Wed, 11 Mar 2015 03:19:42 +0000 (UTC) Received: by lams18 with SMTP id s18sf4474141lam.2 for ; Tue, 10 Mar 2015 20:19:41 -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=a2KOI9SeM8SLmG8fVJtlES8CuLG2Edas5TBT56m3+OA=; b=VNuB/rV4MLHeXmDc4p6V7x4y6uF6pdG5hcIAS/lONJWifX14H9VXRu+Zo+NMFT+DtG MPtK052sl+VHcY1BtwvezuYvSxNVFMjo6+DN7Shm1J5rc9qLrHtl66SkSJSi7f1iWjJW P2r/47xiKhFKx0zCb5PlIjycW13oF11T+9HFhKRJOE6PeiRKMc4PaPxj7e1rPZuttKNe YlebhgjeJkMnBnMCtdgaF6ZDEJ9Ndt4+qI3GorShj/wFsO2WopbXI0vWCQFbDoFuZqHb 3eZ4oyLIPkdWN0eWiRSHmgYwEouf5BtyscPVrUk4NH1UVgB0ZS+18pU0Ws48czLCScPk XKEQ== X-Gm-Message-State: ALoCoQk12vGw2BUAUHdH9aMCn2cV9YawDiTWAUkzCa4vI32jj9fIGdOLSrplF5s0oKZLyC7H7S/F X-Received: by 10.112.130.70 with SMTP id oc6mr5262030lbb.13.1426043981717; Tue, 10 Mar 2015 20:19:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.6 with SMTP id v6ls105001laa.13.gmail; Tue, 10 Mar 2015 20:19:41 -0700 (PDT) X-Received: by 10.152.4.136 with SMTP id k8mr32948673lak.103.1426043981407; Tue, 10 Mar 2015 20:19:41 -0700 (PDT) Received: from mail-la0-x232.google.com (mail-la0-x232.google.com. [2a00:1450:4010:c03::232]) by mx.google.com with ESMTPS id z9si1436578lbw.159.2015.03.10.20.19.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Mar 2015 20:19:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::232 as permitted sender) client-ip=2a00:1450:4010:c03::232; Received: by labmn12 with SMTP id mn12so6069611lab.0 for ; Tue, 10 Mar 2015 20:19:41 -0700 (PDT) X-Received: by 10.112.64.193 with SMTP id q1mr33047699lbs.88.1426043981135; Tue, 10 Mar 2015 20:19:41 -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.35.133 with SMTP id h5csp2513040lbj; Tue, 10 Mar 2015 20:19:40 -0700 (PDT) X-Received: by 10.70.0.176 with SMTP id 16mr73825075pdf.78.1426043975813; Tue, 10 Mar 2015 20:19:35 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id va1si4487475pac.83.2015.03.10.20.19.32; Tue, 10 Mar 2015 20:19:35 -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 S1752766AbbCKDTa (ORCPT + 28 others); Tue, 10 Mar 2015 23:19:30 -0400 Received: from m15-112.126.com ([220.181.15.112]:48852 "EHLO m15-112.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752079AbbCKDTV (ORCPT ); Tue, 10 Mar 2015 23:19:21 -0400 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp2 (Coremail) with SMTP id DMmowEAp51Z4s_9UJTpwAw--.1055S4; Wed, 11 Mar 2015 11:17:36 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: rtc-linux@googlegroups.com, Thomas Gleixner , Alessandro Zummo , John Stultz , Arnd Bergmann , linux-omap@vger.kernel.org, Tony Lindgren , linux-tegra@vger.kernel.org, Stephen Warren , linux390@de.ibm.com, Martin Schwidefsky , Ralf Baechle , Arnd Bergmann , Xunlei Pang Subject: [PATCH 2/8] time: Add y2038 safe read_persistent_clock64() Date: Wed, 11 Mar 2015 11:15:09 +0800 Message-Id: <1426043715-22043-3-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426043715-22043-1-git-send-email-xlpang@126.com> References: <1426043715-22043-1-git-send-email-xlpang@126.com> X-CM-TRANSID: DMmowEAp51Z4s_9UJTpwAw--.1055S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxGr4DCr17Ww1fWr1xJFy5Arb_yoWrCFW5p3 yIyw15Gw4UXF1UurnrtasxZw1agwn5ZF47X34fK34SyryjqFn7GFyrC3yYvryDZFyfAa17 ZF40q3WDZw4UZFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jSApnUUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbiJwS5v01sAr9NXAABsp Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: xlpang@126.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::232 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@; dmarc=fail (p=NONE dis=NONE) header.from=126.com 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: , From: Xunlei Pang As part of addressing in-kernel y2038 issues, this patch adds read_persistent_clock64() and replaces all the call sites of read_persistent_clock() with this function. This is a __weak implementation, which simply calls the existing y2038 unsafe read_persistent_clock(). This allows architecture specific implementations to be converted independently, and eventually the y2038 unsafe read_persistent_clock() can be removed after all its architecture specific implementations have been converted to read_persistent_clock64(). Suggested-by: Arnd Bergmann Signed-off-by: Xunlei Pang --- arch/mips/lasat/sysctl.c | 4 ++-- include/linux/timekeeping.h | 1 + kernel/time/timekeeping.c | 22 ++++++++++++---------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/arch/mips/lasat/sysctl.c b/arch/mips/lasat/sysctl.c index 3b7f65c..cf9b4633 100644 --- a/arch/mips/lasat/sysctl.c +++ b/arch/mips/lasat/sysctl.c @@ -75,11 +75,11 @@ static int rtctmp; int proc_dolasatrtc(struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { - struct timespec ts; + struct timespec64 ts; int r; if (!write) { - read_persistent_clock(&ts); + read_persistent_clock64(&ts); rtctmp = ts.tv_sec; /* check for time < 0 and set to 0 */ if (rtctmp < 0) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index d53c522..ff56a0f 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -262,6 +262,7 @@ static inline bool has_persistent_clock(void) } extern void read_persistent_clock(struct timespec *ts); +extern void read_persistent_clock64(struct timespec64 *ts); extern void read_boot_clock(struct timespec *ts); extern void read_boot_clock64(struct timespec64 *ts); extern int update_persistent_clock(struct timespec now); diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 7080c21..0e5a696 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1057,6 +1057,14 @@ void __weak read_persistent_clock(struct timespec *ts) ts->tv_nsec = 0; } +void __weak read_persistent_clock64(struct timespec64 *ts64) +{ + struct timespec ts; + + read_persistent_clock(&ts); + *ts64 = timespec_to_timespec64(ts); +} + /** * read_boot_clock - Return time of the system start. * @@ -1089,10 +1097,8 @@ void __init timekeeping_init(void) struct clocksource *clock; unsigned long flags; struct timespec64 now, boot, tmp; - struct timespec ts; - read_persistent_clock(&ts); - now = timespec_to_timespec64(ts); + read_persistent_clock64(&now); if (!timespec64_valid_strict(&now)) { pr_warn("WARNING: Persistent clock returned invalid value!\n" " Check your CMOS/BIOS settings.\n"); @@ -1163,7 +1169,7 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk, * timekeeping_inject_sleeptime64 - Adds suspend interval to timeekeeping values * @delta: pointer to a timespec64 delta value * - * This hook is for architectures that cannot support read_persistent_clock + * This hook is for architectures that cannot support read_persistent_clock64 * because their RTC/persistent clock is only accessible when irqs are enabled. * * This function should only be called by rtc_resume(), and allows @@ -1210,12 +1216,10 @@ void timekeeping_resume(void) struct clocksource *clock = tk->tkr.clock; unsigned long flags; struct timespec64 ts_new, ts_delta; - struct timespec tmp; cycle_t cycle_now, cycle_delta; bool suspendtime_found = false; - read_persistent_clock(&tmp); - ts_new = timespec_to_timespec64(tmp); + read_persistent_clock64(&ts_new); clockevents_resume(); clocksource_resume(); @@ -1291,10 +1295,8 @@ int timekeeping_suspend(void) unsigned long flags; struct timespec64 delta, delta_delta; static struct timespec64 old_delta; - struct timespec tmp; - read_persistent_clock(&tmp); - timekeeping_suspend_time = timespec_to_timespec64(tmp); + read_persistent_clock64(&timekeeping_suspend_time); /* * On some systems the persistent_clock can not be detected at