Skip to contentSkip to conversation

swsusp/pm: refuse to suspend devices if wrong console is active

PATCH In review Rafael J. Wysocki 3 participants 3 messages Feb 19, 2006 – Feb 20, 2006

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

PATCH 1/1 swsusp/pm: refuse to suspend devices if wrong console is active

1) Remove the console-switching code from the suspend part of the swsusp userland interface and let the userland tools switch the console.

2) It is unsafe to suspend devices if the hardware is controlled by X. Add an extra check to prevent this from happening.

---
 drivers/base/power/suspend.c |    9 +++++++++
 kernel/power/user.c          |    3 ---
 2 files changed, 9 insertions(+), 3 deletions(-)
kernel/power/user.c +0 -3
Index: linux-2.6.16-rc3-mm1/kernel/power/user.c
===================================================================
@@ -138,12 +138,10 @@ static int snapshot_ioctl(struct inode *
 		if (data->frozen)
 			break;
 		down(&pm_sem);
-		pm_prepare_console();
 		disable_nonboot_cpus();
 		if (freeze_processes()) {
 			thaw_processes();
 			enable_nonboot_cpus();
-			pm_restore_console();
 			error = -EBUSY;
 		}
 		up(&pm_sem);
@@ -157,7 +155,6 @@ static int snapshot_ioctl(struct inode *
 		down(&pm_sem);
 		thaw_processes();
 		enable_nonboot_cpus();
-		pm_restore_console();
 		up(&pm_sem);
 		data->frozen = 0;
 		break;
drivers/base/power/suspend.c +9 -0
Index: linux-2.6.16-rc3-mm1/drivers/base/power/suspend.c
===================================================================
@@ -8,6 +8,9 @@
  *
  */
 
+#include <linux/vt_kern.h>
+#include <linux/kbd_kern.h>
+#include <linux/console.h>
 #include <linux/device.h>
 #include "../base.h"
 #include "power.h"
@@ -82,6 +85,12 @@ int device_suspend(pm_message_t state)
 {
 	int error = 0;
 
+	/* It is unsafe to suspend devices while X has control of the
+	 * hardware. Make sure we are running on a kernel-controlled console.
+	 */
+	if (vc_cons[fg_console].d->vc_mode != KD_TEXT)
+		return -EINVAL;
+
 	down(&dpm_sem);
 	down(&dpm_list_sem);
 	while (!list_empty(&dpm_active) && error == 0) {
#1 lore raw
Quoted 9 lines · Rafael J. Wysocki

1) Remove the console-switching code from the suspend part of the swsusp userland interface and let the userland tools switch the console.

2) It is unsafe to suspend devices if the hardware is controlled by X. Add an extra check to prevent this from happening.

...

drivers/base/power/suspend.c int device_suspend(pm_message_t state) · line 94

Quoted 10 lines
drivers/base/power/suspend.c +6 -0
@@ -82,6 +85,12 @@ int device_suspend(pm_message_t state)
 {
 	int error = 0;
 
+	/* It is unsafe to suspend devices while X has control of the
+	 * hardware. Make sure we are running on a kernel-controlled console.
+	 */
+	if (vc_cons[fg_console].d->vc_mode != KD_TEXT)
+		return -EINVAL;
+
 	down(&dpm_sem);

Does this mean that swsusp simply won't work if invoked while X is running and being displayed? If so, that sounds like a pretty severe limitation.

#2 lore raw
Quoted 13 lines · Andrew Morton
Quoted 12 lines · Rafael J. Wysocki

1) Remove the console-switching code from the suspend part of the swsusp userland interface and let the userland tools switch the console.

2) It is unsafe to suspend devices if the hardware is controlled by X. Add an extra check to prevent this from happening.

...

drivers/base/power/suspend.c +0 -0
@@ -82,6 +85,12 @@ int device_suspend(pm_message_t state)
 {
 	int error = 0;
 
Quoted 10 lines

drivers/base/power/suspend.c int device_suspend(pm_message_t state) · line 94

Quoted 7 lines
drivers/base/power/suspend.c +6 -0
+	/* It is unsafe to suspend devices while X has control of the
+	 * hardware. Make sure we are running on a kernel-controlled console.
+	 */
+	if (vc_cons[fg_console].d->vc_mode != KD_TEXT)
+		return -EINVAL;
+
 	down(&dpm_sem);

Does this mean that swsusp simply won't work if invoked while X is running and being displayed? If so, that sounds like a pretty severe limitation.

No, no. Kernel with switch to text console before doing this in swsusp case, and userspace has to switch to text console before doing this in uswsusp case.

This is just a sanity check, to guard against misuse by uswsusp program.

Pavel

Signature · 1 line
Web maintainer for suspend.sf.net (www.sf.net/projects/suspend) wanted...