* [PATCH -mm 1/3] swsusp: let userland tools switch console on suspend
[not found] <200603191158.26275.rjw@sisk.pl>
@ 2006-03-19 11:05 ` Rafael J. Wysocki
2006-03-19 11:05 ` [PATCH -mm 2/3] pm: check console before suspending devices Rafael J. Wysocki
2006-03-19 11:16 ` [PATCH -mm 3/3] swsusp: add s2ram ioctl to userland interface Rafael J. Wysocki
2 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2006-03-19 11:05 UTC (permalink / raw)
To: Andrew Morton; +Cc: LKML, Pavel Machek
From: "Rafael J. Wysocki" <rjw@sisk.pl>
Remove the console-switching code from the suspend part of the swsusp
userland interface and let the userland tools switch the console.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@suse.cz>
---
kernel/power/user.c | 3 ---
1 files changed, 3 deletions(-)
Index: linux-2.6.16-rc6-mm2/kernel/power/user.c
===================================================================
--- linux-2.6.16-rc6-mm2.orig/kernel/power/user.c
+++ linux-2.6.16-rc6-mm2/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;
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH -mm 2/3] pm: check console before suspending devices
[not found] <200603191158.26275.rjw@sisk.pl>
2006-03-19 11:05 ` [PATCH -mm 1/3] swsusp: let userland tools switch console on suspend Rafael J. Wysocki
@ 2006-03-19 11:05 ` Rafael J. Wysocki
2006-03-19 11:16 ` [PATCH -mm 3/3] swsusp: add s2ram ioctl to userland interface Rafael J. Wysocki
2 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2006-03-19 11:05 UTC (permalink / raw)
To: Andrew Morton; +Cc: LKML, Pavel Machek
From: "Rafael J. Wysocki" <rjw@sisk.pl>
It is unsafe to suspend devices if the hardware is controlled by X.
Add an extra check to prevent this from happening.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
drivers/base/power/suspend.c | 5 ++++-
drivers/char/vt.c | 8 ++++++++
include/linux/vt_kern.h | 5 +++++
3 files changed, 17 insertions(+), 1 deletion(-)
Index: linux-2.6.16-rc6-mm2/drivers/base/power/suspend.c
===================================================================
--- linux-2.6.16-rc6-mm2.orig/drivers/base/power/suspend.c
+++ linux-2.6.16-rc6-mm2/drivers/base/power/suspend.c
@@ -8,6 +8,7 @@
*
*/
+#include <linux/vt_kern.h>
#include <linux/device.h>
#include <linux/kallsyms.h>
#include <linux/pm.h>
@@ -65,7 +66,6 @@ int suspend_device(struct device * dev,
return error;
}
-
/**
* device_suspend - Save state and stop all devices in system.
* @state: Power state to put each device in.
@@ -85,6 +85,9 @@ int device_suspend(pm_message_t state)
{
int error = 0;
+ if (!is_console_suspend_safe())
+ return -EINVAL;
+
down(&dpm_sem);
down(&dpm_list_sem);
while (!list_empty(&dpm_active) && error == 0) {
Index: linux-2.6.16-rc6-mm2/drivers/char/vt.c
===================================================================
--- linux-2.6.16-rc6-mm2.orig/drivers/char/vt.c
+++ linux-2.6.16-rc6-mm2/drivers/char/vt.c
@@ -3234,6 +3234,14 @@ void vcs_scr_writew(struct vc_data *vc,
}
}
+/* It is unsafe to suspend devices while X has control of the
+ * hardware. Check if we are running on a kernel-controlled console.
+ */
+int is_console_suspend_safe(void)
+{
+ return vc_cons[fg_console].d->vc_mode == KD_TEXT;
+}
+
/*
* Visible symbols for modules
*/
Index: linux-2.6.16-rc6-mm2/include/linux/vt_kern.h
===================================================================
--- linux-2.6.16-rc6-mm2.orig/include/linux/vt_kern.h
+++ linux-2.6.16-rc6-mm2/include/linux/vt_kern.h
@@ -73,6 +73,11 @@ int con_copy_unimap(struct vc_data *dst_
int vt_waitactive(int vt);
void change_console(struct vc_data *new_vc);
void reset_vc(struct vc_data *vc);
+#ifdef CONFIG_VT
+int is_console_suspend_safe(void);
+#else
+static inline int is_console_suspend_safe(void) { return 1; }
+#endif
/*
* vc_screen.c shares this temporary buffer with the console write code so that
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH -mm 3/3] swsusp: add s2ram ioctl to userland interface
[not found] <200603191158.26275.rjw@sisk.pl>
2006-03-19 11:05 ` [PATCH -mm 1/3] swsusp: let userland tools switch console on suspend Rafael J. Wysocki
2006-03-19 11:05 ` [PATCH -mm 2/3] pm: check console before suspending devices Rafael J. Wysocki
@ 2006-03-19 11:16 ` Rafael J. Wysocki
2 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2006-03-19 11:16 UTC (permalink / raw)
To: Andrew Morton; +Cc: LKML, Pavel Machek
From: Luca Tettamanti <kronos.it@gmail.com>
Add the SNAPSHOT_S2RAM ioctl to the snapshot device.
This ioctl allows a userland application to make the system (previously
frozen with the SNAPSHOT_FREE ioctl) enter the S3 state without freezing
processes and disabling nonboot CPUs for the second time.
This will allow us to implement the suspend-to-disk-and-RAM (STDR)
functionality in the userland suspend tools.
Signed-off-by: Luca Tettamanti <kronos.it@gmail.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
kernel/power/main.c | 2 +-
kernel/power/power.h | 4 +++-
kernel/power/user.c | 36 ++++++++++++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 2 deletions(-)
Index: linux-2.6.16-rc6-mm2/kernel/power/main.c
===================================================================
--- linux-2.6.16-rc6-mm2.orig/kernel/power/main.c
+++ linux-2.6.16-rc6-mm2/kernel/power/main.c
@@ -103,7 +103,7 @@ static int suspend_prepare(suspend_state
}
-static int suspend_enter(suspend_state_t state)
+int suspend_enter(suspend_state_t state)
{
int error = 0;
unsigned long flags;
Index: linux-2.6.16-rc6-mm2/kernel/power/power.h
===================================================================
--- linux-2.6.16-rc6-mm2.orig/kernel/power/power.h
+++ linux-2.6.16-rc6-mm2/kernel/power/power.h
@@ -77,7 +77,8 @@ int snapshot_image_loaded(struct snapsho
#define SNAPSHOT_GET_SWAP_PAGE _IOR(SNAPSHOT_IOC_MAGIC, 8, void *)
#define SNAPSHOT_FREE_SWAP_PAGES _IO(SNAPSHOT_IOC_MAGIC, 9)
#define SNAPSHOT_SET_SWAP_FILE _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int)
-#define SNAPSHOT_IOC_MAXNR 10
+#define SNAPSHOT_S2RAM _IO(SNAPSHOT_IOC_MAGIC, 11)
+#define SNAPSHOT_IOC_MAXNR 11
/**
* The bitmap is used for tracing allocated swap pages
@@ -112,3 +113,4 @@ extern int swsusp_resume(void);
extern int swsusp_read(void);
extern int swsusp_write(void);
extern void swsusp_close(void);
+extern int suspend_enter(suspend_state_t state);
Index: linux-2.6.16-rc6-mm2/kernel/power/user.c
===================================================================
--- linux-2.6.16-rc6-mm2.orig/kernel/power/user.c
+++ linux-2.6.16-rc6-mm2/kernel/power/user.c
@@ -265,6 +265,42 @@ static int snapshot_ioctl(struct inode *
}
break;
+ case SNAPSHOT_S2RAM:
+ if (!data->frozen) {
+ error = -EPERM;
+ break;
+ }
+
+ if (down_trylock(&pm_sem)) {
+ error = -EBUSY;
+ break;
+ }
+
+ if (pm_ops->prepare) {
+ error = pm_ops->prepare(PM_SUSPEND_MEM);
+ if (error)
+ goto OutS3;
+ }
+
+ /* Put devices to sleep */
+ error = device_suspend(PMSG_SUSPEND);
+ if (error) {
+ printk(KERN_ERR "Failed to suspend some devices.\n");
+ } else {
+ /* Enter S3, system is already frozen */
+ suspend_enter(PM_SUSPEND_MEM);
+
+ /* Wake up devices */
+ device_resume();
+ }
+
+ if (pm_ops->finish)
+ pm_ops->finish(PM_SUSPEND_MEM);
+
+OutS3:
+ up(&pm_sem);
+ break;
+
default:
error = -ENOTTY;
^ permalink raw reply [flat|nested] 3+ messages in thread