Skip to content

Commit

Permalink
PM: hibernate: Clean up sync_read handling in snapshot_write_next()
Browse files Browse the repository at this point in the history
commit d08970d upstream.

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: 8357376 ("[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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
bgaff authored and gregkh committed Nov 28, 2023
1 parent 567c6f6 commit d150294
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions kernel/power/snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -2633,8 +2633,6 @@ int snapshot_write_next(struct snapshot_handle *handle)
if (handle->cur > 1 && handle->cur > nr_meta_pages + nr_copy_pages)
return 0;

handle->sync_read = 1;

if (!handle->cur) {
if (!buffer)
/* This makes the buffer be freed by swsusp_free() */
Expand Down Expand Up @@ -2670,7 +2668,6 @@ int snapshot_write_next(struct snapshot_handle *handle)
memory_bm_position_reset(&orig_bm);
restore_pblist = NULL;
handle->buffer = get_buffer(&orig_bm, &ca);
handle->sync_read = 0;
if (IS_ERR(handle->buffer))
return PTR_ERR(handle->buffer);
}
Expand All @@ -2680,9 +2677,8 @@ int snapshot_write_next(struct snapshot_handle *handle)
handle->buffer = get_buffer(&orig_bm, &ca);
if (IS_ERR(handle->buffer))
return PTR_ERR(handle->buffer);
if (handle->buffer != buffer)
handle->sync_read = 0;
}
handle->sync_read = (handle->buffer == buffer);
handle->cur++;
return PAGE_SIZE;
}
Expand Down

0 comments on commit d150294

Please sign in to comment.