Skip to contentSkip to conversation

watchdog: fix for lockup detector breakage on resume

PATCH Superseded Sameer Nanda 6 participants 14 messages Apr 27, 2012 – Jun 8, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: fix for lockup detector breakage on resume

On the suspend/resume path the boot CPU does not go though an offline->online transition. This breaks the NMI detector post-resume since it depends on PMU state that is lost when the system gets suspended.

Fix this by forcing a CPU offline->online transition for the lockup detector on the boot CPU during resume.

---
To provide more context, we enable NMI watchdog on Chrome OS. We have seen several reports of systems freezing up completely which indicated that the NMI watchdog was not firing for some reason.

Debugging further, we found a simple way of repro'ing system freezes -- issuing the command 'tasket 1 sh -c "echo nmilockup > /proc/breakme"' after the system has been suspended/resumed one or more times.

With this patch in place, the system freeze result in panics, as expected. These panics provide a nice stack trace for us to debug the actual issue causing the freeze.

 include/linux/sched.h  |    4 ++++
 kernel/power/suspend.c |    3 +++
 kernel/watchdog.c      |   16 ++++++++++++++++
 3 files changed, 23 insertions(+), 0 deletions(-)
include/linux/sched.h +4 -0
index 81a173c..118cc38 100644
@@ -317,6 +317,7 @@ extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
 				  size_t *lenp, loff_t *ppos);
 extern unsigned int  softlockup_panic;
 void lockup_detector_init(void);
+void lockup_detector_bootcpu_resume(void);
 #else
 static inline void touch_softlockup_watchdog(void)
 {
@@ -330,6 +331,9 @@ static inline void touch_all_softlockup_watchdogs(void)
 static inline void lockup_detector_init(void)
 {
 }
+static inline void lockup_detector_bootcpu_resume(void)
+{
+}
 #endif
 
 #ifdef CONFIG_DETECT_HUNG_TASK
kernel/power/suspend.c +3 -0
index 396d262..0d262a8 100644
@@ -177,6 +177,9 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
 	arch_suspend_enable_irqs();
 	BUG_ON(irqs_disabled());
 
+	/* Kick the lockup detector */
+	lockup_detector_bootcpu_resume();
+
  Enable_cpus:
 	enable_nonboot_cpus();
 
kernel/watchdog.c +16 -0
index df30ee0..dd2ac93 100644
@@ -585,6 +585,22 @@ static struct notifier_block __cpuinitdata cpu_nfb = {
 	.notifier_call = cpu_callback
 };
 
+void lockup_detector_bootcpu_resume(void)
+{
+	void *cpu = (void *)(long)smp_processor_id();
+
+	/*
+	 * On the suspend/resume path the boot CPU does not go though the
+	 * offline->online transition. This breaks the NMI detector post
+	 * resume. Force an offline->online transition for the boot CPU on
+	 * resume.
+	 */
+	cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
+	cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
+
+	return;
+}
+
 void __init lockup_detector_init(void)
 {
 	void *cpu = (void *)(long)smp_processor_id();
Signature · 1 line
1.7.7.3
#1 lore raw
Quoted 72 lines · On Fri, 27 Apr 2012 11:10:40 -0700 Sameer Nanda <[email protected]> wrote:

On the suspend/resume path the boot CPU does not go though an offline->online transition. This breaks the NMI detector post-resume since it depends on PMU state that is lost when the system gets suspended.

Fix this by forcing a CPU offline->online transition for the lockup detector on the boot CPU during resume.

---
To provide more context, we enable NMI watchdog on Chrome OS. We have seen several reports of systems freezing up completely which indicated that the NMI watchdog was not firing for some reason.

Debugging further, we found a simple way of repro'ing system freezes -- issuing the command 'tasket 1 sh -c "echo nmilockup > /proc/breakme"' after the system has been suspended/resumed one or more times.

With this patch in place, the system freeze result in panics, as expected. These panics provide a nice stack trace for us to debug the actual issue causing the freeze.

...

include/linux/sched.h +4 -0
@@ -317,6 +317,7 @@ extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
 				  size_t *lenp, loff_t *ppos);
 extern unsigned int  softlockup_panic;
 void lockup_detector_init(void);
+void lockup_detector_bootcpu_resume(void);
 #else
 static inline void touch_softlockup_watchdog(void)
 {
@@ -330,6 +331,9 @@ static inline void touch_all_softlockup_watchdogs(void)
 static inline void lockup_detector_init(void)
 {
 }
+static inline void lockup_detector_bootcpu_resume(void)
+{
+}
 #endif
 
 #ifdef CONFIG_DETECT_HUNG_TASK
kernel/power/suspend.c +3 -0
index 396d262..0d262a8 100644
@@ -177,6 +177,9 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
 	arch_suspend_enable_irqs();
 	BUG_ON(irqs_disabled());
 
+	/* Kick the lockup detector */
+	lockup_detector_bootcpu_resume();
+
  Enable_cpus:
 	enable_nonboot_cpus();
 
kernel/watchdog.c +5 -0
index df30ee0..dd2ac93 100644
@@ -585,6 +585,22 @@ static struct notifier_block __cpuinitdata cpu_nfb = {
 	.notifier_call = cpu_callback
 };
 
+void lockup_detector_bootcpu_resume(void)
+{
+	void *cpu = (void *)(long)smp_processor_id();
+
+	/*

kernel/watchdog.c static struct notifier_block __cpuinitdata cpu_nfb = { · line 602

Quoted 10 lines
kernel/watchdog.c +10 -0
+	 * On the suspend/resume path the boot CPU does not go though the
+	 * offline->online transition. This breaks the NMI detector post
+	 * resume. Force an offline->online transition for the boot CPU on
+	 * resume.
+	 */
+	cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
+	cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
+
+	return;
+}

I have issues with the comment ;) It describes some old bug which isn't there any more and which nobody cares about. A better comment would simply describe the function in the usual fashion. Something like this:

kernel/watchdog.c renamed from kernel/watchdog.c~nmi-watchdog-fix-for-lockup-detector-breakage-on-resume-fix +5 -8
@@ -597,20 +597,17 @@ static struct notifier_block __cpuinitda
 	.notifier_call = cpu_callback
 };
 
+/*
+ * On entry to suspend we force an offline->online transition on the boot CPU so
+ * that PMU state is available to that CPU when it comes back online after
+ * resume.  This information is required for restarting the NMI watchdog.
+ */
 void lockup_detector_bootcpu_resume(void)
 {
 	void *cpu = (void *)(long)smp_processor_id();
 
-	/*
-	 * On the suspend/resume path the boot CPU does not go though the
-	 * offline->online transition. This breaks the NMI detector post
-	 * resume. Force an offline->online transition for the boot CPU on
-	 * resume.
-	 */
 	cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
 	cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
-
-	return;
 }
 
 void __init lockup_detector_init(void)

_

But I'm not sure how accurate it is. Is it true that the PMU data was required for starting the NMI hardware?

Also, this is all dead code if CONFIG_SUSPEND=n, so how about

include/linux/sched.h renamed from include/linux/sched.h~nmi-watchdog-fix-for-lockup-detector-breakage-on-resume-fix-fix +5 -1
@@ -317,7 +317,6 @@ extern int proc_dowatchdog_thresh(struct
 				  size_t *lenp, loff_t *ppos);
 extern unsigned int  softlockup_panic;
 void lockup_detector_init(void);
-void lockup_detector_bootcpu_resume(void);
 #else
 static inline void touch_softlockup_watchdog(void)
 {
@@ -331,6 +330,11 @@ static inline void touch_all_softlockup_
 static inline void lockup_detector_init(void)
 {
 }
+#endif
+
+#if defined(CONFIG_LOCKUP_DETECTOR) && defined(CONFIG_SUSPEND)
+void lockup_detector_bootcpu_resume(void);
+#else
 static inline void lockup_detector_bootcpu_resume(void)
 {
 }
kernel/watchdog.c renamed from kernel/watchdog.c~nmi-watchdog-fix-for-lockup-detector-breakage-on-resume-fix-fix +2 -0
@@ -597,6 +597,7 @@ static struct notifier_block __cpuinitda
 	.notifier_call = cpu_callback
 };
 
+#ifdef CONFIG_SUSPEND
 /*
  * On entry to suspend we force an offline->online transition on the boot CPU so
  * that PMU state is available to that CPU when it comes back online after
@@ -609,6 +610,7 @@ void lockup_detector_bootcpu_resume(void
 	cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
 	cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
 }
+#endif
 
 void __init lockup_detector_init(void)
 {

_

#2 lore raw
Quoted 122 lines · Andrew Morton
Quoted 72 lines · On Fri, 27 Apr 2012 11:10:40 -0700 Sameer Nanda <[email protected]> wrote:

On the suspend/resume path the boot CPU does not go though an offline->online transition. This breaks the NMI detector post-resume since it depends on PMU state that is lost when the system gets suspended.

Fix this by forcing a CPU offline->online transition for the lockup detector on the boot CPU during resume.

---
To provide more context, we enable NMI watchdog on Chrome OS. We have seen several reports of systems freezing up completely which indicated that the NMI watchdog was not firing for some reason.

Debugging further, we found a simple way of repro'ing system freezes -- issuing the command 'tasket 1 sh -c "echo nmilockup > /proc/breakme"' after the system has been suspended/resumed one or more times.

With this patch in place, the system freeze result in panics, as expected. These panics provide a nice stack trace for us to debug the actual issue causing the freeze.

...

include/linux/sched.h +4 -0
@@ -317,6 +317,7 @@ extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
 				  size_t *lenp, loff_t *ppos);
 extern unsigned int  softlockup_panic;
 void lockup_detector_init(void);
+void lockup_detector_bootcpu_resume(void);
 #else
 static inline void touch_softlockup_watchdog(void)
 {
@@ -330,6 +331,9 @@ static inline void touch_all_softlockup_watchdogs(void)
 static inline void lockup_detector_init(void)
 {
 }
+static inline void lockup_detector_bootcpu_resume(void)
+{
+}
 #endif
 
 #ifdef CONFIG_DETECT_HUNG_TASK
kernel/power/suspend.c +3 -0
index 396d262..0d262a8 100644
@@ -177,6 +177,9 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
 	arch_suspend_enable_irqs();
 	BUG_ON(irqs_disabled());
 
+	/* Kick the lockup detector */
+	lockup_detector_bootcpu_resume();
+
  Enable_cpus:
 	enable_nonboot_cpus();
 
kernel/watchdog.c +5 -0
index df30ee0..dd2ac93 100644
@@ -585,6 +585,22 @@ static struct notifier_block __cpuinitdata cpu_nfb = {
 	.notifier_call = cpu_callback
 };
 
+void lockup_detector_bootcpu_resume(void)
+{
+	void *cpu = (void *)(long)smp_processor_id();
+
+	/*

kernel/watchdog.c static struct notifier_block __cpuinitdata cpu_nfb = { · line 602

Quoted 10 lines
kernel/watchdog.c +10 -0
+	 * On the suspend/resume path the boot CPU does not go though the
+	 * offline->online transition. This breaks the NMI detector post
+	 * resume. Force an offline->online transition for the boot CPU on
+	 * resume.
+	 */
+	cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
+	cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
+
+	return;
+}

I have issues with the comment ;) It describes some old bug which isn't there any more and which nobody cares about. A better comment would simply describe the function in the usual fashion. Something like this:

kernel/watchdog.c renamed from kernel/watchdog.c~nmi-watchdog-fix-for-lockup-detector-breakage-on-resume-fix +5 -8
@@ -597,20 +597,17 @@ static struct notifier_block __cpuinitda
 	.notifier_call = cpu_callback
 };
 
+/*
+ * On entry to suspend we force an offline->online transition on the boot CPU so
+ * that PMU state is available to that CPU when it comes back online after
+ * resume.  This information is required for restarting the NMI watchdog.
+ */
 void lockup_detector_bootcpu_resume(void)
 {
 	void *cpu = (void *)(long)smp_processor_id();
 
-	/*
-	 * On the suspend/resume path the boot CPU does not go though the
-	 * offline->online transition. This breaks the NMI detector post
-	 * resume. Force an offline->online transition for the boot CPU on
-	 * resume.
-	 */
 	cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
 	cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
-
-	return;
 }
 
 void __init lockup_detector_init(void)

_

Quoted 5 lines

But I'm not sure how accurate it is. Is it true that the PMU data was required for starting the NMI hardware?

Also, this is all dead code if CONFIG_SUSPEND=n, so how about

FWIW, looks good to me.

Thanks,
Rafael

Quoted 44 lines
include/linux/sched.h renamed from include/linux/sched.h~nmi-watchdog-fix-for-lockup-detector-breakage-on-resume-fix-fix +5 -1
@@ -317,7 +317,6 @@ extern int proc_dowatchdog_thresh(struct
 				  size_t *lenp, loff_t *ppos);
 extern unsigned int  softlockup_panic;
 void lockup_detector_init(void);
-void lockup_detector_bootcpu_resume(void);
 #else
 static inline void touch_softlockup_watchdog(void)
 {
@@ -331,6 +330,11 @@ static inline void touch_all_softlockup_
 static inline void lockup_detector_init(void)
 {
 }
+#endif
+
+#if defined(CONFIG_LOCKUP_DETECTOR) && defined(CONFIG_SUSPEND)
+void lockup_detector_bootcpu_resume(void);
+#else
 static inline void lockup_detector_bootcpu_resume(void)
 {
 }
kernel/watchdog.c renamed from kernel/watchdog.c~nmi-watchdog-fix-for-lockup-detector-breakage-on-resume-fix-fix +2 -0
@@ -597,6 +597,7 @@ static struct notifier_block __cpuinitda
 	.notifier_call = cpu_callback
 };
 
+#ifdef CONFIG_SUSPEND
 /*
  * On entry to suspend we force an offline->online transition on the boot CPU so
  * that PMU state is available to that CPU when it comes back online after
@@ -609,6 +610,7 @@ void lockup_detector_bootcpu_resume(void
 	cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
 	cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
 }
+#endif
 
 void __init lockup_detector_init(void)
 {

_

#3 lore raw
In reply to Andrew Morton
Quoted 97 lines · Andrew Morton
Quoted 72 lines · On Fri, 27 Apr 2012 11:10:40 -0700 Sameer Nanda <[email protected]> wrote:

On the suspend/resume path the boot CPU does not go though an offline->online transition.  This breaks the NMI detector post-resume since it depends on PMU state that is lost when the system gets suspended.

Fix this by forcing a CPU offline->online transition for the lockup detector on the boot CPU during resume.

---
To provide more context, we enable NMI watchdog on Chrome OS.  We have seen several reports of systems freezing up completely which indicated that the NMI watchdog was not firing for some reason.

Debugging further, we found a simple way of repro'ing system freezes -- issuing the command 'tasket 1 sh -c "echo nmilockup > /proc/breakme"' after the system has been suspended/resumed one or more times.

With this patch in place, the system freeze result in panics, as expected.  These panics provide a nice stack trace for us to debug the actual issue causing the freeze.

...

include/linux/sched.h +4 -0
@@ -317,6 +317,7 @@ extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
                                 size_t *lenp, loff_t *ppos);
  extern unsigned int  softlockup_panic;
  void lockup_detector_init(void);
+void lockup_detector_bootcpu_resume(void);
  #else
  static inline void touch_softlockup_watchdog(void)
  {
@@ -330,6 +331,9 @@ static inline void touch_all_softlockup_watchdogs(void)
  static inline void lockup_detector_init(void)
  {
  }
+static inline void lockup_detector_bootcpu_resume(void)
+{
+}
  #endif
 
  #ifdef CONFIG_DETECT_HUNG_TASK
kernel/power/suspend.c +3 -0
index 396d262..0d262a8 100644
@@ -177,6 +177,9 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
       arch_suspend_enable_irqs();
       BUG_ON(irqs_disabled());
 
+     /* Kick the lockup detector */
+     lockup_detector_bootcpu_resume();
+

  Enable_cpus:
      enable_nonboot_cpus();

kernel/watchdog.c +0 -0
index df30ee0..dd2ac93 100644
@@ -585,6 +585,22 @@ static struct notifier_block __cpuinitdata cpu_nfb = {

      .notifier_call = cpu_callback
 };

kernel/watchdog.c +5 -0
+void lockup_detector_bootcpu_resume(void)
+{
+     void *cpu = (void *)(long)smp_processor_id();
+
+     /*

kernel/watchdog.c

Quoted 10 lines
kernel/watchdog.c +10 -0
+      * On the suspend/resume path the boot CPU does not go though the
+      * offline->online transition. This breaks the NMI detector post
+      * resume. Force an offline->online transition for the boot CPU on
+      * resume.
+      */
+     cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
+     cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
+
+     return;
+}

I have issues with the comment ;) It describes some old bug which isn't there any more and which nobody cares about.  A better comment would simply describe the function in the usual fashion.  Something like this:

kernel/watchdog.c renamed from kernel/watchdog.c~nmi-watchdog-fix-for-lockup-detector-breakage-on-resume-fix +0 -0
@@ -597,20 +597,17 @@ static struct notifier_block __cpuinitda

       .notifier_call = cpu_callback
 };

Quoted 4 lines

+/*
+ * On entry to suspend we force an offline->online transition on the boot CPU so
+ * that PMU state is available to that CPU when it comes back online after
+ * resume.  This information is required for restarting the NMI watchdog.

This call actually happens on "exit from suspend" or "entry into resume" processing so
how about something like:

On exit from suspend we force an offline->online transition on the boot CPU so that the PMU state that was lost while in suspended state gets set up properly for the boot CPU. This information is required for restarting the NMI watchdog.

Quoted 69 lines

+ */
 void lockup_detector_bootcpu_resume(void)
 {
       void *cpu = (void *)(long)smp_processor_id();

-       /*
-        * On the suspend/resume path the boot CPU does not go though the
-        * offline->online transition. This breaks the NMI detector post
-        * resume. Force an offline->online transition for the boot CPU on
-        * resume.
-        */
       cpu_callback(&cpu_nfb, CPU_DEAD, cpu); cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
-
-       return;
 }

 void __init lockup_detector_init(void)
_

But I'm not sure how accurate it is.  Is it true that the PMU data was required for starting the NMI hardware?

Also, this is all dead code if CONFIG_SUSPEND=n, so how about

include/linux/sched.h renamed from include/linux/sched.h~nmi-watchdog-fix-for-lockup-detector-breakage-on-resume-fix-fix +5 -1
@@ -317,7 +317,6 @@ extern int proc_dowatchdog_thresh(struct
                                  size_t *lenp, loff_t *ppos);
  extern unsigned int  softlockup_panic;
  void lockup_detector_init(void);
-void lockup_detector_bootcpu_resume(void);
  #else
  static inline void touch_softlockup_watchdog(void)
  {
@@ -331,6 +330,11 @@ static inline void touch_all_softlockup_
  static inline void lockup_detector_init(void)
  {
  }
+#endif
+
+#if defined(CONFIG_LOCKUP_DETECTOR) && defined(CONFIG_SUSPEND)
+void lockup_detector_bootcpu_resume(void);
+#else
  static inline void lockup_detector_bootcpu_resume(void)
  {
  }
kernel/watchdog.c renamed from kernel/watchdog.c~nmi-watchdog-fix-for-lockup-detector-breakage-on-resume-fix-fix +0 -0
@@ -597,6 +597,7 @@ static struct notifier_block __cpuinitda

       .notifier_call = cpu_callback
 };

+#ifdef CONFIG_SUSPEND
 /*
 * On entry to suspend we force an offline->online transition on the boot CPU so
 * that PMU state is available to that CPU when it comes back online after

kernel/watchdog.c renamed from kernel/watchdog.c~nmi-watchdog-fix-for-lockup-detector-breakage-on-resume-fix-fix +1 -0
@@ -609,6 +610,7 @@ void lockup_detector_bootcpu_resume(void
        cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
        cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
  }
+#endif
 
  void __init lockup_detector_init(void)
  {

_

Signature · 1 line
Sameer
#4 lore raw
Quoted 10 lines · On Fri, 27 Apr 2012 14:40:01 -0700 Sameer Nanda <[email protected]> wrote:

On Fri, Apr 27, 2012 at 2:12 PM, Andrew Morton
<[email protected]> wrote:

This call actually happens on "exit from suspend" or "entry into resume" processing so
how about something like:

On exit from suspend we force an offline->online transition on the boot CPU so that the PMU state that was lost while in suspended state gets set up properly for the boot CPU. This information is required for restarting the NMI watchdog.

OK, let's use that.

Quoted 2 lines
Quoted 2 lines

Also, this is all dead code if CONFIG_SUSPEND=n, so how about

You had no comments about this?

#5 lore raw
Quoted 14 lines · Andrew Morton
Quoted 10 lines · On Fri, 27 Apr 2012 14:40:01 -0700 Sameer Nanda <[email protected]> wrote:

On Fri, Apr 27, 2012 at 2:12 PM, Andrew Morton
<[email protected]> wrote:

This call actually happens on "exit from suspend" or "entry into resume" processing so
how about something like:

On exit from suspend we force an offline->online transition on the boot CPU so that the PMU state that was lost while in suspended state gets set up properly for the boot CPU.  This information is required for restarting the NMI watchdog.

Quoted 6 lines

OK, let's use that.

Quoted 2 lines
Quoted 2 lines

Also, this is all dead code if CONFIG_SUSPEND=n, so how about

You had no comments about this?

Looks good to me.

Thanks for including this in the mm tree!

Signature · 1 line
Sameer
#6 lore raw
In reply to Sameer Nanda
Quoted 76 lines · Sameer Nanda

On the suspend/resume path the boot CPU does not go though an offline->online transition. This breaks the NMI detector post-resume since it depends on PMU state that is lost when the system gets suspended.

Fix this by forcing a CPU offline->online transition for the lockup detector on the boot CPU during resume.

---
To provide more context, we enable NMI watchdog on Chrome OS. We have seen several reports of systems freezing up completely which indicated that the NMI watchdog was not firing for some reason.

Debugging further, we found a simple way of repro'ing system freezes -- issuing the command 'tasket 1 sh -c "echo nmilockup > /proc/breakme"' after the system has been suspended/resumed one or more times.

With this patch in place, the system freeze result in panics, as expected. These panics provide a nice stack trace for us to debug the actual issue causing the freeze.

 include/linux/sched.h  |    4 ++++
 kernel/power/suspend.c |    3 +++
 kernel/watchdog.c      |   16 ++++++++++++++++
 3 files changed, 23 insertions(+), 0 deletions(-)
include/linux/sched.h +4 -0
index 81a173c..118cc38 100644
@@ -317,6 +317,7 @@ extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
 				  size_t *lenp, loff_t *ppos);
 extern unsigned int  softlockup_panic;
 void lockup_detector_init(void);
+void lockup_detector_bootcpu_resume(void);
 #else
 static inline void touch_softlockup_watchdog(void)
 {
@@ -330,6 +331,9 @@ static inline void touch_all_softlockup_watchdogs(void)
 static inline void lockup_detector_init(void)
 {
 }
+static inline void lockup_detector_bootcpu_resume(void)
+{
+}
 #endif
 
 #ifdef CONFIG_DETECT_HUNG_TASK
kernel/power/suspend.c +3 -0
index 396d262..0d262a8 100644
@@ -177,6 +177,9 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
 	arch_suspend_enable_irqs();
 	BUG_ON(irqs_disabled());
 
+	/* Kick the lockup detector */
+	lockup_detector_bootcpu_resume();
+
  Enable_cpus:
 	enable_nonboot_cpus();
 
kernel/watchdog.c +3 -0
index df30ee0..dd2ac93 100644
@@ -585,6 +585,22 @@ static struct notifier_block __cpuinitdata cpu_nfb = {
 	.notifier_call = cpu_callback
 };
 
+void lockup_detector_bootcpu_resume(void)
+{
+	void *cpu = (void *)(long)smp_processor_id();

kernel/watchdog.c static struct notifier_block __cpuinitdata cpu_nfb = { · line 600

Quoted 10 lines
kernel/watchdog.c +10 -0
+
+	/*
+	 * On the suspend/resume path the boot CPU does not go though the
+	 * offline->online transition. This breaks the NMI detector post
+	 * resume. Force an offline->online transition for the boot CPU on
+	 * resume.
+	 */
+	cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
+	cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
+

I have a couple of comments about this:

1. Strictly speaking, we should be using the _FROZEN variants here (since the tasks are still frozen).

Like, cpu_callback(&cpu_nfb, CPU_DEAD_FROZEN, cpu);
and cpu_callback(&cpu_nfb, CPU_ONLINE_FROZEN, cpu);

Right now, since the same action is taken for either variant (ie., with or without _FROZEN), it really doesn't matter. But still, good to be on the safer side no?

2. Why are we skipping the CPU_UP_PREPARE_FROZEN callback?

3. How about hibernation? We don't hit this problem there?

kernel/watchdog.c static struct notifier_block __cpuinitdata cpu_nfb = { · line 606

Quoted 6 lines
kernel/watchdog.c +3 -0
+	return;
+}
+
 void __init lockup_detector_init(void)
 {
 	void *cpu = (void *)(long)smp_processor_id();

Regards,
Srivatsa S. Bhat

#7 lore raw
Quoted 23 lines · Srivatsa S. Bhat

kernel/watchdog.c static struct notifier_block __cpuinitdata cpu_nfb = { · line 600

Quoted 13 lines
kernel/watchdog.c +13 -0
+void lockup_detector_bootcpu_resume(void)
+{
+	void *cpu = (void *)(long)smp_processor_id();
+
+	/*
+	 * On the suspend/resume path the boot CPU does not go though the
+	 * offline->online transition. This breaks the NMI detector post
+	 * resume. Force an offline->online transition for the boot CPU on
+	 * resume.
+	 */
+	cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
+	cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
+

I have a couple of comments about this:

1. Strictly speaking, we should be using the _FROZEN variants here (since the tasks are still frozen).

Like, cpu_callback(&cpu_nfb, CPU_DEAD_FROZEN, cpu);
and cpu_callback(&cpu_nfb, CPU_ONLINE_FROZEN, cpu);

Quoted 6 lines

Right now, since the same action is taken for either variant (ie., with or without _FROZEN), it really doesn't matter. But still, good to be on the safer side no?

2. Why are we skipping the CPU_UP_PREPARE_FROZEN callback?

3. How about hibernation? We don't hit this problem there?

Hi,

I have similar concerns as this patch seems kinda like a hack. OTOH I don't know all the available hooks for the suspend/resume paths. I would have assumed there was a special case call for the boot cpu to shutdown or at least disable its services. Wouldn't a lot of other tasks run into similar problems as the watchdog? I don't think the watchdog does anything special that requires a special hook into the suspend path.

What do other hardware timers do on the suspend path?

Cheers,
Don

#8 lore raw
In reply to Srivatsa S. Bhat
Quoted 92 lines · Srivatsa S. Bhat
Quoted 76 lines · Sameer Nanda

On the suspend/resume path the boot CPU does not go though an offline->online transition.  This breaks the NMI detector post-resume since it depends on PMU state that is lost when the system gets suspended.

Fix this by forcing a CPU offline->online transition for the lockup detector on the boot CPU during resume.

---
To provide more context, we enable NMI watchdog on Chrome OS.  We have seen several reports of systems freezing up completely which indicated that the NMI watchdog was not firing for some reason.

Debugging further, we found a simple way of repro'ing system freezes -- issuing the command 'tasket 1 sh -c "echo nmilockup > /proc/breakme"' after the system has been suspended/resumed one or more times.

With this patch in place, the system freeze result in panics, as expected.  These panics provide a nice stack trace for us to debug the actual issue causing the freeze.

 include/linux/sched.h  |    4 ++++
 kernel/power/suspend.c |    3 +++
 kernel/watchdog.c      |   16 ++++++++++++++++

 3 files changed, 23 insertions(+), 0 deletions(-)
include/linux/sched.h +4 -0
index 81a173c..118cc38 100644
@@ -317,6 +317,7 @@ extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
                                 size_t *lenp, loff_t *ppos);
  extern unsigned int  softlockup_panic;
  void lockup_detector_init(void);
+void lockup_detector_bootcpu_resume(void);
  #else
  static inline void touch_softlockup_watchdog(void)
  {
@@ -330,6 +331,9 @@ static inline void touch_all_softlockup_watchdogs(void)
  static inline void lockup_detector_init(void)
  {
  }
+static inline void lockup_detector_bootcpu_resume(void)
+{
+}
  #endif
 
  #ifdef CONFIG_DETECT_HUNG_TASK
kernel/power/suspend.c +3 -0
index 396d262..0d262a8 100644
@@ -177,6 +177,9 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
       arch_suspend_enable_irqs();
       BUG_ON(irqs_disabled());
 
+     /* Kick the lockup detector */
+     lockup_detector_bootcpu_resume();
+

  Enable_cpus:
      enable_nonboot_cpus();

kernel/watchdog.c +0 -0
index df30ee0..dd2ac93 100644
@@ -585,6 +585,22 @@ static struct notifier_block __cpuinitdata cpu_nfb = {

      .notifier_call = cpu_callback
 };

kernel/watchdog.c +3 -0
+void lockup_detector_bootcpu_resume(void)
+{
+     void *cpu = (void *)(long)smp_processor_id();

kernel/watchdog.c static struct notifier_block __cpuinitdata cpu_nfb = { · line 600

Quoted 10 lines
kernel/watchdog.c +10 -0
+
+     /*
+      * On the suspend/resume path the boot CPU does not go though the
+      * offline->online transition. This breaks the NMI detector post
+      * resume. Force an offline->online transition for the boot CPU on
+      * resume.
+      */
+     cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
+     cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
+

I have a couple of comments about this:

Quoted 8 lines

1. Strictly speaking, we should be using the _FROZEN variants here (since the tasks are still frozen).

Like, cpu_callback(&cpu_nfb, CPU_DEAD_FROZEN, cpu); and   cpu_callback(&cpu_nfb, CPU_ONLINE_FROZEN, cpu);

Right now, since the same action is taken for either variant (ie., with or without _FROZEN), it really doesn't matter. But still, good to be on the safer side no?

Agreed that the _FROZEN counterparts are a better fit here since the tasks are still frozen. Let me make this change.

Quoted 2 lines

2. Why are we skipping the CPU_UP_PREPARE_FROZEN callback?

Mainly because the hrtimer_init has already been done at kernel init time. But, this seems to be a good idea since the non-boot CPUs do transition through the CPU_UP_PREPARE_FROZEN phase on the way up during resume so it makes sense to keep the boot CPU path symmetrical.

Let me make this change also.

Quoted 2 lines

3. How about hibernation? We don't hit this problem there?

I am not too familiar with hibernation path and don't have a setup to test it either so can't really answer this one.

Quoted 13 lines
Quoted 7 lines

+     return;

kernel/watchdog.c +2 -0
+}
+

 void __init lockup_detector_init(void)
 {
      void *cpu = (void *)(long)smp_processor_id();

Regards,
Srivatsa S. Bhat

Signature · 1 line
Sameer
#11 lore raw

PATCH v2 1/1 watchdog: fix for lockup detector breakage on resume

In reply to Sameer Nanda

On the suspend/resume path the boot CPU does not go though an offline->online transition. This breaks the NMI detector post-resume since it depends on PMU state that is lost when the system gets suspended.

Fix this by forcing a CPU offline->online transition for the lockup detector on the boot CPU during resume.

Cc Andrew Morton <[email protected]>
Cc Srivatsa S. Bhat <[email protected]>

---

To provide more context, we enable NMI watchdog on Chrome OS. We have seen several reports of systems freezing up completely which indicated that the NMI watchdog was not firing for some reason.

Debugging further, we found a simple way of repro'ing system freezes -- issuing the command 'tasket 1 sh -c "echo nmilockup > /proc/breakme"' after the system has been suspended/resumed one or more times.

With this patch in place, the system freeze result in panics, as expected. These panics provide a nice stack trace for us to debug the actual issue causing the freeze.

 include/linux/sched.h  |    8 ++++++++
 kernel/power/suspend.c |    3 +++
 kernel/watchdog.c      |   17 +++++++++++++++++
 3 files changed, 28 insertions(+), 0 deletions(-)
include/linux/sched.h +8 -0
index 81a173c..44f6046 100644
@@ -332,6 +332,14 @@ static inline void lockup_detector_init(void)
 }
 #endif
 
+#if defined(CONFIG_LOCKUP_DETECTOR) && defined(CONFIG_SUSPEND)
+void lockup_detector_bootcpu_resume(void);
+#else
+static inline void lockup_detector_bootcpu_resume(void)
+{
+}
+#endif
+
 #ifdef CONFIG_DETECT_HUNG_TASK
 extern unsigned int  sysctl_hung_task_panic;
 extern unsigned long sysctl_hung_task_check_count;
kernel/power/suspend.c +3 -0
index 396d262..0d262a8 100644
@@ -177,6 +177,9 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
 	arch_suspend_enable_irqs();
 	BUG_ON(irqs_disabled());
 
+	/* Kick the lockup detector */
+	lockup_detector_bootcpu_resume();
+
  Enable_cpus:
 	enable_nonboot_cpus();
 
kernel/watchdog.c +17 -0
index df30ee0..dae2482 100644
@@ -585,6 +585,23 @@ static struct notifier_block __cpuinitdata cpu_nfb = {
 	.notifier_call = cpu_callback
 };
 
+#ifdef CONFIG_SUSPEND
+/*
+ * On exit from suspend we force an offline->online transition on the boot CPU
+ * so that the PMU state that was lost while in suspended state gets set up
+ * properly for the boot CPU.  This information is required for restarting the
+ * NMI watchdog.
+ */
+void lockup_detector_bootcpu_resume(void)
+{
+	void *cpu = (void *)(long)smp_processor_id();
+
+	cpu_callback(&cpu_nfb, CPU_DEAD_FROZEN, cpu);
+	cpu_callback(&cpu_nfb, CPU_UP_PREPARE_FROZEN, cpu);
+	cpu_callback(&cpu_nfb, CPU_ONLINE_FROZEN, cpu);
+}
+#endif
+
 void __init lockup_detector_init(void)
 {
 	void *cpu = (void *)(long)smp_processor_id();
Signature · 1 line
1.7.7.3
#9 lore raw
In reply to Sameer Nanda
Quoted 107 lines · Sameer Nanda
Quoted 92 lines · Srivatsa S. Bhat
Quoted 76 lines · Sameer Nanda

On the suspend/resume path the boot CPU does not go though an offline->online transition.  This breaks the NMI detector post-resume since it depends on PMU state that is lost when the system gets suspended.

Fix this by forcing a CPU offline->online transition for the lockup detector on the boot CPU during resume.

---
To provide more context, we enable NMI watchdog on Chrome OS.  We have seen several reports of systems freezing up completely which indicated that the NMI watchdog was not firing for some reason.

Debugging further, we found a simple way of repro'ing system freezes -- issuing the command 'tasket 1 sh -c "echo nmilockup > /proc/breakme"' after the system has been suspended/resumed one or more times.

With this patch in place, the system freeze result in panics, as expected.  These panics provide a nice stack trace for us to debug the actual issue causing the freeze.

 include/linux/sched.h  |    4 ++++
 kernel/power/suspend.c |    3 +++
 kernel/watchdog.c      |   16 ++++++++++++++++

 3 files changed, 23 insertions(+), 0 deletions(-)
include/linux/sched.h +4 -0
index 81a173c..118cc38 100644
@@ -317,6 +317,7 @@ extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
                                 size_t *lenp, loff_t *ppos);
  extern unsigned int  softlockup_panic;
  void lockup_detector_init(void);
+void lockup_detector_bootcpu_resume(void);
  #else
  static inline void touch_softlockup_watchdog(void)
  {
@@ -330,6 +331,9 @@ static inline void touch_all_softlockup_watchdogs(void)
  static inline void lockup_detector_init(void)
  {
  }
+static inline void lockup_detector_bootcpu_resume(void)
+{
+}
  #endif
 
  #ifdef CONFIG_DETECT_HUNG_TASK
kernel/power/suspend.c +3 -0
index 396d262..0d262a8 100644
@@ -177,6 +177,9 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
       arch_suspend_enable_irqs();
       BUG_ON(irqs_disabled());
 
+     /* Kick the lockup detector */
+     lockup_detector_bootcpu_resume();
+

  Enable_cpus:
      enable_nonboot_cpus();

kernel/watchdog.c +0 -0
index df30ee0..dd2ac93 100644
@@ -585,6 +585,22 @@ static struct notifier_block __cpuinitdata cpu_nfb = {

      .notifier_call = cpu_callback
 };

kernel/watchdog.c +3 -0
+void lockup_detector_bootcpu_resume(void)
+{
+     void *cpu = (void *)(long)smp_processor_id();

kernel/watchdog.c static struct notifier_block __cpuinitdata cpu_nfb = { · line 600

Quoted 10 lines
kernel/watchdog.c +10 -0
+
+     /*
+      * On the suspend/resume path the boot CPU does not go though the
+      * offline->online transition. This breaks the NMI detector post
+      * resume. Force an offline->online transition for the boot CPU on
+      * resume.
+      */
+     cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
+     cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
+

I have a couple of comments about this:

Quoted 8 lines

1. Strictly speaking, we should be using the _FROZEN variants here (since the tasks are still frozen).

Like, cpu_callback(&cpu_nfb, CPU_DEAD_FROZEN, cpu); and   cpu_callback(&cpu_nfb, CPU_ONLINE_FROZEN, cpu);

Right now, since the same action is taken for either variant (ie., with or without _FROZEN), it really doesn't matter. But still, good to be on the safer side no?

Agreed that the _FROZEN counterparts are a better fit here since the tasks are still frozen.  Let me make this change.

Quoted 1 line
Quoted 8 lines
Quoted 1 line

2. Why are we skipping the CPU_UP_PREPARE_FROZEN callback?

Mainly because the hrtimer_init has already been done at kernel init time.  But, this seems to be a good idea since the non-boot CPUs do transition through the CPU_UP_PREPARE_FROZEN phase on the way up during resume so it makes sense to keep the boot CPU path symmetrical.

Let me make this change also.

Just sent the updated patch incorporating these two changes as well as the earlier feedback from akpm.

Quoted 25 lines
Quoted 3 lines

3. How about hibernation? We don't hit this problem there?

I am not too familiar with hibernation path and don't have a setup to test it either so can't really answer this one.

Quoted 13 lines
Quoted 7 lines

+     return;

kernel/watchdog.c +2 -0
+}
+

 void __init lockup_detector_init(void)
 {
      void *cpu = (void *)(long)smp_processor_id();

Regards,
Srivatsa S. Bhat

--
Sameer

Signature · 1 line
Sameer
#10 lore raw
In reply to Sameer Nanda
Quoted 94 lines · Sameer Nanda
Quoted 92 lines · Srivatsa S. Bhat
Quoted 76 lines · Sameer Nanda

On the suspend/resume path the boot CPU does not go though an offline->online transition. This breaks the NMI detector post-resume since it depends on PMU state that is lost when the system gets suspended.

Fix this by forcing a CPU offline->online transition for the lockup detector on the boot CPU during resume.

---
To provide more context, we enable NMI watchdog on Chrome OS. We have seen several reports of systems freezing up completely which indicated that the NMI watchdog was not firing for some reason.

Debugging further, we found a simple way of repro'ing system freezes -- issuing the command 'tasket 1 sh -c "echo nmilockup > /proc/breakme"' after the system has been suspended/resumed one or more times.

With this patch in place, the system freeze result in panics, as expected. These panics provide a nice stack trace for us to debug the actual issue causing the freeze.

 include/linux/sched.h  |    4 ++++
 kernel/power/suspend.c |    3 +++
 kernel/watchdog.c      |   16 ++++++++++++++++
 3 files changed, 23 insertions(+), 0 deletions(-)
include/linux/sched.h +4 -0
index 81a173c..118cc38 100644
@@ -317,6 +317,7 @@ extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
                                size_t *lenp, loff_t *ppos);
 extern unsigned int  softlockup_panic;
 void lockup_detector_init(void);
+void lockup_detector_bootcpu_resume(void);
 #else
 static inline void touch_softlockup_watchdog(void)
 {
@@ -330,6 +331,9 @@ static inline void touch_all_softlockup_watchdogs(void)
 static inline void lockup_detector_init(void)
 {
 }
+static inline void lockup_detector_bootcpu_resume(void)
+{
+}
 #endif
 
 #ifdef CONFIG_DETECT_HUNG_TASK
kernel/power/suspend.c +3 -0
index 396d262..0d262a8 100644
@@ -177,6 +177,9 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
      arch_suspend_enable_irqs();
      BUG_ON(irqs_disabled());
 
+     /* Kick the lockup detector */
+     lockup_detector_bootcpu_resume();
+
  Enable_cpus:
      enable_nonboot_cpus();
 
kernel/watchdog.c +3 -0
index df30ee0..dd2ac93 100644
@@ -585,6 +585,22 @@ static struct notifier_block __cpuinitdata cpu_nfb = {
      .notifier_call = cpu_callback
 };
 
+void lockup_detector_bootcpu_resume(void)
+{
+     void *cpu = (void *)(long)smp_processor_id();

kernel/watchdog.c static struct notifier_block __cpuinitdata cpu_nfb = { · line 600

Quoted 10 lines
kernel/watchdog.c +10 -0
+
+     /*
+      * On the suspend/resume path the boot CPU does not go though the
+      * offline->online transition. This breaks the NMI detector post
+      * resume. Force an offline->online transition for the boot CPU on
+      * resume.
+      */
+     cpu_callback(&cpu_nfb, CPU_DEAD, cpu);
+     cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
+

I have a couple of comments about this:

[...]

Quoted 6 lines
Quoted 2 lines

3. How about hibernation? We don't hit this problem there?

I am not too familiar with hibernation path and don't have a setup to test it either so can't really answer this one.

I tested this issue with hibernation, and I found that this problem doesn't occur in that case! And since the paths (atleast related to CPU hotplug) are identical in both the cases (suspend/hibernation), I decided to dig a bit more to understand what is really happening underneath, just in case there is more to this problem than what your patch addresses, or if the root cause is something different...

Anyway, I found a couple of things (see below), though I couldn't put them together to fully explain the observed events.

1. perf_event_exit_cpu(boot-cpu) present in hibernation, missing in suspend path:
------------------------------------------------------------------------------

In the case of hibernation, we ultimately power off the machine (noticeably different from suspend). And all the functions that lead to poweroff/halt/ reboot, end up calling the callbacks registered with the reboot_notifier. (kernel/sys.c)

And perf registers a callback to this, (perf_reboot(), kernel/events/core.c) which does:

	for_each_online_cpu(cpu)
		perf_event_exit_cpu(cpu);

Note that we are doing this for *all* cpus, including the boot cpu. (In fact, if we come here from hibernate path, the only cpu online at the point is the boot cpu.)

So calling perf_event_exit_cpu() for the boot cpu is one of the things that we miss in the suspend path. For the non-boot cpus, the CPU hotplug callback perf_cpu_notify() will call this function anyway.

[By the way, I couldn't figure out where perf_event_init_cpu() is done for the boot cpu in the restore path of hibernation.]

2. perf_cpu_notify() has higher priority than watchdog's cpu_callback():
--------------------------------------------------------------------

Apart from the priority difference, the former listens to CPU_DOWN_PREPARE (early phase of CPU offline), but the latter listens to CPU_DEAD (later phase of CPU offline).

And what all this means is that, for non-boot cpus, we call perf_event_exit_cpu() first, and only then call watchdog_disable()-> watchdog_nmi_disable()->perf_event_disable().

I don't know the implication of that ordering, but it did look a bit weird..

Do the above observations ring a bell to anyone?

Regards,
Srivatsa S. Bhat

#12 lore raw
In reply to Sameer Nanda
Quoted 4 lines · Sameer Nanda

On the suspend/resume path the boot CPU does not go though an offline->online transition. This breaks the NMI detector post-resume since it depends on PMU state that is lost when the system gets suspended.

We should not have allowed the PMU to go with events counting on it across the suspend/resume transition and find out that the state has been lost. This patch solves the problem of the NMI detector as we restart the counter again when the boot cpu comes back online during resume. But the original cause (PMU going with counters into the suspend state) which triggered this problem is still there. May be we should have called perf_event_exit() on the boot cpu before going into the suspend state.

Regards
Anshuman

#13 lore raw
Quoted 8 lines · On Mon, 07 May 2012 08:54:57 +0530 Anshuman Khandual…
Quoted 4 lines · Sameer Nanda

On the suspend/resume path the boot CPU does not go though an offline->online transition. This breaks the NMI detector post-resume since it depends on PMU state that is lost when the system gets suspended.

Quoted 6 lines

We should not have allowed the PMU to go with events counting on it across the suspend/resume transition and find out that the state has been lost. This patch solves the problem of the NMI detector as we restart the counter again when the boot cpu comes back online during resume. But the original cause (PMU going with counters into the suspend state) which triggered this problem is still there. May be we should have called perf_event_exit() on the boot cpu before going into the suspend state.

That sounds like a nicer solution.

An implementation would be nice ;) I'll keep the original patch on life support until we get all this nailed down.