Re: [PATCH] pm-hibernate: flush block device cache when hibernating

"Rafael J. Wysocki" <[email protected]> Wed, 29 Oct 2025 14:31:05 +0100
Newsgroups gmane.linux.lvm.devel
Message-ID <CAJZ5v0gcEjZPVtKrysS=ek7kHpH3afinwY-apKm3Yd4PmKDHdA__21256.8476375722$1761746798$gmane$org@mail.gmail.com>
On Fri, Oct 24, 2025 at 12:23=E2=80=AFPM Mikulas Patocka <[email protected]=
om> wrote:
>
>
>
> On Fri, 24 Oct 2025, Askar Safin wrote:
>
> > Hi.
> >
> > Hibernate to swap located on dm-integrity doesn't work.
> > Let me first describe why I need this, then I will describe a bug with =
steps
> > to reproduce
> > (and some speculation on cause of the bug).
>
> Hi
>
> Does this patch fix it?
>
> Mikulas
>
>
> From: Mikulas Patocka <[email protected]>
>
> There was reported failure that hibernation doesn't work with
> dm-integrity. The reason for the failure is that the hibernation 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.

Hmm, shouldn't it flush every time it does a sync write, and not just
in these two cases?

>
> Signed-off-by: Mikulas Patocka <[email protected]>
> Reported-by: Askar Safin <[email protected]>
> Link: https://lore.kernel.org/dm-devel/a48a37e3-2c22-44fb-97a4-0e57dc2042=
[email protected]/T/
> Cc: [email protected]
>
> ---
>  kernel/power/swap.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> Index: linux-2.6/kernel/power/swap.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> --- linux-2.6.orig/kernel/power/swap.c  2025-10-13 21:42:48.000000000 +02=
00
> +++ linux-2.6/kernel/power/swap.c       2025-10-24 12:01:32.000000000 +02=
00
> @@ -320,8 +320,10 @@ static int mark_swapfiles(struct swap_ma
>                 swsusp_header->flags =3D flags;
>                 if (flags & SF_CRC32_MODE)
>                         swsusp_header->crc32 =3D handle->crc32;
> -               error =3D hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC,
> +               error =3D hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC | RE=
Q_PREFLUSH,
>                                       swsusp_resume_block, swsusp_header)=
;
> +               if (!error)
> +                       error =3D blkdev_issue_flush(file_bdev(hib_resume=
_bdev_file));
>         } else {
>                 pr_err("Swap header not found!\n");
>                 error =3D -ENODEV;
>