suspend from userland
Subsystems (4)
I'd like to get some testing and comments on this. I know that userland part is messy and will not work on x86-64 etc, and I should obviously remove some extra printk's... but otherwise it should be okay.
Testing would be nice, too, but be a bit careful. It should not be more dangerous than /sys/power/resume, but... If you suspect something unusual, be sure to force fsck.
Pavel
Documentation/power/uswsusp.txt new file +43 -0
@@ -0,0 +1,43 @@ + + u-swsusp: do software suspend from userland + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Copyright 2005 Pavel Machek <[email protected]> + (distribute under GPLv2) + +u-swsusp is next generation of swsusp -- it enables userland to do +most of the work. That way graphical progress bar can be added, and +you can have encryption, compression, suspend to regular files, +suspend over network etc. More exotic stuff is possible, too: given +enough memory and some device mapper magic, you could snapshot system +every 5 minutes, and then provided unlimited, cross-application +"undo". + +Notice that all warnings in swsusp.txt still apply. If you change your +filesystem between suspend and resume, that's bye-bye-filesystem. Only +shooting yourself into the foot has now became simpler, because you'll +want to run userspace application to do the resume. Remember that even +read-only mount of journalled filesystem changes it. That means that +either you'll have to use ext2 for resume application, or put it into +initrd. (initrd is certainly right solution, long term). + +Current userland support is _very_ limited, and provides very little +safety measures. Be careful. It can only suspend to empty partition, +and will happily overwrite anything there. + +Installation: place swsusp binary into /tmp/, along with +swsusp-init. Add init=/tmp/swsusp-init to your kernel +commandline. Modify swsusp-init with right device. To suspend, do +something like: + +swapoff /dev/hda1; cat /dev/zero | head -c 4096 > /dev/hda1 +/tmp/swsusp /dev/hda1 -s -b + +. Good luck! + +Q: I hate /dev/kmem, it enables crackers to install rootkits. + +A: There are 1000 other ways to install rootkit if you have all the +priviledges these days. Anyway, if you want to make hijacking +/dev/kmem little harder, you can modify it to only work with pages +that have "PageNosave | PageNosaveFree" set. swsusp application only +needs to manipulate those.
drivers/char/mem.c +41 -0
59 lines not on this page · raw message
include/linux/suspend.h +23 -0
@@ -1,6 +1,7 @@#ifndef _LINUX_SWSUSP_H#define _LINUX_SWSUSP_H +#ifdef __KERNEL__#if defined(CONFIG_X86 ) || defined(CONFIG_FRV ) || defined(CONFIG_PPC32 )#include <asm/suspend.h> #endif
@@ -9,6 +10,7 @@#include <linux/config.h> #include <linux/init.h> #include <linux/pm.h> +#endif /* page backup entry */ typedef struct pbe {
@@ -30,6 +32,7 @@ typedef struct pbe {#define for_each_pb_page (pbe, pblist) \ for (pbe = pblist ; pbe ; pbe = (pbe+PB_PAGE_SKIP)->next) +#ifdef __KERNEL__#define SWAP_FILENAME_MAXLENGTH 32
@@ -79,4 +82,24 @@ unsigned long get_safe_page(gfp_t gfp_ma*/ #define PAGES_FOR_IO 512 +#endif + +struct restore_ioctl { +void *pgdir; +int nr_pages; +}; + +#define IOCTL_FREEZE _IO('3', 1) +#define IOCTL_UNFREEZE _IO('3', 2) +#define IOCTL_ATOMIC_SNAPSHOT _IOW('3', 3, void **) +#define IOCTL_ATOMIC_RESTORE _IOR('3', 4, struct restore_ioctl) +#define IOCTL_KMALLOC _IO('3', 5) +#define IOCTL_KFREE _IOR('3', 6, void *) + +extern int sys_freeze (void ); +extern int sys_unfreeze (void ); +extern int sys_atomic_snapshot (void **pgdir); +extern int sys_atomic_restore (void *pgdir,int pages); + +#endif /* _LINUX_SWSUSP_H */
kernel/power/Kconfig +0 -12
@@ -82,18 +82,6 @@ config PM_STD_PARTITION suspended image to. It will simply pick the first available swap device. -config SWSUSP_ENCRYPT - bool "Encrypt suspend image" - depends on SOFTWARE_SUSPEND && CRYPTO=y && (CRYPTO_AES=y || CRYPTO_AES_586=y || CRYPTO_AES_X86_64=y) - default "" - ---help--- - To prevent data gathering from swap after resume you can encrypt - the suspend image with a temporary key that is deleted on - resume. - - Note that the temporary key is stored unencrypted on disk while the - system is suspended. - config SUSPEND_SMP bool depends on HOTPLUG_CPU && X86 && PM
kernel/power/console.c +1 -0
@@ -9,6 +9,7 @@#include <linux/console.h> #include "power.h" +#undef SUSPEND_CONSOLEstatic int new_loglevel =10 ;static int orig_loglevel;#ifdef SUSPEND_CONSOLE
kernel/power/disk.c +34 -12
72 lines not on this page · raw message
kernel/power/power.h +0 -3
@@ -48,9 +48,6 @@ static struct subsys_attribute _name##_aextern struct subsystem power_subsys; -extern int freeze_processes (void ); -extern void thaw_processes (void ); -extern int pm_prepare_console (void );extern void pm_restore_console (void );
kernel/power/process.c +1 -1
@@ -83,7 +83,7 @@ int freeze_processes(void)yield ();/* Yield is okay here */ if (todo &&time_after (jiffies, start_time +TIMEOUT )) {printk ("\n" ); -printk (KERN_ERR " stopping tasks failed (%d tasks remaining)\n" , todo ); +printk (KERN_ERR " stopping tasks timed out (%d tasks remaining)\n" , todo );break ; } }while (todo);
kernel/power/swsusp.c +72 -3
126 lines not on this page · raw message
usr/swsusp-init new file +9 -0
@@ -0,0 +1,9 @@ +#!/bin/bash +# +# swapoff /dev/hda1; cat /dev/zero | head -c 4096 > /dev/hda1 +# /tmp/swsusp /dev/hda1 -s -b +/tmp/swsusp /dev/hda1 -r +exec /sbin/init +exit + +
usr/swsusp.c new file +529 -0
529 lines not on this page · raw message
Signature · 1 line
Thanks, Sharp!
Hi,
Quoted 7 lines · Pavel Machek
I'd like to get some testing and comments on this. I know that userland part is messy and will not work on x86-64 etc, and I should obviously remove some extra printk's... but otherwise it should be okay.
Testing would be nice, too, but be a bit careful. It should not be more dangerous than
/sys/power/resume, but... If you suspect something unusual, be sure to force fsck.
Could we please postpone it for some time?
First, the patch doesn't apply to the current -mm and the userland part is incompatible with the code there to the extent of a serious breakage (let alone the x86-64 issue).
Second, if I had some time to get my solution ready, we could compare the alternatives instead of just discussing one of them.
Greetings,
Rafael
Signature · 1 line
Beer is proof that God loves us and wants us to be happy - Benjamin Franklin
Hi!
Quoted 9 lines
Quoted 7 lines
I'd like to get some testing and comments on this. I know that userland part is messy and will not work on x86-64 etc, and I should obviously remove some extra printk's... but otherwise it should be okay.
Testing would be nice, too, but be a bit careful. It should not be more dangerous than
/sys/power/resume, but... If you suspect something unusual, be sure to force fsck.Could we please postpone it for some time?
Well, it is probably not going into -mm before your changes are in mainline. That means 2.6.17 earliest.
Quoted 3 lines
First, the patch doesn't apply to the current -mm and the userland part is incompatible with the code there to the extent of a serious breakage (let alone the x86-64 issue).
Of course I'm going to fix up breakage before the merge. At least all the kernel parts and enough userland to test that it still works.
Quoted 2 lines
Second, if I had some time to get my solution ready, we could compare the alternatives instead of just discussing one of them.
Well, I'm trying to gently push you. I'd like to get some solution in 1-2 months timeframe, so that work on userland parts can start.
Pavel
Signature · 1 line
Thanks, Sharp!