From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932484AbcKHIxk (ORCPT ); Tue, 8 Nov 2016 03:53:40 -0500 Received: from mga01.intel.com ([192.55.52.88]:42347 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753502AbcKHIxg (ORCPT ); Tue, 8 Nov 2016 03:53:36 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,609,1473145200"; d="scan'208";a="898956876" From: Chen Yu To: x86@kernel.org Cc: Pavel Machek , Ingo Molnar , "H. Peter Anvin" , linux-pm@vger.kernel.org, rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, Thomas Gleixner , "Rafael J. Wysocki" , Len Brown , John Stultz , Xunlei Pang , Chen Yu Subject: [PATCH 1/2][RFC v6] timekeeping: Ignore the bogus sleep time if pm_trace is enabled Date: Tue, 8 Nov 2016 17:01:35 +0800 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner Previously we encountered some memory overflow issues due to the bogus sleep time brought by inconsistent rtc, which is triggered when pm_trace is enabled, and we have fixed it in recent kernel. However it's improper in the first place to call __timekeeping_inject_sleeptime() in case that pm_trace is enabled simply because that "hash" time value will wreckage the timekeeping subsystem. This patch is to bypass the bogus rtc interval when pm_trace is enabled. Cc: Thomas Gleixner Cc: "Rafael J. Wysocki" Cc: Len Brown Cc: John Stultz Cc: Xunlei Pang Signed-off-by: Chen Yu --- arch/x86/kernel/rtc.c | 9 +++++++++ drivers/base/power/trace.c | 2 ++ drivers/rtc/rtc-cmos.c | 7 +++++++ include/linux/mc146818rtc.h | 1 + include/linux/pm-trace.h | 9 ++++++++- 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c index 79c6311c..898383c 100644 --- a/arch/x86/kernel/rtc.c +++ b/arch/x86/kernel/rtc.c @@ -64,6 +64,15 @@ void mach_get_cmos_time(struct timespec *now) unsigned int status, year, mon, day, hour, min, sec, century = 0; unsigned long flags; + /* + * If pm trace abused the RTC as storage set the timespec to 0 + * which tells the caller that this RTC value is bogus. + */ + if (!pm_trace_rtc_valid()) { + now->tv_sec = now->tv_nsec = 0; + return; + } + spin_lock_irqsave(&rtc_lock, flags); /* diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c index efec10b..aa9109a 100644 --- a/drivers/base/power/trace.c +++ b/drivers/base/power/trace.c @@ -74,6 +74,7 @@ #define DEVSEED (7919) +bool pm_trace_rtc_abused __read_mostly; static unsigned int dev_hash_value; static int set_magic_time(unsigned int user, unsigned int file, unsigned int device) @@ -104,6 +105,7 @@ static int set_magic_time(unsigned int user, unsigned int file, unsigned int dev time.tm_min = (n % 20) * 3; n /= 20; mc146818_set_time(&time); + pm_trace_rtc_abused = true; return n ? -1 : 0; } diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index dd3d598..3d9aedc 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -191,6 +191,13 @@ static inline void cmos_write_bank2(unsigned char val, unsigned char addr) static int cmos_read_time(struct device *dev, struct rtc_time *t) { + /* + * If pmtrace abused the RTC for storage tell the caller that it is + * unusable. + */ + if (!pm_trace_rtc_valid()) + return -EIO; + /* REVISIT: if the clock has a "century" register, use * that instead of the heuristic in mc146818_get_time(). * That'll make Y3K compatility (year > 2070) easy! diff --git a/include/linux/mc146818rtc.h b/include/linux/mc146818rtc.h index a585b4b..0661af1 100644 --- a/include/linux/mc146818rtc.h +++ b/include/linux/mc146818rtc.h @@ -16,6 +16,7 @@ #include /* register access macros */ #include #include +#include #ifdef __KERNEL__ #include /* spinlock_t */ diff --git a/include/linux/pm-trace.h b/include/linux/pm-trace.h index ecbde7a..7b78793 100644 --- a/include/linux/pm-trace.h +++ b/include/linux/pm-trace.h @@ -1,11 +1,17 @@ #ifndef PM_TRACE_H #define PM_TRACE_H +#include #ifdef CONFIG_PM_TRACE #include -#include extern int pm_trace_enabled; +extern bool pm_trace_rtc_abused; + +static inline bool pm_trace_rtc_valid(void) +{ + return !pm_trace_rtc_abused; +} static inline int pm_trace_is_enabled(void) { @@ -24,6 +30,7 @@ extern int show_trace_dev_match(char *buf, size_t size); #else +static inline bool pm_trace_rtc_valid(void) { return true; } static inline int pm_trace_is_enabled(void) { return 0; } #define TRACE_DEVICE(dev) do { } while (0) -- 2.7.4