PM / hibernate: Introduce snapshot test mode for hibernation
Subsystems (2)
PATCH 1/1 PM / hibernate: Introduce snapshot test mode for hibernation
This mode is to verify if the snapshot data written to swap device can be successfully restored to memory. It is useful to ease the debugging process on hibernation, since this mode can not only bypass the BIOSen/bootloader, but also the system re-initialization.
For example:
$ sudo echo snapshot > /sys/power/disk $ sudo echo disk > /sys/power/state
/* manual resume.*/
$ sudo echo 8:3 > /sys/power/resume
--- kernel/power/hibernate.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/power/hibernate.c +7 -0
@@ -52,6 +52,7 @@ enum {#ifdef CONFIG_SUSPEND HIBERNATION_SUSPEND , #endif +HIBERNATION_SNAPSHOT ,/* keep last */ __HIBERNATION_AFTER_LAST };
@@ -631,6 +632,9 @@ static void power_down(void) "Try swapon -a.\n");return ;#endif +case HIBERNATION_SNAPSHOT : +/* Do nothing. */ +return ; }kernel_halt ();/*
@@ -878,6 +882,7 @@ static const char * const hibernation_modes[] = { #ifdef CONFIG_SUSPEND [HIBERNATION_SUSPEND] = "suspend", #endif + [HIBERNATION_SNAPSHOT] = "snapshot", };/*
@@ -924,6 +929,7 @@ static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr,#ifdef CONFIG_SUSPEND case HIBERNATION_SUSPEND :#endif +case HIBERNATION_SNAPSHOT :break ;case HIBERNATION_PLATFORM :if (hibernation_ops)
@@ -970,6 +976,7 @@ static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,#ifdef CONFIG_SUSPEND case HIBERNATION_SUSPEND :#endif +case HIBERNATION_SNAPSHOT : hibernation_mode = mode;break ;case HIBERNATION_PLATFORM :
Signature · 1 line
2.7.4
Quoted 6 lines · Chen Yu
This mode is to verify if the snapshot data written to swap device can be successfully restored to memory. It is useful to ease the debugging process on hibernation, since this mode can not only bypass the BIOSen/bootloader, but also the system re-initialization.
Quoted 6 lines
For example:
$ sudo echo snapshot > /sys/power/disk $ sudo echo disk > /sys/power/state/* manual resume.*/
$ sudo echo 8:3 > /sys/power/resume
Your examples will not work, will they?
This is also quite tricky/dangerous. If you do this with filesystems mounted R/W, it is "good bye, filesystems".
I guess updating documentation would be welcome from my side, otherwise it should be ok.
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi Pavel,
thanks for your reply,
Quoted 7 lines · Pavel Machek
Quoted 6 lines · Chen Yu
This mode is to verify if the snapshot data written to swap device can be successfully restored to memory. It is useful to ease the debugging process on hibernation, since this mode can not only bypass the BIOSen/bootloader, but also the system re-initialization.
Quoted 7 lines
Quoted 6 lines
For example:
$ sudo echo snapshot > /sys/power/disk $ sudo echo disk > /sys/power/state/* manual resume.*/
$ sudo echo 8:3 > /sys/power/resumeYour examples will not work, will they?
It works on my platform, although I did not tested it for too many rounds. And here's a revised version of v2, which introduced a new test mode in pm_test, thus users do not need to run a manual resume.
https://patchwork.kernel.org/patch/9226837/
Quoted 3 lines
This is also quite tricky/dangerous. If you do this with filesystems mounted R/W, it is "good bye, filesystems".
Ah, yes, this is quite tricky, maybe we can use this option as a debug method, for example, boot with rootfs = initrd, without mounting any disks, and then swapon the swap device, and do a testing. This should be safer?
Quoted 3 lines
I guess updating documentation would be welcome from my side, otherwise it should be ok.
OK, I'll update the documents.
Quoted 2 lines
Acked-by Pavel Machek <[email protected]>
thanks.
Quoted 4 lines
Best regards,
Pavel
Hi!
Quoted 12 lines · Pavel Machek
Quoted 11 lines · Chen Yu
Quoted 10 lines
This mode is to verify if the snapshot data written to swap device can be successfully restored to memory. It is useful to ease the debugging process on hibernation, since this mode can not only bypass the BIOSen/bootloader, but also the system re-initialization.
For example:
$ sudo echo snapshot > /sys/power/disk $ sudo echo disk > /sys/power/state
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
/* manual resume.*/
$ sudo echo 8:3 > /sys/power/resumeYour examples will not work, will they?
It works on my platform, although I did not tested it for too many rounds.
Please check again:
sudo echo disk > /sys/power/state
-bash: /sys/power/state: Permission denied
...because bash does the open, not echo.
Quoted 6 lines
Quoted 2 lines
This is also quite tricky/dangerous. If you do this with filesystems mounted R/W, it is "good bye, filesystems".
Ah, yes, this is quite tricky, maybe we can use this option as a debug method,
for example, boot with rootfs = initrd, without mounting any disks, and then swapon the swap device, and do a testing. This should be safer?
Yeah, that's the way. Read-only root is other option.
Quoted 3 lines
Quoted 2 lines
I guess updating documentation would be welcome from my side, otherwise it should be ok.
OK, I'll update the documents.
Just add fat warning into the documentation.
Thanks,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 17 lines · Pavel Machek
Hi!
Quoted 15 lines · Pavel Machek
Quoted 14 lines · Chen Yu
Quoted 6 lines
This mode is to verify if the snapshot data written to swap device can be successfully restored to memory. It is useful to ease the debugging process on hibernation, since this mode can not only bypass the BIOSen/bootloader, but also the system re-initialization.
Quoted 6 lines
For example:
$ sudo echo snapshot > /sys/power/disk $ sudo echo disk > /sys/power/state/* manual resume.*/
$ sudo echo 8:3 > /sys/power/resumeYour examples will not work, will they?
Quoted 8 lines
Quoted 2 lines
It works on my platform, although I did not tested it for too many rounds.
Please check again:
sudo echo disk >
/sys/power/state
-bash:/sys/power/state: Permission denied...because bash does the open, not echo.
Sorry, my bad, I logined as root:P
I'll rewrite the commit log.
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
This is also quite tricky/dangerous. If you do this with filesystems mounted R/W, it is "good bye, filesystems".
Ah, yes, this is quite tricky, maybe we can use this option as a debug method,
for example, boot with rootfs = initrd, without mounting any disks, and then swapon the swap device, and do a testing. This should be safer?
Quoted 6 lines
Yeah, that's the way. Read-only root is other option.
Quoted 3 lines
Quoted 2 lines
I guess updating documentation would be welcome from my side, otherwise it should be ok.
OK, I'll update the documents.
Just add fat warning into the documentation.
OK.
Quoted 2 lines
Thanks,
Pavel
Hi!
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
and then swapon the swap device, and do a testing. This should be safer?
Yeah, that's the way. Read-only root is other option.
Quoted 3 lines
Quoted 2 lines
I guess updating documentation would be welcome from my side, otherwise it should be ok.
OK, I'll update the documents.
Just add fat warning into the documentation.
OK.
Actually... If you could add
printk(KERN_ALERT "Hibernation image written. If you have any filesystems mounted read-write and attempt to resume, you'll corrupt your data. To prevent that, remove the hibernation image.\n")
...I guess that would save someone's filesystem. (Yes, very high loglevel. If you attempt to do this from anything else then singleuser or initrd, you are asking for problems, so... lets make sure user sees it.)
Thanks,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Rafael J. Wysocki
maintainerQuoted 13 lines · Pavel Machek
Hi!
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
and then swapon the swap device, and do a testing. This should be safer?
Yeah, that's the way. Read-only root is other option.
Quoted 3 lines
Quoted 2 lines
I guess updating documentation would be welcome from my side, otherwise it should be ok.
OK, I'll update the documents.
Just add fat warning into the documentation.
OK.
Actually... If you could add
Quoted 8 lines
printk(KERN_ALERT "Hibernation image written. If you have any filesystems mounted read-write and attempt to resume, you'll corrupt your data. To prevent that, remove the hibernation image.\n")
...I guess that would save someone's filesystem. (Yes, very high loglevel. If you attempt to do this from anything else then singleuser or initrd, you are asking for problems, so... lets make sure user sees it.)
Please see the new version of this patch:
https://patchwork.kernel.org/patch/9226837/
Thanks,
Rafael
Quoted 18 lines · Rafael J. Wysocki
Quoted 17 lines · Pavel Machek
Hi!
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
and then swapon the swap device, and do a testing. This should be safer?
Yeah, that's the way. Read-only root is other option.
Quoted 3 lines
Quoted 2 lines
I guess updating documentation would be welcome from my side, otherwise it should be ok.
OK, I'll update the documents.
Just add fat warning into the documentation.
OK.
Actually... If you could add
printk(KERN_ALERT "Hibernation image written. If you have any filesystems mounted read-write and attempt to resume, you'll corrupt your data. To prevent that, remove the hibernation image.\n")
Quoted 7 lines
Quoted 4 lines
...I guess that would save someone's filesystem. (Yes, very high loglevel. If you attempt to do this from anything else then singleuser or initrd, you are asking for problems, so... lets make sure user sees it.)
Please see the new version of this patch:
https://patchwork.kernel.org/patch/9226837/
New version changes nothing, right? You still need to be sure filesystems are not mounted r/w. So I would still like to see printk() with warning.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Rafael J. Wysocki
maintainerQuoted 24 lines · Pavel Machek
Quoted 23 lines · Rafael J. Wysocki
Quoted 21 lines · Pavel Machek
Hi!
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
and then swapon the swap device, and do a testing. This should be safer?
Yeah, that's the way. Read-only root is other option.
Quoted 3 lines
Quoted 2 lines
I guess updating documentation would be welcome from my side, otherwise it should be ok.
OK, I'll update the documents.
Just add fat warning into the documentation.
OK.
Actually... If you could add
printk(KERN_ALERT "Hibernation image written. If you have any filesystems mounted read-write and attempt to resume, you'll corrupt your data. To prevent that, remove the hibernation image.\n")
...I guess that would save someone's filesystem. (Yes, very high loglevel. If you attempt to do this from anything else then singleuser or initrd, you are asking for problems, so... lets make sure user sees it.)
Quoted 6 lines
Quoted 2 lines
Please see the new version of this patch:
https://patchwork.kernel.org/patch/9226837/New version changes nothing, right? You still need to be sure filesystems are not mounted r/w. So I would still like to see
printk()with warning.
It shouldn't matter how they are mounted, because the contents of persistent storage don't change.
Thanks,
Rafael
Quoted 28 lines · Rafael J. Wysocki
Quoted 27 lines · Pavel Machek
Quoted 25 lines · Rafael J. Wysocki
Quoted 13 lines · Pavel Machek
Hi!
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
and then swapon the swap device, and do a testing. This should be safer?
Yeah, that's the way. Read-only root is other option.
Quoted 3 lines
Quoted 2 lines
I guess updating documentation would be welcome from my side, otherwise it should be ok.
OK, I'll update the documents.
Just add fat warning into the documentation.
OK.
Actually... If you could add
Quoted 8 lines
printk(KERN_ALERT "Hibernation image written. If you have any filesystems mounted read-write and attempt to resume, you'll corrupt your data. To prevent that, remove the hibernation image.\n")
...I guess that would save someone's filesystem. (Yes, very high loglevel. If you attempt to do this from anything else then singleuser or initrd, you are asking for problems, so... lets make sure user sees it.)
Please see the new version of this patch:
https://patchwork.kernel.org/patch/9226837/
Quoted 6 lines
Quoted 3 lines
New version changes nothing, right? You still need to be sure filesystems are not mounted r/w. So I would still like to see
printk()with warning.It shouldn't matter how they are mounted, because the contents of persistent storage don't change.
@@ -721,6 +724,9 @@ int hibernate(void)
atomic_inc(&snapshot_device_available);
Unlock:
unlock_system_sleep();
+ if (snapshot_test)
+ software_resume();
+
return error;
}Aha, I see, immediate wakeup here. Makes sense. ... ...
No.
AFAICT, freezer is used in hibernation_snapshot, which means at Unlock:, kernel threads are running; software_resume() freezes them again, but they had chance to run and potentially corrupt the persistent storage... right?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Rafael J. Wysocki
maintainerQuoted 46 lines · Pavel Machek
Quoted 34 lines · Rafael J. Wysocki
Quoted 24 lines · Pavel Machek
Quoted 23 lines · Rafael J. Wysocki
Quoted 21 lines · Pavel Machek
Hi!
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
and then swapon the swap device, and do a testing. This should be safer?
Yeah, that's the way. Read-only root is other option.
Quoted 3 lines
Quoted 2 lines
I guess updating documentation would be welcome from my side, otherwise it should be ok.
OK, I'll update the documents.
Just add fat warning into the documentation.
OK.
Actually... If you could add
printk(KERN_ALERT "Hibernation image written. If you have any filesystems mounted read-write and attempt to resume, you'll corrupt your data. To prevent that, remove the hibernation image.\n")
...I guess that would save someone's filesystem. (Yes, very high loglevel. If you attempt to do this from anything else then singleuser or initrd, you are asking for problems, so... lets make sure user sees it.)
Quoted 6 lines
Quoted 2 lines
Please see the new version of this patch:
https://patchwork.kernel.org/patch/9226837/New version changes nothing, right? You still need to be sure filesystems are not mounted r/w. So I would still like to see
printk()with warning.It shouldn't matter how they are mounted, because the contents of persistent storage don't change.
(quoted diff) +0
-0@@ -721,6 +724,9 @@ int hibernate(void) atomic_inc(&snapshot_device_available); Unlock: unlock_system_sleep(); + if (snapshot_test) + software_resume(); + return error; }
Quoted 8 lines
Aha, I see, immediate wakeup here. Makes sense. ... ...
No.
AFAICT, freezer is used in
hibernation_snapshot, which means at Unlock:, kernel threads are running;software_resume()freezes them again, but they had chance to run and potentially corrupt the persistent storage... right?
OK, there is a bug.
The thawing of user space is potentially dangerous, so in the "snapshot" test mode hibernate() should just call free_basic_memory_bitmaps() and from there invoke the code below the Check_image label in software_resume(), roughly.
Thanks,
Rafael
Rafael J. Wysocki
maintainerQuoted 58 lines · Rafael J. Wysocki
Quoted 46 lines · Pavel Machek
Quoted 34 lines · Rafael J. Wysocki
Quoted 24 lines · Pavel Machek
Quoted 23 lines · Rafael J. Wysocki
Quoted 21 lines · Pavel Machek
Hi!
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
and then swapon the swap device, and do a testing. This should be safer?
Yeah, that's the way. Read-only root is other option.
Quoted 3 lines
Quoted 2 lines
I guess updating documentation would be welcome from my side, otherwise it should be ok.
OK, I'll update the documents.
Just add fat warning into the documentation.
OK.
Actually... If you could add
printk(KERN_ALERT "Hibernation image written. If you have any filesystems mounted read-write and attempt to resume, you'll corrupt your data. To prevent that, remove the hibernation image.\n")
...I guess that would save someone's filesystem. (Yes, very high loglevel. If you attempt to do this from anything else then singleuser or initrd, you are asking for problems, so... lets make sure user sees it.)
Quoted 6 lines
Quoted 2 lines
Please see the new version of this patch:
https://patchwork.kernel.org/patch/9226837/New version changes nothing, right? You still need to be sure filesystems are not mounted r/w. So I would still like to see
printk()with warning.It shouldn't matter how they are mounted, because the contents of persistent storage don't change.
(quoted diff) +0
-0@@ -721,6 +724,9 @@ int hibernate(void) atomic_inc(&snapshot_device_available); Unlock: unlock_system_sleep(); + if (snapshot_test) + software_resume(); + return error; }Quoted 8 lines
Aha, I see, immediate wakeup here. Makes sense. ... ...
No.
AFAICT, freezer is used in
hibernation_snapshot, which means at Unlock:, kernel threads are running;software_resume()freezes them again, but they had chance to run and potentially corrupt the persistent storage... right?OK, there is a bug.
Quoted 4 lines
The thawing of user space is potentially dangerous, so in the "snapshot" test mode
hibernate()should just callfree_basic_memory_bitmaps()and from there invoke the code below theCheck_imagelabel insoftware_resume(), roughly.
Or rather call free_basic_memory_bitmaps() and unlock_device_hotplug(), then do swsusp_check() and invoke the code starting with the "PM: Loading hibernation image.\n" message in software_resume().
Thanks,
Rafael
Hi,
Quoted 53 lines · Rafael J. Wysocki
Quoted 52 lines · Rafael J. Wysocki
Quoted 41 lines · Pavel Machek
Quoted 30 lines · Rafael J. Wysocki
Quoted 22 lines · Pavel Machek
Quoted 21 lines · Rafael J. Wysocki
Quoted 20 lines · Pavel Machek
Hi!
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
and then swapon the swap device, and do a testing. This should be safer?
Yeah, that's the way. Read-only root is other option.
Quoted 3 lines
Quoted 2 lines
I guess updating documentation would be welcome from my side, otherwise it should be ok.
OK, I'll update the documents.
Just add fat warning into the documentation.
OK.
Actually... If you could add
printk(KERN_ALERT "Hibernation image written. If you have any filesystems mounted read-write and attempt to resume, you'll corrupt your data. To prevent that, remove the hibernation image.\n")
...I guess that would save someone's filesystem. (Yes, very high loglevel. If you attempt to do this from anything else then singleuser or initrd, you are asking for problems, so... lets make sure user sees it.)
Quoted 5 lines
Quoted 2 lines
Please see the new version of this patch:
https://patchwork.kernel.org/patch/9226837/New version changes nothing, right? You still need to be sure filesystems are not mounted r/w. So I would still like to see
printk()with warning.It shouldn't matter how they are mounted, because the contents of persistent storage don't change.
(quoted diff) +0
-0@@ -721,6 +724,9 @@ int hibernate(void) atomic_inc(&snapshot_device_available); Unlock: unlock_system_sleep(); + if (snapshot_test) + software_resume(); + return error; }Quoted 8 lines
Aha, I see, immediate wakeup here. Makes sense. ... ...
No.
AFAICT, freezer is used in
hibernation_snapshot, which means at Unlock:, kernel threads are running;software_resume()freezes them again, but they had chance to run and potentially corrupt the persistent storage... right?OK, there is a bug.
Quoted 8 lines
Quoted 4 lines
The thawing of user space is potentially dangerous, so in the "snapshot" test mode
hibernate()should just callfree_basic_memory_bitmaps()and from there invoke the code below theCheck_imagelabel insoftware_resume(), roughly.Or rather call
free_basic_memory_bitmaps()andunlock_device_hotplug(), then doswsusp_check()and invoke the code starting with the "PM: Loading hibernation image.\n" message insoftware_resume().
OK, I've used this solution and sent a v3 out.
thanks!
Quoted 3 lines
Thanks,
Rafael