* dm bug: hibernate to swap located on dm-integrity doesn't work (how to get data redundancy for swap?)
@ 2025-10-23 11:29 Askar Safin
2025-10-23 20:42 ` Milan Broz
[not found] ` <4cd2d217-f97d-4923-b852-4f8746456704@mazyland.cz>
0 siblings, 2 replies; 15+ messages in thread
From: Askar Safin @ 2025-10-23 11:29 UTC (permalink / raw)
To: linux-mm, linux-pm, linux-block, linux-crypto, linux-lvm,
lvm-devel, linux-raid, DellClientKernel, dm-devel, linux-btrfs
Cc: Nhat Pham, Kairui Song, Pavel Machek,
Rodolfo García Peñas (kix), Rafael J. Wysocki,
Eric Biggers, Lennart Poettering, Christian Brauner,
Linus Torvalds
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).
I want a personal Linux laptop fully protected from data corruption (cosmic rays, etc).
And even if data corruption does happen, I want reliable indication of that,
so that I know that I need to restore from backups and replace faulty hardware.
So I did this:
- I bought a laptop with ECC memory: Dell Precision 7780. It seems to be one of
the few laptop models in the world with ECC memory. And probably the only model
in the world, which DOES HAVE ECC memory, but DOES NOT HAVE nvidia card
- I set up btrfs raid-1
So far, so good. I'm protected from both memory errors and disk errors.
But my swap partition stays unprotected. And yes, I need swap. I have 64 GiB of RAM,
but this still is not enough for zillions of Chromium tabs and vscode windows.
And, according to btrfs docs, if I put swapfile to btrfs, it will be exempt from raid-1 guarantees.
It seems that the only solution in this case is to put swap partition on top of dm-integrity.
Note: I don't need error correcting code for my swap. I don't need a self-healing swap.
The only thing I need is reliable error detection.
There is discussion on Stack Exchange on exactly the same problem:
https://unix.stackexchange.com/questions/269098/silent-disk-errors-and-reliability-of-linux-swap .
I think it reached the same conclusion: the only solution is dm-integrity.
Also, as well as I understand, md raid is not a solution: when reading, it reads
from one disk only, and thus doesn't detect all errors. It can detect remaining errors
during scrub, which is too late (wrong data may be already consumed by some app).
Also: I don't need encryption.
(Also: there is other solution: "cryptsetup --integrity", but it uses dm-integrity anyway. We will
get to it.)
Okay, so I put swap partition to dm-integrity, and it worked!
But then hibernation stopped to work.
And here come steps to reproduce.
Okay, so I have Dell Precision 7780. I bought it year ago, so I don't
think my hardware is faulty. Also, I recently updated BIOS.
My OS is Debian Trixie amd64. My kernel is Linux 6.12.48-1 from Debian.
I created swap partition so:
integritysetup format --integrity xxhash64 /dev/disk/by-partuuid/c4bbc73d-7909-42ea-8d96-eab82512cbe7
integritysetup open --integrity xxhash64 /dev/disk/by-partuuid/c4bbc73d-7909-42ea-8d96-eab82512cbe7 swap
mkswap /dev/mapper/swap
swapon /dev/mapper/swap
When I need to activate swap, I do this:
integritysetup open --integrity xxhash64 /dev/disk/by-partuuid/c4bbc73d-7909-42ea-8d96-eab82512cbe7 swap
swapon /dev/mapper/swap
When I need to hibernate, I do "systemctl hibernate".
And hibernate appears to work.
Then, when I need to resume, I boot to my hand-crafted initramfs.
That initramfs does this (I slightly simplified this script):
==
busybox mount -t proc proc /proc
busybox mount -t devtmpfs devtmpfs /dev
busybox mount -t sysfs sysfs /sys
modprobe nvme
modprobe dm-integrity
modprobe xxhash64
sleep 1
integritysetup open --integrity xxhash64 "$LOWER_SWAP_DEV" early-swap
sleep 1
# The following "blkid" command should detect what is present on /dev/mapper/early-swap
TYPE="$(blkid --match-tag TYPE --output value /dev/mapper/early-swap)"
if [ "$TYPE" = 'swsuspend' ]; then
echo "got hibernation image, trying to resume"
echo /dev/mapper/early-swap > /sys/power/resume
elif [ "$TYPE" = 'swap' ]; then
echo 'got normal swap without hibernation image'
integritysetup close early-swap
# proceed with fresh boot here
fi
==
And this doesn't work. Hibernate works, resume doesn't. :)
"blkid" reports swap as "swap" as opposed to "swsuspend".
I suspect this is because hibernation doesn't flush dm-integrity journal.
Also I tried to add "--integrity-bitmap-mode" to "format" and "open".
Resume started to work, but when I try to shutdown resumed system,
I get errors about corrupted dm-integrity partition. (Of course, I
did necessary edits to initramfs script above.)
Also I tried to add "--integrity-no-journal" to "format" and "open".
It didn't work, either. (I don't remember what exactly didn't work.
I can do this experiment again, if needed.)
Then I tried to do "cryptsetup" instead of "integritysetup". I created
swap partition so:
cryptsetup luksFormat --type luks2 /dev/disk/by-partuuid/c4bbc73d-7909-42ea-8d96-eab82512cbe7 /tmp/key
cryptsetup open --type luks2 --key-file /tmp/key /dev/disk/by-partuuid/c4bbc73d-7909-42ea-8d96-eab82512cbe7 swap
mkswap /dev/mapper/swap
swapon /dev/mapper/swap
And, of course, I did all necessary edits to initramfs.
And this time everything worked. This proves that I didn't do any mistakes in my setup
(i. e. I got initramfs right, etc), and this is actual bug in dm-integrity.
Unfortunately, LUKS created such way doesn't have any redundancy. So this is not solution for me.
So I did this:
cryptsetup luksFormat --type luks2 --integrity hmac-sha256 /dev/disk/by-partuuid/c4bbc73d-7909-42ea-8d96-eab82512cbe7 /tmp/key
cryptsetup open --type luks2 --key-file /tmp/key /dev/disk/by-partuuid/c4bbc73d-7909-42ea-8d96-eab82512cbe7 swap
mkswap /dev/mapper/swap
swapon /dev/mapper/swap
And this time everything stopped to work, again. I don't remember what exactly went wrong.
As well as I remember, that "blkid" again returned "swap" instead of "swsuspend".
I can run experiment again, if needed.
The commands above use dm-integrity internally. So we clearly see: if dm-integrity is involved, then hibernation
doesn't work.
Here is a user with exactly same problem:
https://www.reddit.com/r/archlinux/comments/atg18t/hibernation_wipes_swap_and_my_system_hangs_on_boot/ .
I. e. "hibernation doesn't work if swap is on LUKS with integrity protection".
So, please, fix this bug. Or say me how to solve my original problem (i. e. achieving full reliable error
reporting). I'm available for testing. Send me experimental patches. I can provide more info, if needed.
There is yet another potential solution: uswsusp ( https://docs.kernel.org/power/userland-swsusp.html ).
In short, this is hibernation driven from userspace. I. e. uswsusp allows for finer control of hibernation.
Thus, I can write my own userspace util, which will do hibernation, and execute "integritysetup close"
after writing image. Assuming that original problem is what I think (i. e. lack of journal flush after writing of image),
this may work. The problem is... latest commit to userspace implementation is dated 2012-09-15
( https://git.kernel.org/pub/scm/linux/kernel/git/rafael/suspend-utils.git/ ). Do I really need to use such ancient
technology? I didn't test this yet, I will test it in coming days. Even if it works, this will still mean that dm-integrity
is buggy with kernel-based hibernation.
--
Askar Safin
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: dm bug: hibernate to swap located on dm-integrity doesn't work (how to get data redundancy for swap?) 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-27 8:08 ` Askar Safin [not found] ` <4cd2d217-f97d-4923-b852-4f8746456704@mazyland.cz> 1 sibling, 2 replies; 15+ messages in thread From: Milan Broz @ 2025-10-23 20:42 UTC (permalink / raw) To: Askar Safin, linux-mm, linux-pm, linux-block, linux-crypto, linux-lvm, lvm-devel, linux-raid, DellClientKernel, dm-devel, linux-btrfs Cc: Nhat Pham, Kairui Song, Pavel Machek, Rodolfo García Peñas (kix), Rafael J. Wysocki, Eric Biggers, Lennart Poettering, Christian Brauner, Linus Torvalds Hi, I am not sure why you cc so many people, most of lists are not relevant here. Anyway, could you please test one thing below so the problem is better isolated? On 10/23/25 1:29 PM, Askar Safin wrote: ... > Also I tried to add "--integrity-no-journal" to "format" and "open". > It didn't work, either. (I don't remember what exactly didn't work. > I can do this experiment again, if needed.) Are you sure you used --integrity-no-journal both in activation before hibernation and also in resume? If not, please try it. This flag activates direct mode and and completely avoids dm-integrity journal. You can verify it with "integritysetup status <device>" - it should say "journal: not active". And if it does not work, could you try to use -integrity-recovery-mode the same way (both before hibernation and later in resume)? This will effectively ignore checksums providing no protection, but keeping dm-integrity device still in place. You can verify it with "integritysetup status <device>" - it should say "mode: read/write recovery". Is the problem still in place with this setting? You can also try to decrease journal commit time with --journal-commit-time option, but this is not a real solution. ...> > Then I tried to do "cryptsetup" instead of "integritysetup". I created > swap partition so: > > cryptsetup luksFormat --type luks2 /dev/disk/by-partuuid/c4bbc73d-7909-42ea-8d96-eab82512cbe7 /tmp/key > cryptsetup open --type luks2 --key-file /tmp/key /dev/disk/by-partuuid/c4bbc73d-7909-42ea-8d96-eab82512cbe7 swap > mkswap /dev/mapper/swap > swapon /dev/mapper/swap > > And, of course, I did all necessary edits to initramfs. > > And this time everything worked. This proves that I didn't do any mistakes in my setup > (i. e. I got initramfs right, etc), and this is actual bug in dm-integrity. > > Unfortunately, LUKS created such way doesn't have any redundancy. So this is not solution for me. Redundancy? You mean data integrity protection? There is no redundancy, only additional authentication tag (detecting integrity error but not correcting it). Thanks, Milan ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: dm bug: hibernate to swap located on dm-integrity doesn't work (how to get data redundancy for swap?) 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 1 sibling, 2 replies; 15+ messages in thread From: Askar Safin @ 2025-10-24 16:31 UTC (permalink / raw) To: gmazyland Cc: Dell.Client.Kernel, brauner, dm-devel, ebiggers, kix, linux-block, linux-btrfs, linux-crypto, linux-lvm, linux-mm, linux-pm, linux-raid, lvm-devel, mzxreary, nphamcs, pavel, rafael, ryncsn, safinaskar, torvalds Milan Broz <gmazyland@gmail.com>: > Hi, I just wrote script for reproduction of this bug in Qemu: https://zerobin.net/?4e742925aedbecc6#BX3Tulvp7E3gKhopFKrx/2ZdOelMyYk1qOyitcOr1h8= Just run it, and you will reproduce this bug, too. Also, I just reproduced it on current master (43e9ad0c55a3). Here is output of this script on master: https://zerobin.net/?68ef6601ab203a11#7zBZ44AaVKmvRq161MJaOXIXY/5Hiv+hRUxWoqyZ7uE= As you can see, hibernate succeeds, but resume fails so: + blkid --match-tag TYPE --output value /dev/mapper/early-swap + TYPE=swap + echo 'Type: swap' Type: swap + echo /dev/mapper/early-swap [ 0.446545] PM: Image not found (code -22) Also, I just noticed that the bug sometimes reproduces, and sometimes not. Still it reproduces more than 50% of time. Also, you will find backtrace in logs above. Disregard it. I think this is just some master bug, which is unrelated to our dm-integrity bug. I will answer to rest of your letter later. Also, I saw patch, I will test it later. -- Askar Safin ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: dm bug: hibernate to swap located on dm-integrity doesn't work (how to get data redundancy for swap?) 2025-10-24 16:31 ` Askar Safin @ 2025-10-24 17:50 ` Milan Broz 2025-10-25 5:26 ` Askar Safin 1 sibling, 0 replies; 15+ messages in thread From: Milan Broz @ 2025-10-24 17:50 UTC (permalink / raw) To: Askar Safin Cc: Dell.Client.Kernel, brauner, dm-devel, ebiggers, kix, linux-block, linux-btrfs, linux-crypto, linux-lvm, linux-mm, linux-pm, linux-raid, lvm-devel, mzxreary, nphamcs, pavel, rafael, ryncsn, torvalds, Mikulas Patocka On 10/24/25 6:31 PM, Askar Safin wrote: > > Also, I saw patch, I will test it later. Yes, please test it, you can ignore may previous comments as they are irrelevant now. Here is the link to the mentioned patch: https://lore.kernel.org/dm-devel/03e58462-5045-e12f-9af6-be2aaf19f32c@redhat.com/T/#u I think that the issue is clear (as found by Mikulas) - DM device (dm-integrity here) does not receive the FLUSH command here. This would explain all issues you see. If the patch works, it should be fixed in stable kernels as it impacts other more complex storage configurations. Thanks, Milan ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: dm bug: hibernate to swap located on dm-integrity doesn't work (how to get data redundancy for swap?) 2025-10-24 16:31 ` Askar Safin 2025-10-24 17:50 ` Milan Broz @ 2025-10-25 5:26 ` Askar Safin 1 sibling, 0 replies; 15+ messages in thread From: Askar Safin @ 2025-10-25 5:26 UTC (permalink / raw) To: safinaskar Cc: Dell.Client.Kernel, brauner, dm-devel, ebiggers, gmazyland, kix, linux-block, linux-btrfs, linux-crypto, linux-lvm, linux-mm, linux-pm, linux-raid, lvm-devel, mzxreary, nphamcs, pavel, rafael, ryncsn, torvalds Askar Safin <safinaskar@gmail.com>: > Here is output of this script on master: > https://zerobin.net/?68ef6601ab203a11#7zBZ44AaVKmvRq161MJaOXIXY/5Hiv+hRUxWoqyZ7uE= [...] > Also, you will find backtrace in logs above. Disregard it. I think this > is just some master bug, which is unrelated to our dm-integrity bug. That WARNING in logs is unrelated bug, which happens always when I hibernate. I reported it here: https://lore.kernel.org/regressions/20251025050812.421905-1-safinaskar@gmail.com/ -- Askar Safin ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: dm bug: hibernate to swap located on dm-integrity doesn't work (how to get data redundancy for swap?) 2025-10-23 20:42 ` Milan Broz 2025-10-24 16:31 ` Askar Safin @ 2025-10-27 8:08 ` Askar Safin 1 sibling, 0 replies; 15+ messages in thread From: Askar Safin @ 2025-10-27 8:08 UTC (permalink / raw) To: gmazyland Cc: Dell.Client.Kernel, brauner, dm-devel, ebiggers, kix, linux-block, linux-btrfs, linux-crypto, linux-lvm, linux-mm, linux-pm, linux-raid, lvm-devel, mzxreary, nphamcs, pavel, rafael, ryncsn, safinaskar, torvalds Milan Broz <gmazyland@gmail.com>: > Hi, That patch doesn't fix the problem. I will send more details within some days, hopefully today. Also, I just found that for reliable reproduction you need to do "swapoff /dev/mapper/swap; cat /dev/mapper/swap > /dev/null" after resume (assuming you were able to resume, of course). So here is updated script for reproduction in Qemu: https://zerobin.net/?0aa379bae218cf92#DDVFMvfi6S3ydCQLSrL+us1lHjXQJIZasW55JI7gEfU= This script is very easy to use! Try 1-2 times to reproduce. Here is result of that script: https://zerobin.net/?3d9447900052f9ce#ng0htJDAdSsvqVunL+BnoLHXszM6ardt9R3wkbO9L28= This results are on 43e9ad0c55a3, which is current master, without Mikulas Patocka's patch, but with this Mario's patch: https://lore.kernel.org/linux-pm/20251026033115.436448-1-superm1@kernel.org/ . Mario's patch is needed, otherwise we get WARNING when we try to hibernate. Again: these logs are without Mikulas Patocka's patch. I will send results of testing his patch later, hopefully today. But don't expect much. As I said, his patch doesn't work. "log-def-1" is output of first Qemu invocation (i. e. first boot) with default integritysetup options. "log-def-2" is second Qemu invocation (i. e. when we try to resume). log-bit-{1,2} is same thing, but with "--integrity-bitmap-mode" added to "integritysetup format" and "integritysetup open". log-no-{1,2} is same, but with "--integrity-no-journal". log-nodm-{1,2} is same, but without dm-integrity at all, i. e. we create swap directly on partition. As you can see in logs, hibernate with dm-integrity never works perfectly. We either unable to resume, either we are able to resume, but then get integrity errors when we do "cat /dev/mapper/swap > /dev/null". Swap directly on partition works. Again: you may need 1-2 attempts to reproduce using this script. Also: the bug is reproducible even if we do "echo test_resume > /sys/power/disk". > Are you sure you used --integrity-no-journal both in activation before > hibernation and also in resume? If not, please try it. I'm totally sure. (You can see script above and "set -x" output in logs.) > You can verify it with "integritysetup status <device>" - it should say "journal: not active". I just checked. It indeed says so. > And if it does not work, could you try to use -integrity-recovery-mode the same > way (both before hibernation and later in resume)? This will effectively ignore checksums So I should pass it to both "integritysetup open" invocations, but not to "integritysetup format" invocation. Right? Okay, I did so. I. e. I did this: integritysetup format --batch-mode --integrity xxhash64 /dev/sda # when formatting integritysetup open --integrity-recovery-mode --integrity xxhash64 /dev/sda swap # before hibernate integritysetup open --integrity-recovery-mode --integrity xxhash64 /dev/sda early-swap # when resuming And something completely unexpected happened! "swapon" failed immediately after "mkswap"!!! I. e. "swapon" was unable to read swap signature right after "mkswap". Here is log: https://zerobin.net/?ebe34fc9ce94be45#6DWKSXvgUDKIrF4299th0ylhQNEcdqeeBfxzSJjROpA= This seems like another dm-integrity bug. > You can verify it with "integritysetup status <device>" - it should say "mode: read/write recovery". Yes, it says so in logs above. > You can also try to decrease journal commit time with --journal-commit-time option, I just put "--journal-commit-time 1" to format and both opens. I got the same result I get with default options: i. e. blkid returns "swap" instead of "swsuspend", when I try to resume. Here are logs: https://zerobin.net/?c5f8320eb89b1cfb#drrxRgnGk817oEDUA8idhn+WEQgocWjtbsAYuEHF5rI= . > Redundancy? You mean data integrity protection? There is no redundancy, only additional authentication tag > (detecting integrity error but not correcting it). Yes, I meant integrity protection. -- Askar Safin ^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <4cd2d217-f97d-4923-b852-4f8746456704@mazyland.cz>]
* [PATCH] pm-hibernate: flush block device cache when hibernating [not found] ` <4cd2d217-f97d-4923-b852-4f8746456704@mazyland.cz> @ 2025-10-24 10:23 ` Mikulas Patocka 2025-10-27 8:42 ` Askar Safin 2025-10-29 13:31 ` [PATCH] pm-hibernate: flush block device cache when hibernating Rafael J. Wysocki 0 siblings, 2 replies; 15+ messages in thread From: Mikulas Patocka @ 2025-10-24 10:23 UTC (permalink / raw) To: Askar Safin Cc: linux-mm, linux-pm, linux-block, linux-crypto, linux-lvm, lvm-devel, linux-raid, DellClientKernel, dm-devel, linux-btrfs, Nhat Pham, Kairui Song, Pavel Machek, Rodolfo García Peñas, Rafael J. Wysocki, Eric Biggers, Lennart Poettering, Christian Brauner, Linus Torvalds, Milan Broz 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 <mpatocka@redhat.com> 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. 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/ Cc: stable@vger.kernel.org --- kernel/power/swap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) Index: linux-2.6/kernel/power/swap.c =================================================================== --- linux-2.6.orig/kernel/power/swap.c 2025-10-13 21:42:48.000000000 +0200 +++ linux-2.6/kernel/power/swap.c 2025-10-24 12:01:32.000000000 +0200 @@ -320,8 +320,10 @@ 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, swsusp_resume_block, swsusp_header); + if (!error) + error = blkdev_issue_flush(file_bdev(hib_resume_bdev_file)); } else { pr_err("Swap header not found!\n"); error = -ENODEV; ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] pm-hibernate: flush block device cache when hibernating 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-29 13:31 ` [PATCH] pm-hibernate: flush block device cache when hibernating Rafael J. Wysocki 1 sibling, 1 reply; 15+ messages in thread From: Askar Safin @ 2025-10-27 8:42 UTC (permalink / raw) To: mpatocka Cc: Dell.Client.Kernel, brauner, dm-devel, ebiggers, kix, linux-block, linux-btrfs, linux-crypto, linux-lvm, linux-mm, linux-pm, linux-raid, lvm-devel, milan, mzxreary, nphamcs, pavel, rafael, ryncsn, safinaskar, torvalds Mikulas Patocka <mpatocka@redhat.com>: > Hi > > Does this patch fix it? > > Mikulas > > > From: Mikulas Patocka <mpatocka@redhat.com> > > 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. I tested this patch in Qemu on current master (43e9ad0c55a3). Also I applied Mario's patch https://lore.kernel.org/linux-pm/20251026033115.436448-1-superm1@kernel.org/ . It is needed, otherwise you get WARNING when you try to hibernate. The patch doesn't work. Here is script I used for reproduction: https://zerobin.net/?66669be7d2404586#xWufhCq7zCoOk3LJcJCj7W4k3vYT3U4vhGutTN3p8m0= . It is the same script as in previous letter. I just added some "integritysetup status /dev/mapper/..." calls. Here are results: https://zerobin.net/?2331637d633d20c5#EmyhxiHLDmoZT1jBVbe/q9iJKhDEw4n+Bwr5mAcaOpM= . File names mean the same as in previous letter, i. e.: > "log-def-1" is output of first Qemu invocation (i. e. first boot) with > default integritysetup options. "log-def-2" is second Qemu invocation > (i. e. when we try to resume). > > log-bit-{1,2} is same thing, but with "--integrity-bitmap-mode" added to > "integritysetup format" and "integritysetup open". > > log-no-{1,2} is same, but with "--integrity-no-journal". > > log-nodm-{1,2} is same, but without dm-integrity at all, i. e. we create > swap directly on partition. Results are somewhat better than without the patch. Without the patch we don't even try to resume in default mode. "blkid" simply reports "swap" instead of "swsuspend". With patch "blkid" reports "swsuspend", and so we try to resume. But then in the middle of resuming we get this: [ 1.008223] PM: Image loading progress: 70% [ 1.017478] PM: Image loading progress: 80% [ 1.027069] PM: Image loading progress: 90% [ 1.029653] PM: hibernation: Read 36196 kbytes in 0.49 seconds (73.86 MB/s) [ 1.030146] PM: Error -1 resuming [ 1.030322] PM: hibernation: Failed to load image, recovering. (See link above for full logs.) Very similar thing happens in "--integrity-no-journal" mode in the middle of resuming: [ 0.531245] device-mapper: integrity: dm-0: Checksum failed at sector 0x6e70 [ 0.531600] PM: Error -84 resuming [ 0.531799] PM: hibernation: Failed to load image, recovering. The patch doesn't change anything in "--integrity-bitmap-mode" mode: we still are able to resume, but then get integrity errors when we do "cat /dev/mapper/swap > /dev/null". -- Askar Safin ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] pm-hibernate: flush block device cache when hibernating 2025-10-27 8:42 ` Askar Safin @ 2025-10-31 19:29 ` Mikulas Patocka 2025-10-31 19:33 ` [PATCH 1/2] pm-hibernate: flush disk cache when suspending Mikulas Patocka 2025-10-31 19:35 ` [RFC PATCH 2/2] swsusp: make it possible to hibernate to device mapper devices Mikulas Patocka 0 siblings, 2 replies; 15+ messages in thread From: Mikulas Patocka @ 2025-10-31 19:29 UTC (permalink / raw) To: Askar Safin Cc: Dell.Client.Kernel, brauner, dm-devel, ebiggers, kix, linux-block, linux-btrfs, linux-crypto, linux-lvm, linux-mm, linux-pm, linux-raid, lvm-devel, agk, msnitzer, milan, mzxreary, nphamcs, pavel, rafael, ryncsn, torvalds On Mon, 27 Oct 2025, Askar Safin wrote: > Mikulas Patocka <mpatocka@redhat.com>: > > Hi > > > > Does this patch fix it? > > > > Mikulas > > > > > > From: Mikulas Patocka <mpatocka@redhat.com> > > > > 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. > > I tested this patch in Qemu on current master (43e9ad0c55a3). Also I > applied Mario's patch > https://lore.kernel.org/linux-pm/20251026033115.436448-1-superm1@kernel.org/ . > It is needed, otherwise you get WARNING when you try to hibernate. > > The patch doesn't work. Yes, I see - the problem is harder than I thought. I've created two patches and I tested them that they work. So, you can try them. Mikulas ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 1/2] pm-hibernate: flush disk cache when suspending 2025-10-31 19:29 ` Mikulas Patocka @ 2025-10-31 19:33 ` Mikulas Patocka 2025-11-03 15:53 ` Askar Safin 2025-10-31 19:35 ` [RFC PATCH 2/2] swsusp: make it possible to hibernate to device mapper devices Mikulas Patocka 1 sibling, 1 reply; 15+ messages in thread From: Mikulas Patocka @ 2025-10-31 19:33 UTC (permalink / raw) To: Askar Safin Cc: Dell.Client.Kernel, brauner, dm-devel, ebiggers, kix, linux-block, linux-btrfs, linux-crypto, linux-lvm, linux-mm, linux-pm, linux-raid, lvm-devel, agk, msnitzer, milan, mzxreary, nphamcs, pavel, rafael, ryncsn, torvalds [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 { ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 1/2] pm-hibernate: flush disk cache when suspending 2025-10-31 19:33 ` [PATCH 1/2] pm-hibernate: flush disk cache when suspending Mikulas Patocka @ 2025-11-03 15:53 ` Askar Safin 0 siblings, 0 replies; 15+ messages in thread From: Askar Safin @ 2025-11-03 15:53 UTC (permalink / raw) To: mpatocka Cc: Dell.Client.Kernel, agk, brauner, dm-devel, ebiggers, kix, linux-block, linux-btrfs, linux-crypto, linux-lvm, linux-mm, linux-pm, linux-raid, lvm-devel, milan, msnitzer, mzxreary, nphamcs, pavel, rafael, ryncsn, safinaskar, torvalds Mikulas Patocka <mpatocka@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. Thank you! I hope I will test this within 2 weeks. -- Askar Safin ^ permalink raw reply [flat|nested] 15+ messages in thread
* [RFC PATCH 2/2] swsusp: make it possible to hibernate to device mapper devices 2025-10-31 19:29 ` Mikulas Patocka 2025-10-31 19:33 ` [PATCH 1/2] pm-hibernate: flush disk cache when suspending Mikulas Patocka @ 2025-10-31 19:35 ` Mikulas Patocka 1 sibling, 0 replies; 15+ messages in thread From: Mikulas Patocka @ 2025-10-31 19:35 UTC (permalink / raw) To: Askar Safin Cc: Dell.Client.Kernel, brauner, dm-devel, ebiggers, kix, linux-block, linux-btrfs, linux-crypto, linux-lvm, linux-mm, linux-pm, linux-raid, lvm-devel, agk, msnitzer, milan, mzxreary, nphamcs, pavel, rafael, ryncsn, torvalds Hi Askar Safin requires swap and hibernation on the dm-integrity device mapper target because he needs to protect his data. This hits two problems: 1. The kernel doesn't send the flush bio to the hibernation device after writing the image and before powering off - this is easy to fix 2. The dm-integrity target keeps parts of the device in-memory - it keeps a journal and a dm-bufio cache in memory. If we hibernate and resume, the content of memory no longer matches the data on the hibernate partition and that may cause spurious errors - this is hard to fix We cannot use register_pm_notifier - the problem is that device mapper devices may depend on each other, forming a directed acyclic graph, and we need to suspend them in the order of the graph. PM notifiers have no notion of the graph - they have priority, but mapping the priorities to the device dependency graph would be hard. So I added a new method "hibernate" to struct block_device_operations. If the method is NULL, the device doesn't need special treatment during hibernation. If the method is non-NULL, the method is called on the swap device where we are suspending - the method will clear in-memory structures (in the case of dm-integrity, it will flush the journal and invalidate the dm-bufio cache), so that when the machine is resumed, the driver won't use stale data. Finally, the "hibernate" method calls itself on subordinate devices, so that complex stack of device mapper devices is handled correctly. Hibernation is allowed only on targets that have DM_TARGET_HIBERNATE. Hibernation on other targets is rejected because it may cause data corruption. Previously, the kernel would allow hibernation on any DM device, causing potential data corruption if the in-memory metadata doesn't match the content of the swap device. I am submitting this patch as a request for comment - I'd like to know if you consider this approach correct or not. If you would like to solve the hibernation problem in some other way, let me know. 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/ --- drivers/md/dm-crypt.c | 2 - drivers/md/dm-integrity.c | 42 ++++++++++++++++++++++++++++++++++++++- drivers/md/dm-linear.c | 2 - drivers/md/dm-stripe.c | 3 +- drivers/md/dm.c | 45 ++++++++++++++++++++++++++++++++++++++++++ include/linux/blkdev.h | 12 +++++++++++ include/linux/device-mapper.h | 6 +++++ kernel/power/hibernate.c | 4 +++ kernel/power/power.h | 2 + kernel/power/swap.c | 20 ++++++++++++++++++ 10 files changed, 134 insertions(+), 4 deletions(-) Index: linux-2.6/include/linux/blkdev.h =================================================================== --- linux-2.6.orig/include/linux/blkdev.h +++ linux-2.6/include/linux/blkdev.h @@ -1676,6 +1676,11 @@ struct block_device_operations { * driver. */ int (*alternative_gpt_sector)(struct gendisk *disk, sector_t *sector); + + /* + * This invalidates the device cache when hibernating. + */ + int (*hibernate)(struct gendisk *disk); }; #ifdef CONFIG_COMPAT @@ -1875,4 +1880,11 @@ static inline int bio_split_rw_at(struct #define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { } +static inline int bdev_hibernate(struct block_device *bdev) +{ + if (!bdev->bd_disk->fops->hibernate) + return 0; + return bdev->bd_disk->fops->hibernate(bdev->bd_disk); +} + #endif /* _LINUX_BLKDEV_H */ Index: linux-2.6/drivers/md/dm-integrity.c =================================================================== --- linux-2.6.orig/drivers/md/dm-integrity.c +++ linux-2.6/drivers/md/dm-integrity.c @@ -4053,6 +4053,45 @@ static void dm_integrity_io_hints(struct limits->max_integrity_segments = USHRT_MAX; } +static int dm_integrity_hibernate(struct dm_target *ti) +{ + struct dm_integrity_c *ic = ti->private; + int r; + + timer_delete_sync(&ic->autocommit_timer); + + if (ic->recalc_wq) + drain_workqueue(ic->recalc_wq); /* !!! FIXME */ + + if (ic->mode == 'B') + cancel_delayed_work_sync(&ic->bitmap_flush_work); + + queue_work(ic->commit_wq, &ic->commit_work); + drain_workqueue(ic->commit_wq); + + if (ic->mode == 'J') { + queue_work(ic->writer_wq, &ic->writer_work); + drain_workqueue(ic->writer_wq); + dm_integrity_flush_buffers(ic, true); + init_journal(ic, ic->free_section, + ic->journal_sections - ic->free_section, ic->commit_seq); + if (ic->free_section) { + init_journal(ic, 0, ic->free_section, + next_commit_seq(ic->commit_seq)); + } + } + + dm_bufio_client_reset(ic->bufio); + + if (ic->meta_dev) { + r = bdev_hibernate(ic->meta_dev->bdev); + if (r) + return r; + } + + return 0; +} + static void calculate_journal_section_size(struct dm_integrity_c *ic) { unsigned int sector_space = JOURNAL_SECTOR_DATA; @@ -5414,7 +5453,7 @@ static struct target_type integrity_targ .name = "integrity", .version = {1, 14, 0}, .module = THIS_MODULE, - .features = DM_TARGET_SINGLETON | DM_TARGET_INTEGRITY, + .features = DM_TARGET_SINGLETON | DM_TARGET_INTEGRITY | DM_TARGET_HIBERNATE, .ctr = dm_integrity_ctr, .dtr = dm_integrity_dtr, .map = dm_integrity_map, @@ -5424,6 +5463,7 @@ static struct target_type integrity_targ .status = dm_integrity_status, .iterate_devices = dm_integrity_iterate_devices, .io_hints = dm_integrity_io_hints, + .hibernate = dm_integrity_hibernate, }; static int __init dm_integrity_init(void) Index: linux-2.6/drivers/md/dm.c =================================================================== --- linux-2.6.orig/drivers/md/dm.c +++ linux-2.6/drivers/md/dm.c @@ -3439,6 +3439,50 @@ out: return ret; } +static int __dm_hibernate(struct dm_target *ti, struct dm_dev *dev, + sector_t start, sector_t len, void *data) +{ + return bdev_hibernate(dev->bdev); +} + +static int dm_blk_hibernate(struct gendisk *disk) +{ + struct mapped_device *md = disk->private_data; + int srcu_idx; + struct dm_table *map; + int r = 0; + + map = dm_get_live_table(md, &srcu_idx); + if (unlikely(!map)) + goto out; + + for (unsigned int i = 0; i < map->num_targets; i++) { + struct dm_target *ti = dm_table_get_target(map, i); + + if (!dm_target_supports_hibernate(ti->type)) { + r = -EOPNOTSUPP; + goto out; + } + + if (ti->type->hibernate) { + r = ti->type->hibernate(ti); + if (r) + goto out; + } + + if (ti->type->iterate_devices) { + r = ti->type->iterate_devices(ti, __dm_hibernate, NULL); + if (r) + goto out; + } + } + +out: + dm_put_live_table(md, srcu_idx); + + return r; +} + struct dm_pr { u64 old_key; u64 new_key; @@ -3768,6 +3812,7 @@ static const struct block_device_operati .getgeo = dm_blk_getgeo, .report_zones = dm_blk_report_zones, .get_unique_id = dm_blk_get_unique_id, + .hibernate = dm_blk_hibernate, .pr_ops = &dm_pr_ops, .owner = THIS_MODULE }; Index: linux-2.6/include/linux/device-mapper.h =================================================================== --- linux-2.6.orig/include/linux/device-mapper.h +++ linux-2.6/include/linux/device-mapper.h @@ -142,6 +142,8 @@ typedef int (*dm_iterate_devices_fn) (st typedef void (*dm_io_hints_fn) (struct dm_target *ti, struct queue_limits *limits); +typedef int (*dm_hibernate_fn) (struct dm_target *ti); + /* * Returns: * 0: The target can handle the next I/O immediately. @@ -219,6 +221,7 @@ struct target_type { dm_busy_fn busy; dm_iterate_devices_fn iterate_devices; dm_io_hints_fn io_hints; + dm_hibernate_fn hibernate; dm_dax_direct_access_fn direct_access; dm_dax_zero_page_range_fn dax_zero_page_range; dm_dax_recovery_write_fn dax_recovery_write; @@ -309,6 +312,9 @@ struct target_type { #define DM_TARGET_ATOMIC_WRITES 0x00000400 #define dm_target_supports_atomic_writes(type) ((type)->features & DM_TARGET_ATOMIC_WRITES) +#define DM_TARGET_HIBERNATE 0x00000800 +#define dm_target_supports_hibernate(type) ((type)->features & DM_TARGET_HIBERNATE) + struct dm_target { struct dm_table *table; struct target_type *type; Index: linux-2.6/kernel/power/hibernate.c =================================================================== --- linux-2.6.orig/kernel/power/hibernate.c +++ linux-2.6/kernel/power/hibernate.c @@ -832,6 +832,10 @@ int hibernate(void) if (error) goto Exit; + error = notify_swap_device(); + if (error) + goto Thaw; + lock_device_hotplug(); /* Allocate memory management structures */ error = create_basic_memory_bitmaps(); Index: linux-2.6/kernel/power/power.h =================================================================== --- linux-2.6.orig/kernel/power/power.h +++ linux-2.6/kernel/power/power.h @@ -68,6 +68,8 @@ extern int hibernation_snapshot(int plat extern int hibernation_restore(int platform_mode); extern int hibernation_platform_enter(void); +extern int notify_swap_device(void); + #ifdef CONFIG_STRICT_KERNEL_RWX /* kernel/power/snapshot.c */ extern void enable_restore_image_protection(void); Index: linux-2.6/kernel/power/swap.c =================================================================== --- linux-2.6.orig/kernel/power/swap.c +++ linux-2.6/kernel/power/swap.c @@ -1591,6 +1591,9 @@ int swsusp_check(bool exclusive) error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC | REQ_FUA, swsusp_resume_block, swsusp_header); + + /* Flush device-mapper related metadata */ + bdev_hibernate(file_bdev(hib_resume_bdev_file)); } else { error = -EINVAL; } @@ -1630,6 +1633,23 @@ void swsusp_close(void) fput(hib_resume_bdev_file); } +int notify_swap_device(void) +{ + int error; + + error = swsusp_swap_check(); + if (error) + return error; + + error = bdev_hibernate(file_bdev(hib_resume_bdev_file)); + if (error) + pr_err("Swap is on unsupported device\n"); + + swsusp_close(); + + return error; +} + /** * swsusp_unmark - Unmark swsusp signature in the resume device */ Index: linux-2.6/drivers/md/dm-crypt.c =================================================================== --- linux-2.6.orig/drivers/md/dm-crypt.c +++ linux-2.6/drivers/md/dm-crypt.c @@ -3770,7 +3770,7 @@ static struct target_type crypt_target = .module = THIS_MODULE, .ctr = crypt_ctr, .dtr = crypt_dtr, - .features = DM_TARGET_ZONED_HM, + .features = DM_TARGET_ZONED_HM | DM_TARGET_HIBERNATE, .report_zones = crypt_report_zones, .map = crypt_map, .status = crypt_status, Index: linux-2.6/drivers/md/dm-linear.c =================================================================== --- linux-2.6.orig/drivers/md/dm-linear.c +++ linux-2.6/drivers/md/dm-linear.c @@ -204,7 +204,7 @@ static struct target_type linear_target .version = {1, 5, 0}, .features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT | DM_TARGET_ZONED_HM | DM_TARGET_PASSES_CRYPTO | - DM_TARGET_ATOMIC_WRITES, + DM_TARGET_ATOMIC_WRITES | DM_TARGET_HIBERNATE, .report_zones = linear_report_zones, .module = THIS_MODULE, .ctr = linear_ctr, Index: linux-2.6/drivers/md/dm-stripe.c =================================================================== --- linux-2.6.orig/drivers/md/dm-stripe.c +++ linux-2.6/drivers/md/dm-stripe.c @@ -471,7 +471,8 @@ static struct target_type stripe_target .name = "striped", .version = {1, 7, 0}, .features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT | - DM_TARGET_ATOMIC_WRITES | DM_TARGET_PASSES_CRYPTO, + DM_TARGET_ATOMIC_WRITES | DM_TARGET_PASSES_CRYPTO | + DM_TARGET_HIBERNATE, .module = THIS_MODULE, .ctr = stripe_ctr, .dtr = stripe_dtr, ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] pm-hibernate: flush block device cache when hibernating 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-29 13:31 ` Rafael J. Wysocki 2025-10-29 14:38 ` Christoph Hellwig 1 sibling, 1 reply; 15+ messages in thread From: Rafael J. Wysocki @ 2025-10-29 13:31 UTC (permalink / raw) To: Mikulas Patocka Cc: Askar Safin, linux-mm, linux-pm, linux-block, linux-crypto, linux-lvm, lvm-devel, linux-raid, DellClientKernel, dm-devel, linux-btrfs, Nhat Pham, Kairui Song, Pavel Machek, Rodolfo García Peñas, Rafael J. Wysocki, Eric Biggers, Lennart Poettering, Christian Brauner, Linus Torvalds, Milan Broz On Fri, Oct 24, 2025 at 12:23 PM Mikulas Patocka <mpatocka@redhat.com> 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 <mpatocka@redhat.com> > > 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 <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/ > Cc: stable@vger.kernel.org > > --- > kernel/power/swap.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > Index: linux-2.6/kernel/power/swap.c > =================================================================== > --- linux-2.6.orig/kernel/power/swap.c 2025-10-13 21:42:48.000000000 +0200 > +++ linux-2.6/kernel/power/swap.c 2025-10-24 12:01:32.000000000 +0200 > @@ -320,8 +320,10 @@ 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, > swsusp_resume_block, swsusp_header); > + if (!error) > + error = blkdev_issue_flush(file_bdev(hib_resume_bdev_file)); > } else { > pr_err("Swap header not found!\n"); > error = -ENODEV; > ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] pm-hibernate: flush block device cache when hibernating 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 0 siblings, 1 reply; 15+ messages in thread From: Christoph Hellwig @ 2025-10-29 14:38 UTC (permalink / raw) To: Rafael J. Wysocki Cc: Mikulas Patocka, Askar Safin, linux-mm, linux-pm, linux-block, linux-crypto, linux-lvm, lvm-devel, linux-raid, DellClientKernel, dm-devel, linux-btrfs, Nhat Pham, Kairui Song, Pavel Machek, Rodolfo García Peñas, Eric Biggers, Lennart Poettering, Christian Brauner, Linus Torvalds, Milan Broz On Wed, Oct 29, 2025 at 02:31:05PM +0100, Rafael J. Wysocki wrote: > > 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? It certainly should not use the PREFLUSH flag that flushes before writing, as the cache will be dirty again after that. I'd expect a single blkdev_issue_flush after all writing is done, under the assumption that the swsusp swap writing doesn't have transaction integrity for individual writes anyway. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] pm-hibernate: flush block device cache when hibernating 2025-10-29 14:38 ` Christoph Hellwig @ 2025-10-29 16:31 ` Mikulas Patocka 0 siblings, 0 replies; 15+ messages in thread From: Mikulas Patocka @ 2025-10-29 16:31 UTC (permalink / raw) To: Christoph Hellwig Cc: Rafael J. Wysocki, Askar Safin, linux-mm, linux-pm, linux-block, linux-crypto, linux-lvm, lvm-devel, linux-raid, DellClientKernel, dm-devel, linux-btrfs, Nhat Pham, Kairui Song, Pavel Machek, Rodolfo García Peñas, Eric Biggers, Lennart Poettering, Christian Brauner, Linus Torvalds, Milan Broz On Wed, 29 Oct 2025, Christoph Hellwig wrote: > On Wed, Oct 29, 2025 at 02:31:05PM +0100, Rafael J. Wysocki wrote: > > > 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? > > It certainly should not use the PREFLUSH flag that flushes before > writing, as the cache will be dirty again after that. > > I'd expect a single blkdev_issue_flush after all writing is done, > under the assumption that the swsusp swap writing doesn't have > transaction integrity for individual writes anyway. I think that we should use two flushes - one before writing the header and the other after writing the header. Otherwise, it could be possible that the header is written and some of the data is not written, if the system loses power during hibernation. Mikulas ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2025-11-03 15:53 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 1/2] pm-hibernate: flush disk cache when suspending Mikulas Patocka
2025-11-03 15:53 ` 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
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).