diff options
authorJames Morse <james.morse@arm.com>2016-04-27 17:47:11 +0100
committerAlex Shi <alex.shi@linaro.org>2016-05-25 15:03:11 +0800
commitac8cb4a81303a97c49857b5228d8392933d07562 (patch)
parent3c34ab73b30e24320ec90c0143910744bb10e915 (diff)
PM / Hibernate: Call flush_icache_range() on pages restored in-place
Some architectures require code written to memory as if it were data to be 'cleaned' from any data caches before the processor can fetch them as new instructions. During resume from hibernate, the snapshot code copies some pages directly, meaning these architectures do not get a chance to perform their cache maintenance. Modify the read and decompress code to call flush_icache_range() on all pages that are restored, so that the restored in-place pages are guaranteed to be executable on these architectures. Signed-off-by: James Morse <james.morse@arm.com> Acked-by: Pavel Machek <pavel@ucw.cz> Acked-by: Rafael J. Wysocki <rjw@rjwysocki.net> Acked-by: Catalin Marinas <catalin.marinas@arm.com> [will: make clean_pages_on_* static and remove initialisers] Signed-off-by: Will Deacon <will.deacon@arm.com> (cherry picked from commit f6cf0545ec697ddc278b7457b7d0c0d86a2ea88e) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 files changed, 18 insertions, 0 deletions
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 2f30ca91e4fa..0dedb58d404b 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -37,6 +37,14 @@
+ * When reading an {un,}compressed image, we may restore pages in place,
+ * in which case some architectures need these pages cleaning before they
+ * can be executed. We don't know which pages these may be, so clean the lot.
+ */
+static bool clean_pages_on_read;
+static bool clean_pages_on_decompress;
* The swap map is a data structure used for keeping track of each page
* written to a swap partition. It consists of many swap_map_page
* structures that contain each an array of MAP_PAGE_ENTRIES swap entries.
@@ -245,6 +253,9 @@ static void hib_end_io(struct bio *bio, int error)
if (bio_data_dir(bio) == WRITE)
+ else if (clean_pages_on_read)
+ flush_icache_range((unsigned long)page_address(page),
+ (unsigned long)page_address(page) + PAGE_SIZE);
if (error && !hb->error)
hb->error = error;
@@ -1053,6 +1064,7 @@ static int load_image(struct swap_map_handle *handle,
+ clean_pages_on_read = true;
printk(KERN_INFO "PM: Loading image data pages (%u pages)...\n",
m = nr_to_read / 10;
@@ -1128,6 +1140,10 @@ static int lzo_decompress_threadfn(void *data)
d->unc_len = LZO_UNC_SIZE;
d->ret = lzo1x_decompress_safe(d->cmp + LZO_HEADER, d->cmp_len,
d->unc, &d->unc_len);
+ if (clean_pages_on_decompress)
+ flush_icache_range((unsigned long)d->unc,
+ (unsigned long)d->unc + d->unc_len);
atomic_set(&d->stop, 1);
@@ -1193,6 +1209,8 @@ static int load_image_lzo(struct swap_map_handle *handle,
memset(crc, 0, offsetof(struct crc_data, go));
+ clean_pages_on_decompress = true;
* Start the decompression threads.