PM: hibernate: Clean up sync_read handling in snapshot_write_next()
authorBrian Geffon <bgeffon@google.com>
Fri, 22 Sep 2023 16:07:04 +0000 (12:07 -0400)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 26 Sep 2023 18:21:28 +0000 (20:21 +0200)
commitd08970df1980476f27936e24d452550f3e9e92e1
treed81e927cb9a6730ea7dfc1c63ee96f9dd5df5e46
parent8d74f1da776da9b0306630b13a3025214fa44618
PM: hibernate: Clean up sync_read handling in snapshot_write_next()

In snapshot_write_next(), sync_read is set and unset in three different
spots unnecessiarly. As a result there is a subtle bug where the first
page after the meta data has been loaded unconditionally sets sync_read
to 0. If this first PFN was actually a highmem page, then the returned
buffer will be the global "buffer," and the page needs to be loaded
synchronously.

That is, I'm not sure we can always assume the following to be safe:

handle->buffer = get_buffer(&orig_bm, &ca);
handle->sync_read = 0;

Because get_buffer() can call get_highmem_page_buffer() which can
return 'buffer'.

The easiest way to address this is just set sync_read before
snapshot_write_next() returns if handle->buffer == buffer.

Signed-off-by: Brian Geffon <bgeffon@google.com>
Fixes: 8357376d3df2 ("[PATCH] swsusp: Improve handling of highmem")
Cc: All applicable <stable@vger.kernel.org>
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
kernel/power/snapshot.c