[PATCH v3 0/4] PM: hibernate: flush icache for restored pages from task context

From: Xiong Xin

Date: Thu Oct 01 2026 - 23:42:45 EST


Hello,

With `hibernate=nocompress`, load_image() submits the read bios
asynchronously and hib_end_io() completes them from hardirq/softirq
context. The flush_icache_range() call there, added by the
commit f6cf0545ec69 ("PM / Hibernate: Call flush_icache_range() on pages
restored in-place"), ends with kick_all_cpus_sync() on ARM64 and so
triggers the WARN_ON_ONCE(!in_task()) in smp_call_function().

This series fixes it by keeping the flush in task context, and first
closes three pre-existing holes in the restore error paths that the
rework would otherwise trip over.

Patch 1 resets clean_pages_on_read when load_image() finishes, so that
a failed nocompress resume can no longer leak the flag into a later
compressed resume, where it made hib_end_io() call flush_icache_range()
from interrupt context for the reused ring pages of
load_compressed_image(). The flag is also cleared as soon as the load
is known to have failed, so that the bios still in flight do not flush
from interrupt context during the final drain.

Patch 2 stops snapshot_write_next() from releasing all snapshot pages
in place when one of its internal allocations fails: the read bios do
not take page references, so freed pages could be handed out again
while the device is still writing the image data into them. The image
is now released by the outer error paths, after swsusp_read() has
drained the batch.

Patch 3 makes the error exits of load_compressed_image() wait for the
read bios that may still be in flight before the ring pages are freed,
like save_compressed_image() and load_image() already do.

Patch 4 defers the flush on the nocompress path: hib_end_io() now only
records the restored page on a per-batch list, and load_image() flushes
the pages once hib_wait_io() has returned, preserving the asynchronous
batched I/O.

Patches 1 to 3 are new in v3; the per-patch changelogs are in the ---
sections of each commit. Many thanks to sashiko for the v2 review,
both findings are addressed.

Xiong Xin (4):
PM: hibernate: reset clean_pages_on_read after load_image()
PM: hibernate: do not free the image in place while restore I/O is in
flight
PM: hibernate: drain pending reads in compressed image load errors
PM: hibernate: flush icache for restored pages from task context

kernel/power/snapshot.c | 9 ++-----
kernel/power/swap.c | 55 +++++++++++++++++++++++++++++++++++------
2 files changed, 50 insertions(+), 14 deletions(-)

--
2.25.1