Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1471388 > unrolled thread
| Started by | Chen Yu <yu.c.chen@intel.com> |
|---|---|
| First post | 2016-08-28 18:40 +0200 |
| Last post | 2016-09-09 07:40 +0200 |
| Articles | 6 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH][RFC v5] timekeeping: Ignore the bogus sleep time if pm_trace is enabled Chen Yu <yu.c.chen@intel.com> - 2016-08-28 18:40 +0200
Re: [PATCH][RFC v5] timekeeping: Ignore the bogus sleep time if pm_trace is enabled "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2016-08-31 02:30 +0200
Re: [PATCH][RFC v5] timekeeping: Ignore the bogus sleep time if pm_trace is enabled Thomas Gleixner <tglx@linutronix.de> - 2016-09-02 21:30 +0200
Re: [PATCH][RFC v5] timekeeping: Ignore the bogus sleep time if pm_trace is enabled Chen Yu <yu.c.chen@intel.com> - 2016-09-04 17:30 +0200
Re: [PATCH][RFC v5] timekeeping: Ignore the bogus sleep time if pm_trace is enabled Thomas Gleixner <tglx@linutronix.de> - 2016-09-05 10:00 +0200
Re: [PATCH][RFC v5] timekeeping: Ignore the bogus sleep time if pm_trace is enabled Chen Yu <yu.c.chen@intel.com> - 2016-09-09 07:40 +0200
| From | Chen Yu <yu.c.chen@intel.com> |
|---|---|
| Date | 2016-08-28 18:40 +0200 |
| Subject | [PATCH][RFC v5] timekeeping: Ignore the bogus sleep time if pm_trace is enabled |
| Message-ID | <sbbhL-44E-5@gated-at.bofh.it> |
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.
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,
or
2. rtc is used to calculate the sleep time in rtc_resume.
Cc: stable@vger.kernel.org (3.17+)
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: Xunlei Pang <xlpang@redhat.com>
Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Reported-by: Janek Kozicki <cosurgi@gmail.com>
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
---
arch/x86/kernel/rtc.c | 12 ++++++++++++
kernel/time/timekeeping.c | 3 ++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c
index 79c6311c..5c28197 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>
@@ -144,6 +145,17 @@ int update_persistent_clock(struct timespec now)
void read_persistent_clock(struct timespec *ts)
{
x86_platform.get_wallclock(ts);
+
+ /*
+ * Make rtc-based persistent clock unusable
+ * if pm_trace is enabled, only take effect
+ * for timekeeping_suspend/resume.
+ */
+ if (pm_trace_is_enabled() &&
+ x86_platform.get_wallclock == mach_get_cmos_time) {
+ ts->tv_sec = 0;
+ ts->tv_nsec = 0;
+ }
}
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 3b65746..9af885d 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"
@@ -1551,7 +1552,7 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
*/
bool timekeeping_rtc_skipresume(void)
{
- return sleeptime_injected;
+ return sleeptime_injected || pm_trace_is_enabled();
}
/**
--
2.7.4
[toc] | [next] | [standalone]
| From | "Rafael J. Wysocki" <rjw@rjwysocki.net> |
|---|---|
| Date | 2016-08-31 02:30 +0200 |
| Message-ID | <sc1zH-3CS-7@gated-at.bofh.it> |
| In reply to | #1471388 |
On Monday, August 29, 2016 12:40:39 AM Chen Yu wrote:
> 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.
>
> 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,
> or
> 2. rtc is used to calculate the sleep time in rtc_resume.
>
> Cc: stable@vger.kernel.org (3.17+)
> 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: Xunlei Pang <xlpang@redhat.com>
> Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Suggested-by: Thomas Gleixner <tglx@linutronix.de>
> Reported-by: Janek Kozicki <cosurgi@gmail.com>
> Signed-off-by: Chen Yu <yu.c.chen@intel.com>
> ---
> arch/x86/kernel/rtc.c | 12 ++++++++++++
> kernel/time/timekeeping.c | 3 ++-
> 2 files changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c
> index 79c6311c..5c28197 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>
> @@ -144,6 +145,17 @@ int update_persistent_clock(struct timespec now)
> void read_persistent_clock(struct timespec *ts)
> {
> x86_platform.get_wallclock(ts);
> +
> + /*
> + * Make rtc-based persistent clock unusable
> + * if pm_trace is enabled, only take effect
> + * for timekeeping_suspend/resume.
> + */
> + if (pm_trace_is_enabled() &&
> + x86_platform.get_wallclock == mach_get_cmos_time) {
> + ts->tv_sec = 0;
> + ts->tv_nsec = 0;
> + }
I'm not sure about this. Looks hackish.
> }
>
>
> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> index 3b65746..9af885d 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"
> @@ -1551,7 +1552,7 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
> */
> bool timekeeping_rtc_skipresume(void)
> {
> - return sleeptime_injected;
> + return sleeptime_injected || pm_trace_is_enabled();
> }
>
> /**
Thanks,
Rafael
[toc] | [prev] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2016-09-02 21:30 +0200 |
| Subject | Re: [PATCH][RFC v5] timekeeping: Ignore the bogus sleep time if pm_trace is enabled |
| Message-ID | <sd2k1-3y8-11@gated-at.bofh.it> |
| In reply to | #1472959 |
On Wed, 31 Aug 2016, Rafael J. Wysocki wrote:
> On Monday, August 29, 2016 12:40:39 AM Chen Yu wrote:
> > +
> > + /*
> > + * Make rtc-based persistent clock unusable
> > + * if pm_trace is enabled, only take effect
> > + * for timekeeping_suspend/resume.
> > + */
> > + if (pm_trace_is_enabled() &&
> > + x86_platform.get_wallclock == mach_get_cmos_time) {
> > + ts->tv_sec = 0;
> > + ts->tv_nsec = 0;
> > + }
>
> I'm not sure about this. Looks hackish.
Indeed. Can't you just keep track that pm_trace fiddled with the cmos clock
and then discard the value either in the core or in mach_get_cmos_time()
Thanks,
tglx
[toc] | [prev] | [next] | [standalone]
| From | Chen Yu <yu.c.chen@intel.com> |
|---|---|
| Date | 2016-09-04 17:30 +0200 |
| Subject | Re: [PATCH][RFC v5] timekeeping: Ignore the bogus sleep time if pm_trace is enabled |
| Message-ID | <sdHwS-7uQ-17@gated-at.bofh.it> |
| In reply to | #1475418 |
Hi Thomas, Rafael,
On Fri, Sep 02, 2016 at 09:26:51PM +0200, Thomas Gleixner wrote:
> On Wed, 31 Aug 2016, Rafael J. Wysocki wrote:
> > On Monday, August 29, 2016 12:40:39 AM Chen Yu wrote:
> > > +
> > > + /*
> > > + * Make rtc-based persistent clock unusable
> > > + * if pm_trace is enabled, only take effect
> > > + * for timekeeping_suspend/resume.
> > > + */
> > > + if (pm_trace_is_enabled() &&
> > > + x86_platform.get_wallclock == mach_get_cmos_time) {
> > > + ts->tv_sec = 0;
> > > + ts->tv_nsec = 0;
> > > + }
> >
> > I'm not sure about this. Looks hackish.
>
> Indeed. Can't you just keep track that pm_trace fiddled with the cmos clock
> and then discard the value either in the core or in mach_get_cmos_time()
The previous version is more straightforward, since
it ignored the bogus rtc in core. Would you please take
a glance at it too, thanks:
https://patchwork.kernel.org/patch/9287347/
Thanks,
Yu
[toc] | [prev] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2016-09-05 10:00 +0200 |
| Subject | Re: [PATCH][RFC v5] timekeeping: Ignore the bogus sleep time if pm_trace is enabled |
| Message-ID | <sdWYW-N5-17@gated-at.bofh.it> |
| In reply to | #1475957 |
On Sun, 4 Sep 2016, Chen Yu wrote:
> Hi Thomas, Rafael,
> On Fri, Sep 02, 2016 at 09:26:51PM +0200, Thomas Gleixner wrote:
> > On Wed, 31 Aug 2016, Rafael J. Wysocki wrote:
> > > On Monday, August 29, 2016 12:40:39 AM Chen Yu wrote:
> > > > +
> > > > + /*
> > > > + * Make rtc-based persistent clock unusable
> > > > + * if pm_trace is enabled, only take effect
> > > > + * for timekeeping_suspend/resume.
> > > > + */
> > > > + if (pm_trace_is_enabled() &&
> > > > + x86_platform.get_wallclock == mach_get_cmos_time) {
> > > > + ts->tv_sec = 0;
> > > > + ts->tv_nsec = 0;
> > > > + }
> > >
> > > I'm not sure about this. Looks hackish.
> >
> > Indeed. Can't you just keep track that pm_trace fiddled with the cmos clock
> > and then discard the value either in the core or in mach_get_cmos_time()
> The previous version is more straightforward, since
> it ignored the bogus rtc in core. Would you please take
> a glance at it too, thanks:
> https://patchwork.kernel.org/patch/9287347/
This is the same hackery just different:
> +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());
> +}
I really have no idea why this is burried in x86 land. The pm_trace hackery
issues mc146818_set_time() to fiddle with the RTC. So any implementation of
this is affected.
So that very piece of pmtrace code should keep track of the wreckage it did
to the RTC and provide the fact to the core timekeeping code which can then
skip the update.
Thanks,
tglx
[toc] | [prev] | [next] | [standalone]
| From | Chen Yu <yu.c.chen@intel.com> |
|---|---|
| Date | 2016-09-09 07:40 +0200 |
| Subject | Re: [PATCH][RFC v5] timekeeping: Ignore the bogus sleep time if pm_trace is enabled |
| Message-ID | <sfmHD-7kc-1@gated-at.bofh.it> |
| In reply to | #1476171 |
Hi,
On Mon, Sep 05, 2016 at 01:54:20AM -0600, Thomas Gleixner wrote:
> On Sun, 4 Sep 2016, Chen Yu wrote:
> > Hi Thomas, Rafael,
> > On Fri, Sep 02, 2016 at 09:26:51PM +0200, Thomas Gleixner wrote:
> > > On Wed, 31 Aug 2016, Rafael J. Wysocki wrote:
> > > > On Monday, August 29, 2016 12:40:39 AM Chen Yu wrote:
> > > > > +
> > > > > + /*
> > > > > + * Make rtc-based persistent clock unusable
> > > > > + * if pm_trace is enabled, only take effect
> > > > > + * for timekeeping_suspend/resume.
> > > > > + */
> > > > > + if (pm_trace_is_enabled() &&
> > > > > + x86_platform.get_wallclock == mach_get_cmos_time) {
> > > > > + ts->tv_sec = 0;
> > > > > + ts->tv_nsec = 0;
> > > > > + }
> > > >
> > > > I'm not sure about this. Looks hackish.
> > >
> > > Indeed. Can't you just keep track that pm_trace fiddled with the cmos clock
> > > and then discard the value either in the core or in mach_get_cmos_time()
> > The previous version is more straightforward, since
> > it ignored the bogus rtc in core. Would you please take
> > a glance at it too, thanks:
> > https://patchwork.kernel.org/patch/9287347/
>
> This is the same hackery just different:
>
> > +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());
> > +}
>
> I really have no idea why this is burried in x86 land. The pm_trace hackery
> issues mc146818_set_time() to fiddle with the RTC. So any implementation of
> this is affected.
OK, I've changed this patch according to this suggestion.
Previously I tried to deal with the case that x86 uses
RTC-CMOS as its presistent clock, not kvm_clock, nor
other get_wallclock, and this seems only be related to x86.
So this piece of code looks hackish.
>
> So that very piece of pmtrace code should keep track of the wreckage it did
> to the RTC and provide the fact to the core timekeeping code which can then
> skip the update.
>
OK. I've moved most of the logic into the pm_trace component,
Once the mc146818_set_time has modified the RTC by pm_trace,
related flags will be set which indicates the unusable of RTC.
And timekeeping system is able to query these flags to decide whether
it should inject the sleep time. (We tried to make this patch as
simple as possible, but it looks like we have to deal with persistent
clock for x86, which makes this patch a little more complicated).
Here's the trial version of it, any suggestion would be appreciated:
Index: linux/drivers/base/power/trace.c
===================================================================
--- linux.orig/drivers/base/power/trace.c
+++ linux/drivers/base/power/trace.c
@@ -75,6 +75,27 @@
#define DEVSEED (7919)
static unsigned int dev_hash_value;
+unsigned int timekeeping_tainted;
+
+/* Is the persistent clock effected by pm_trace? */
+int __weak arch_pm_trace_taint_pclock(void)
+{
+ return 0;
+}
+
+void pm_trace_untaint_timekeeping(void)
+{
+ timekeeping_tainted = 0;
+}
+
+void pm_trace_taint_timekeeping(void)
+{
+ if (pm_trace_is_enabled()) {
+ timekeeping_tainted |= TIMEKEEPING_RTC_TAINTED;
+ if (arch_pm_trace_taint_pclock())
+ timekeeping_tainted |= TIMEKEEPING_PERSISTENT_CLOCK_TAINTED;
+ }
+}
static int set_magic_time(unsigned int user, unsigned int file, unsigned int device)
{
@@ -104,6 +125,7 @@ static int set_magic_time(unsigned int u
time.tm_min = (n % 20) * 3;
n /= 20;
mc146818_set_time(&time);
+ pm_trace_taint_timekeeping();
return n ? -1 : 0;
}
Index: linux/kernel/power/main.c
===================================================================
--- linux.orig/kernel/power/main.c
+++ linux/kernel/power/main.c
@@ -548,6 +548,7 @@ pm_trace_store(struct kobject *kobj, str
if (sscanf(buf, "%d", &val) == 1) {
pm_trace_enabled = !!val;
if (pm_trace_enabled) {
+ pm_trace_untaint_timekeeping();
pr_warn("PM: Enabling pm_trace changes system date and time during resume.\n"
"PM: Correct system time has to be restored manually after resume.\n");
}
Index: linux/include/linux/pm-trace.h
===================================================================
--- linux.orig/include/linux/pm-trace.h
+++ linux/include/linux/pm-trace.h
@@ -1,10 +1,14 @@
#ifndef PM_TRACE_H
#define PM_TRACE_H
+#define TIMEKEEPING_RTC_TAINTED 0x1
+#define TIMEKEEPING_PERSISTENT_CLOCK_TAINTED 0x2
+
#ifdef CONFIG_PM_TRACE
#include <asm/pm-trace.h>
#include <linux/types.h>
+extern unsigned int timekeeping_tainted;
extern int pm_trace_enabled;
static inline int pm_trace_is_enabled(void)
@@ -12,10 +16,23 @@ static inline int pm_trace_is_enabled(vo
return pm_trace_enabled;
}
+static inline int pm_trace_rtc_is_tainted(void)
+{
+ return (timekeeping_tainted & TIMEKEEPING_RTC_TAINTED) ?
+ 1 : 0;
+}
+
+static inline int pm_trace_pclock_is_tainted(void)
+{
+ return (timekeeping_tainted & TIMEKEEPING_PERSISTENT_CLOCK_TAINTED) ?
+ 1 : 0;
+}
+
struct device;
extern void set_trace_device(struct device *);
extern void generate_pm_trace(const void *tracedata, unsigned int user);
extern int show_trace_dev_match(char *buf, size_t size);
+extern void pm_trace_untaint_timekeeping(void);
#define TRACE_DEVICE(dev) do { \
if (pm_trace_enabled) \
@@ -25,6 +42,8 @@ extern int show_trace_dev_match(char *bu
#else
static inline int pm_trace_is_enabled(void) { return 0; }
+static inline int pm_trace_rtc_is_tainted(void) { return 0; }
+static inline int pm_trace_pclock_is_tainted(void) { return 0; }
#define TRACE_DEVICE(dev) do { } while (0)
#define TRACE_RESUME(dev) do { } while (0)
Index: linux/arch/x86/kernel/rtc.c
===================================================================
--- linux.orig/arch/x86/kernel/rtc.c
+++ linux/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,10 @@ void read_persistent_clock(struct timesp
x86_platform.get_wallclock(ts);
}
+int arch_pm_trace_taint_pclock(void)
+{
+ return (x86_platform.get_wallclock == mach_get_cmos_time);
+}
static struct resource rtc_resources[] = {
[0] = {
Index: linux/kernel/time/timekeeping.c
===================================================================
--- linux.orig/kernel/time/timekeeping.c
+++ linux/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"
@@ -1554,7 +1555,7 @@ static void __timekeeping_inject_sleepti
*/
bool timekeeping_rtc_skipresume(void)
{
- return sleeptime_injected;
+ return sleeptime_injected || pm_trace_rtc_is_tainted();
}
/**
@@ -1664,7 +1665,7 @@ void timekeeping_resume(void)
sleeptime_injected = true;
} else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) {
ts_delta = timespec64_sub(ts_new, timekeeping_suspend_time);
- sleeptime_injected = true;
+ sleeptime_injected = pm_trace_pclock_is_tainted() ? false : true;
}
if (sleeptime_injected)
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web