PM: hibernate: Enforce ordering during image compression/decompression
commit71cd7e80cfupstream. An S4 (suspend to disk) test on the LoongArch 3A6000 platform sometimes fails with the following error messaged in the dmesg log: Invalid LZO compressed length That happens because when compressing/decompressing the image, the synchronization between the control thread and the compress/decompress/crc thread is based on a relaxed ordering interface, which is unreliable, and the following situation may occur: CPU 0 CPU 1 save_image_lzo lzo_compress_threadfn atomic_set(&d->stop, 1); atomic_read(&data[thr].stop) data[thr].cmp = data[thr].cmp_len; WRITE data[thr].cmp_len Then CPU0 gets a stale cmp_len and writes it to disk. During resume from S4, wrong cmp_len is loaded. To maintain data consistency between the two threads, use the acquire/release variants of atomic set and read operations. Fixes:081a9d043c("PM / Hibernate: Improve performance of LZO/plain hibernation, checksum image") Cc: All applicable <stable@vger.kernel.org> Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn> Co-developed-by: Weihao Li <liweihao@loongson.cn> Signed-off-by: Weihao Li <liweihao@loongson.cn> [ rjw: Subject rewrite and changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
15a67115d4
commit
489506a2a0
+19
-19
@@ -596,11 +596,11 @@ static int crc32_threadfn(void *data)
|
||||
unsigned i;
|
||||
|
||||
while (1) {
|
||||
wait_event(d->go, atomic_read(&d->ready) ||
|
||||
wait_event(d->go, atomic_read_acquire(&d->ready) ||
|
||||
kthread_should_stop());
|
||||
if (kthread_should_stop()) {
|
||||
d->thr = NULL;
|
||||
atomic_set(&d->stop, 1);
|
||||
atomic_set_release(&d->stop, 1);
|
||||
wake_up(&d->done);
|
||||
break;
|
||||
}
|
||||
@@ -609,7 +609,7 @@ static int crc32_threadfn(void *data)
|
||||
for (i = 0; i < d->run_threads; i++)
|
||||
*d->crc32 = crc32_le(*d->crc32,
|
||||
d->unc[i], *d->unc_len[i]);
|
||||
atomic_set(&d->stop, 1);
|
||||
atomic_set_release(&d->stop, 1);
|
||||
wake_up(&d->done);
|
||||
}
|
||||
return 0;
|
||||
@@ -639,12 +639,12 @@ static int lzo_compress_threadfn(void *data)
|
||||
struct cmp_data *d = data;
|
||||
|
||||
while (1) {
|
||||
wait_event(d->go, atomic_read(&d->ready) ||
|
||||
wait_event(d->go, atomic_read_acquire(&d->ready) ||
|
||||
kthread_should_stop());
|
||||
if (kthread_should_stop()) {
|
||||
d->thr = NULL;
|
||||
d->ret = -1;
|
||||
atomic_set(&d->stop, 1);
|
||||
atomic_set_release(&d->stop, 1);
|
||||
wake_up(&d->done);
|
||||
break;
|
||||
}
|
||||
@@ -653,7 +653,7 @@ static int lzo_compress_threadfn(void *data)
|
||||
d->ret = lzo1x_1_compress(d->unc, d->unc_len,
|
||||
d->cmp + LZO_HEADER, &d->cmp_len,
|
||||
d->wrk);
|
||||
atomic_set(&d->stop, 1);
|
||||
atomic_set_release(&d->stop, 1);
|
||||
wake_up(&d->done);
|
||||
}
|
||||
return 0;
|
||||
@@ -791,7 +791,7 @@ static int save_image_lzo(struct swap_map_handle *handle,
|
||||
|
||||
data[thr].unc_len = off;
|
||||
|
||||
atomic_set(&data[thr].ready, 1);
|
||||
atomic_set_release(&data[thr].ready, 1);
|
||||
wake_up(&data[thr].go);
|
||||
}
|
||||
|
||||
@@ -799,12 +799,12 @@ static int save_image_lzo(struct swap_map_handle *handle,
|
||||
break;
|
||||
|
||||
crc->run_threads = thr;
|
||||
atomic_set(&crc->ready, 1);
|
||||
atomic_set_release(&crc->ready, 1);
|
||||
wake_up(&crc->go);
|
||||
|
||||
for (run_threads = thr, thr = 0; thr < run_threads; thr++) {
|
||||
wait_event(data[thr].done,
|
||||
atomic_read(&data[thr].stop));
|
||||
atomic_read_acquire(&data[thr].stop));
|
||||
atomic_set(&data[thr].stop, 0);
|
||||
|
||||
ret = data[thr].ret;
|
||||
@@ -843,7 +843,7 @@ static int save_image_lzo(struct swap_map_handle *handle,
|
||||
}
|
||||
}
|
||||
|
||||
wait_event(crc->done, atomic_read(&crc->stop));
|
||||
wait_event(crc->done, atomic_read_acquire(&crc->stop));
|
||||
atomic_set(&crc->stop, 0);
|
||||
}
|
||||
|
||||
@@ -1124,12 +1124,12 @@ static int lzo_decompress_threadfn(void *data)
|
||||
struct dec_data *d = data;
|
||||
|
||||
while (1) {
|
||||
wait_event(d->go, atomic_read(&d->ready) ||
|
||||
wait_event(d->go, atomic_read_acquire(&d->ready) ||
|
||||
kthread_should_stop());
|
||||
if (kthread_should_stop()) {
|
||||
d->thr = NULL;
|
||||
d->ret = -1;
|
||||
atomic_set(&d->stop, 1);
|
||||
atomic_set_release(&d->stop, 1);
|
||||
wake_up(&d->done);
|
||||
break;
|
||||
}
|
||||
@@ -1142,7 +1142,7 @@ static int lzo_decompress_threadfn(void *data)
|
||||
flush_icache_range((unsigned long)d->unc,
|
||||
(unsigned long)d->unc + d->unc_len);
|
||||
|
||||
atomic_set(&d->stop, 1);
|
||||
atomic_set_release(&d->stop, 1);
|
||||
wake_up(&d->done);
|
||||
}
|
||||
return 0;
|
||||
@@ -1330,7 +1330,7 @@ static int load_image_lzo(struct swap_map_handle *handle,
|
||||
}
|
||||
|
||||
if (crc->run_threads) {
|
||||
wait_event(crc->done, atomic_read(&crc->stop));
|
||||
wait_event(crc->done, atomic_read_acquire(&crc->stop));
|
||||
atomic_set(&crc->stop, 0);
|
||||
crc->run_threads = 0;
|
||||
}
|
||||
@@ -1366,7 +1366,7 @@ static int load_image_lzo(struct swap_map_handle *handle,
|
||||
pg = 0;
|
||||
}
|
||||
|
||||
atomic_set(&data[thr].ready, 1);
|
||||
atomic_set_release(&data[thr].ready, 1);
|
||||
wake_up(&data[thr].go);
|
||||
}
|
||||
|
||||
@@ -1385,7 +1385,7 @@ static int load_image_lzo(struct swap_map_handle *handle,
|
||||
|
||||
for (run_threads = thr, thr = 0; thr < run_threads; thr++) {
|
||||
wait_event(data[thr].done,
|
||||
atomic_read(&data[thr].stop));
|
||||
atomic_read_acquire(&data[thr].stop));
|
||||
atomic_set(&data[thr].stop, 0);
|
||||
|
||||
ret = data[thr].ret;
|
||||
@@ -1416,7 +1416,7 @@ static int load_image_lzo(struct swap_map_handle *handle,
|
||||
ret = snapshot_write_next(snapshot);
|
||||
if (ret <= 0) {
|
||||
crc->run_threads = thr + 1;
|
||||
atomic_set(&crc->ready, 1);
|
||||
atomic_set_release(&crc->ready, 1);
|
||||
wake_up(&crc->go);
|
||||
goto out_finish;
|
||||
}
|
||||
@@ -1424,13 +1424,13 @@ static int load_image_lzo(struct swap_map_handle *handle,
|
||||
}
|
||||
|
||||
crc->run_threads = thr;
|
||||
atomic_set(&crc->ready, 1);
|
||||
atomic_set_release(&crc->ready, 1);
|
||||
wake_up(&crc->go);
|
||||
}
|
||||
|
||||
out_finish:
|
||||
if (crc->run_threads) {
|
||||
wait_event(crc->done, atomic_read(&crc->stop));
|
||||
wait_event(crc->done, atomic_read_acquire(&crc->stop));
|
||||
atomic_set(&crc->stop, 0);
|
||||
}
|
||||
stop = ktime_get();
|
||||
|
||||
Reference in New Issue
Block a user