public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PM: hibernate: Drain trailing zero pages on userspace restore
@ 2026-03-09  0:12 Alberto Garcia
  2026-03-09 11:26 ` Alberto Garcia
  0 siblings, 1 reply; 5+ messages in thread
From: Alberto Garcia @ 2026-03-09  0:12 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: Len Brown, Pavel Machek, Brian Geffon, linux-pm, Alberto Garcia

Commit 005e8dddd497 ("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 the SNAPSHOT_ATOMIC_RESTORE
handler before snapshot_write_finalize(), giving the kernel the chance
to process any trailing zero pages.

Fixes: 005e8dddd497 ("PM: hibernate: don't store zero pages in the image file")
Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 kernel/power/user.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/kernel/power/user.c b/kernel/power/user.c
index 4401cfe26e5c..d5f189c4c93e 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -319,6 +319,14 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
 		break;
 
 	case SNAPSHOT_ATOMIC_RESTORE:
+		/*
+		 * We need to call snapshot_write_next() one last time
+		 * before finalizing in order to process any trailing
+		 * zero pages.
+		 */
+		error = snapshot_write_next(&data->handle);
+		if (error < 0)
+			break;
 		error = snapshot_write_finalize(&data->handle);
 		if (error)
 			break;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-09 16:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-09  0:12 [PATCH] PM: hibernate: Drain trailing zero pages on userspace restore Alberto Garcia
2026-03-09 11:26 ` Alberto Garcia
2026-03-09 15:01   ` Brian Geffon
2026-03-09 15:57     ` Alberto Garcia
2026-03-09 16:08       ` Brian Geffon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox