linux/kernel/power
Alberto Garcia 734eba62cd PM: hibernate: Drain trailing zero pages on userspace restore
Commit 005e8dddd4 ("PM: hibernate: don't store zero pages in the
image file") added an optimization to skip zero-filled pages in the
hibernation image. On restore, zero pages are handled internally by
snapshot_write_next() in a loop that processes them without returning
to the caller.

With the userspace restore interface, writing the last non-zero page
to /dev/snapshot is followed by the SNAPSHOT_ATOMIC_RESTORE ioctl. At
this point there are no more calls to snapshot_write_next() so any
trailing zero pages are not processed, snapshot_image_loaded() fails
because handle->cur is smaller than expected, the ioctl returns -EPERM
and the image is not restored.

The in-kernel restore path is not affected by this because the loop in
load_image() in swap.c calls snapshot_write_next() until it returns 0.
It is this final call that drains any trailing zero pages.

Fixed by calling snapshot_write_next() in snapshot_write_finalize(),
giving the kernel the chance to drain any trailing zero pages.

Fixes: 005e8dddd4 ("PM: hibernate: don't store zero pages in the image file")
Signed-off-by: Alberto Garcia <berto@igalia.com>
Acked-by: Brian Geffon <bgeffon@google.com>
Link: https://patch.msgid.link/ef5a7c5e3e3dbd17dcb20efaa0c53a47a23498bb.1773075892.git.berto@igalia.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2026-03-23 13:33:06 +01:00
..
Kconfig PM: QoS: Introduce a CPU system wakeup QoS limit 2025-11-25 19:01:29 +01:00
Makefile PM: EM: Add a skeleton code for netlink notification 2025-10-22 21:44:37 +02:00
autosleep.c PM: sleep: autosleep: don't include 'pm_wakeup.h' directly 2024-12-05 12:14:26 +01:00
console.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
em_netlink.c PM: EM: Add dump to get-perf-domains in the EM YNL spec 2026-01-09 21:44:46 +01:00
em_netlink.h PM: EM: Implement em_notify_pd_created/updated() 2025-10-22 21:44:38 +02:00
em_netlink_autogen.c PM: EM: Add dump to get-perf-domains in the EM YNL spec 2026-01-09 21:44:46 +01:00
em_netlink_autogen.h PM: EM: Add dump to get-perf-domains in the EM YNL spec 2026-01-09 21:44:46 +01:00
energy_model.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
hibernate.c Merge branch 'pm-sleep' 2025-11-28 16:01:13 +01:00
main.c PM: sleep: Do not flag runtime PM workqueue as freezable 2025-12-15 12:20:02 +01:00
power.h PM: sleep: Add support for wakeup during filesystem sync 2025-11-20 22:29:40 +01:00
poweroff.c
process.c Revert "PM: sleep: Make pm_wakeup_clear() call more clear" 2025-10-23 12:48:04 +02:00
qos.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
snapshot.c PM: hibernate: Drain trailing zero pages on userspace restore 2026-03-23 13:33:06 +01:00
suspend.c PM: sleep: Fix suspend_test() at the TEST_CORE level 2025-12-28 13:01:39 +01:00
suspend_test.c
swap.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
user.c PM: sleep: Call pm_sleep_fs_sync() instead of ksys_sync_helper() 2025-11-20 22:29:40 +01:00
wakelock.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00