linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: Askar Safin <safinaskar@gmail.com>
Cc: Dell.Client.Kernel@dell.com, brauner@kernel.org,
	dm-devel@lists.linux.dev,  ebiggers@kernel.org, kix@kix.es,
	linux-block@vger.kernel.org,  linux-btrfs@vger.kernel.org,
	linux-crypto@vger.kernel.org,  linux-lvm@lists.linux.dev,
	linux-mm@kvack.org, linux-pm@vger.kernel.org,
	 linux-raid@vger.kernel.org, lvm-devel@lists.linux.dev,
	agk@redhat.com,  msnitzer@redhat.com, milan@mazyland.cz,
	mzxreary@0pointer.de,  nphamcs@gmail.com, pavel@ucw.cz,
	rafael@kernel.org, ryncsn@gmail.com,
	 torvalds@linux-foundation.org
Subject: [PATCH 1/2] pm-hibernate: flush disk cache when suspending
Date: Fri, 31 Oct 2025 20:33:03 +0100 (CET)	[thread overview]
Message-ID: <c44942f2-cf4d-04c2-908f-d16e2e60aae2@redhat.com> (raw)
In-Reply-To: <de1f0036-84f9-2923-2c0a-620e702d850b@redhat.com>

[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 <mpatocka@redhat.com>
Reported-by: Askar Safin <safinaskar@gmail.com>
Link: https://lore.kernel.org/dm-devel/a48a37e3-2c22-44fb-97a4-0e57dc20421a@gmail.com/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 {



  reply	other threads:[~2025-10-31 19:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-23 11:29 dm bug: hibernate to swap located on dm-integrity doesn't work (how to get data redundancy for swap?) Askar Safin
2025-10-23 20:42 ` Milan Broz
2025-10-24 16:31   ` Askar Safin
2025-10-24 17:50     ` Milan Broz
2025-10-25  5:26     ` Askar Safin
2025-10-27  8:08   ` Askar Safin
     [not found] ` <4cd2d217-f97d-4923-b852-4f8746456704@mazyland.cz>
2025-10-24 10:23   ` [PATCH] pm-hibernate: flush block device cache when hibernating Mikulas Patocka
2025-10-27  8:42     ` Askar Safin
2025-10-31 19:29       ` Mikulas Patocka
2025-10-31 19:33         ` Mikulas Patocka [this message]
2025-11-03 15:53           ` [PATCH 1/2] pm-hibernate: flush disk cache when suspending Askar Safin
2025-10-31 19:35         ` [RFC PATCH 2/2] swsusp: make it possible to hibernate to device mapper devices Mikulas Patocka
2025-10-29 13:31     ` [PATCH] pm-hibernate: flush block device cache when hibernating Rafael J. Wysocki
2025-10-29 14:38       ` Christoph Hellwig
2025-10-29 16:31         ` Mikulas Patocka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c44942f2-cf4d-04c2-908f-d16e2e60aae2@redhat.com \
    --to=mpatocka@redhat.com \
    --cc=Dell.Client.Kernel@dell.com \
    --cc=agk@redhat.com \
    --cc=brauner@kernel.org \
    --cc=dm-devel@lists.linux.dev \
    --cc=ebiggers@kernel.org \
    --cc=kix@kix.es \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-lvm@lists.linux.dev \
    --cc=linux-mm@kvack.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=lvm-devel@lists.linux.dev \
    --cc=milan@mazyland.cz \
    --cc=msnitzer@redhat.com \
    --cc=mzxreary@0pointer.de \
    --cc=nphamcs@gmail.com \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    --cc=ryncsn@gmail.com \
    --cc=safinaskar@gmail.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).