linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chen Yu <yu.c.chen@intel.com>
To: linux-pm@vger.kernel.org
Cc: Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org, Chen Yu <yu.c.chen@intel.com>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	John Stultz <john.stultz@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Xunlei Pang <xlpang@redhat.com>, Zhang Rui <rui.zhang@intel.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH][RFC v4] timekeeping: ignore the bogus sleep time if pm_trace is enabled
Date: Thu, 18 Aug 2016 18:43:39 +0800	[thread overview]
Message-ID: <1471517019-15216-1-git-send-email-yu.c.chen@intel.com> (raw)

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, please refer to:
https://patchwork.kernel.org/patch/9286365/
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.

So this patch ignores the sleep time if pm_trace is enabled in
the following situation:
1. rtc is used as persist clock to compensate for sleep time,
   (because system does not have a nonstop clocksource) or
2. rtc is used to calculate the sleep time in rtc_resume.

Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Xunlei Pang <xlpang@redhat.com>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-pm@vger.kernel.org
Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reported-by: Janek Kozicki <cosurgi@gmail.com>
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
---
 arch/x86/kernel/rtc.c     |  7 +++++++
 kernel/time/timekeeping.c | 14 +++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c
index 79c6311c..6039138 100644
--- a/arch/x86/kernel/rtc.c
+++ b/arch/x86/kernel/rtc.c
@@ -8,6 +8,7 @@
 #include <linux/export.h>
 #include <linux/pnp.h>
 #include <linux/of.h>
+#include <linux/pm-trace.h>
 
 #include <asm/vsyscall.h>
 #include <asm/x86_init.h>
@@ -146,6 +147,12 @@ void read_persistent_clock(struct timespec *ts)
 	x86_platform.get_wallclock(ts);
 }
 
+bool persistent_clock_is_usable(void)
+{
+	/* Unusable if pm_trace is enabled. */
+	return !((x86_platform.get_wallclock == mach_get_cmos_time) &&
+		 pm_trace_is_enabled());
+}
 
 static struct resource rtc_resources[] = {
 	[0] = {
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 3b65746..3122bd2b 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -23,6 +23,7 @@
 #include <linux/stop_machine.h>
 #include <linux/pvclock_gtod.h>
 #include <linux/compiler.h>
+#include <linux/pm-trace.h>
 
 #include "tick-internal.h"
 #include "ntp_internal.h"
@@ -1450,6 +1451,11 @@ void __weak read_boot_clock64(struct timespec64 *ts)
 	ts->tv_nsec = 0;
 }
 
+bool __weak persistent_clock_is_usable(void)
+{
+	return true;
+}
+
 /* Flag for if timekeeping_resume() has injected sleeptime */
 static bool sleeptime_injected;
 
@@ -1551,7 +1557,7 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
  */
 bool timekeeping_rtc_skipresume(void)
 {
-	return sleeptime_injected;
+	return sleeptime_injected || pm_trace_is_enabled();
 }
 
 /**
@@ -1662,6 +1668,12 @@ void timekeeping_resume(void)
 	} else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) {
 		ts_delta = timespec64_sub(ts_new, timekeeping_suspend_time);
 		sleeptime_injected = true;
+		/*
+		 * If rtc is used as persist clock thus it
+		 * would be bogus when pm_trace is enabled.
+		 */
+		if (!persistent_clock_is_usable())
+			sleeptime_injected = false;
 	}
 
 	if (sleeptime_injected)
-- 
2.7.4


             reply	other threads:[~2016-08-18 10:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-18 10:43 Chen Yu [this message]
2016-08-18 10:36 ` [PATCH][RFC v4] timekeeping: ignore the bogus sleep time if pm_trace is enabled Oliver Neukum
2016-08-18 11:04   ` Xunlei Pang
2016-08-18 11:24   ` Chen Yu
2016-08-27  7:08 ` Xunlei Pang
2016-08-28  1:57   ` Chen Yu
2016-08-28  8:28   ` Chen Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471517019-15216-1-git-send-email-yu.c.chen@intel.com \
    --to=yu.c.chen@intel.com \
    --cc=hpa@zytor.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rjw@rjwysocki.net \
    --cc=rui.zhang@intel.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=xlpang@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).