[PATCH 1/2] pm-hibernate: flush disk cache when suspending There was reported failure that suspend doesn't work with dm-integrity. The reason for the failure is that the suspend code doesn't issue the FLUSH bio - the data still sits in the dm-integrity cache and they are lost when poweroff happens.
This commit fixes the suspend code so that it issues flushes before writing the header and after writing the header. Note that the system may lose power during suspend - in this situation, we don't want to attempt to resume with invalid data. So, we flush the cache before writing the header (with REQ_PREFLUSH) and after writing the header (with REQ_FUA). The call to flush_swap_writer was moved up in swap_writer_finish, so that it writes the data before mark_swapfiles writes the header. REQ_FUA is also needed on resume, when marking resumed image with the original swap header. Signed-off-by: Mikulas Patocka <[email protected]> Reported-by: Askar Safin <[email protected]> Link: https://lore.kernel.org/dm-devel/[email protected]/T/ --- kernel/power/swap.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) Index: linux-2.6/kernel/power/swap.c =================================================================== --- linux-2.6.orig/kernel/power/swap.c +++ linux-2.6/kernel/power/swap.c @@ -320,7 +320,7 @@ static int mark_swapfiles(struct swap_ma swsusp_header->flags = flags; if (flags & SF_CRC32_MODE) swsusp_header->crc32 = handle->crc32; - error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC, + error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC | REQ_PREFLUSH | REQ_FUA, swsusp_resume_block, swsusp_header); } else { pr_err("Swap header not found!\n"); @@ -486,11 +486,12 @@ static int flush_swap_writer(struct swap static int swap_writer_finish(struct swap_map_handle *handle, unsigned int flags, int error) { + if (!error) + error = flush_swap_writer(handle); if (!error) { pr_info("S"); error = mark_swapfiles(handle, flags); pr_cont("|\n"); - flush_swap_writer(handle); } if (error) @@ -1587,7 +1588,7 @@ int swsusp_check(bool exclusive) memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10); swsusp_header_flags = swsusp_header->flags; /* Reset swap signature now */ - error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC, + error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC | REQ_FUA, swsusp_resume_block, swsusp_header); } else { @@ -1641,7 +1642,7 @@ int swsusp_unmark(void) hib_submit_io_sync(REQ_OP_READ, swsusp_resume_block, swsusp_header); if (!memcmp(HIBERNATE_SIG,swsusp_header->sig, 10)) { memcpy(swsusp_header->sig,swsusp_header->orig_sig, 10); - error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC, + error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC | REQ_FUA, swsusp_resume_block, swsusp_header); } else {
