x86, hotplug, suspend: Online CPU0 for suspend or hibernate
authorFenghua Yu <fenghua.yu@intel.com>
Tue, 13 Nov 2012 19:32:42 +0000 (11:32 -0800)
committerH. Peter Anvin <hpa@linux.intel.com>
Wed, 14 Nov 2012 17:39:49 +0000 (09:39 -0800)
Because x86 BIOS requires CPU0 to resume from sleep, suspend or hibernate can't
be executed if CPU0 is detected offline. To make suspend or hibernate and
further resume succeed, CPU0 must be online.

Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Link: http://lkml.kernel.org/r/1352835171-3958-6-git-send-email-fenghua.yu@intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
arch/x86/power/cpu.c

index 218cdb16163c3ae7026a40f95f06dd139a862db8..adde77588e25aa4ff6c1cd4ba9762db41130d238 100644 (file)
@@ -237,3 +237,47 @@ void restore_processor_state(void)
 #ifdef CONFIG_X86_32
 EXPORT_SYMBOL(restore_processor_state);
 #endif
+
+/*
+ * When bsp_check() is called in hibernate and suspend, cpu hotplug
+ * is disabled already. So it's unnessary to handle race condition between
+ * cpumask query and cpu hotplug.
+ */
+static int bsp_check(void)
+{
+       if (cpumask_first(cpu_online_mask) != 0) {
+               pr_warn("CPU0 is offline.\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+static int bsp_pm_callback(struct notifier_block *nb, unsigned long action,
+                          void *ptr)
+{
+       int ret = 0;
+
+       switch (action) {
+       case PM_SUSPEND_PREPARE:
+       case PM_HIBERNATION_PREPARE:
+               ret = bsp_check();
+               break;
+       default:
+               break;
+       }
+       return notifier_from_errno(ret);
+}
+
+static int __init bsp_pm_check_init(void)
+{
+       /*
+        * Set this bsp_pm_callback as lower priority than
+        * cpu_hotplug_pm_callback. So cpu_hotplug_pm_callback will be called
+        * earlier to disable cpu hotplug before bsp online check.
+        */
+       pm_notifier(bsp_pm_callback, -INT_MAX);
+       return 0;
+}
+
+core_initcall(bsp_pm_check_init);