On Saturday 18 March 2006 20:58, Rafael J. Wysocki wrote:
> On Saturday 18 March 2006 20:48, Andrew Morton wrote:
> > "Rafael J. Wysocki" <[email protected]> wrote:
> > >
> > > --- 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,9 @@
> > > *
> > > */
> > >
> > > +#include <linux/vt_kern.h>
> > > +#include <linux/kbd_kern.h>
> > > +#include <linux/console.h>
> > > #include <linux/device.h>
> > > #include <linux/kallsyms.h>
> > > #include <linux/pm.h>
> > > @@ -65,6 +68,17 @@ int suspend_device(struct device * dev,
> > > return error;
> > > }
> > >
> > > +#ifdef CONFIG_VT
> > > +static inline int is_suspend_console_safe(void)
> > > +{
> > > + /* It is unsafe to suspend devices while X has control of the
> > > + * hardware. Make sure we are running on a kernel-controlled console.
> > > + */
> > > + return vc_cons[fg_console].d->vc_mode == KD_TEXT;
> > > +}
> >
> > Please implement this inside the vt subsystem, not the pm subsystem. That way
> >
> > a) It gets to be called "console_is_in_text_mode()", or
> > "vt_not_running_X()" or something, which is something someone else might
> > want to know.
> >
> > b) People who work on vt code don't need to keep an eye on a hunk of pm
> > code at the same time.
> >
> > c) You won't need all those includes.
>
> I'm working on this now. [For some obscure reason I received your reply to
> Adrian only a couple of minutes ago.]
>
> Still I'd like to separate it from the console-related changes in
> kernel/power/user.c that are needed for the userland suspend, so I'd like
> to split the dropped patch in two.
>
> I've already sent the kernel/power/user.c changes in a separate patch,
> and I'll send the drivers/base/power/suspend.c changes when I test them
> (in a while).
OK, here they go.
---
From: "Rafael J. Wysocki" <[email protected]>
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 <[email protected]>
---
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,
}
}
+int is_console_suspend_safe(void)
+{
+ /* It is unsafe to suspend devices while X has control of the
+ * hardware. Make sure we are running on a kernel-controlled console.
+ */
+ 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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]