[PATCH] f2fs: don't fall back to the older checkpoint on a read error

From: Mani Tofigh via B4 Relay

Date: Wed Nov 11 2026 - 16:54:37 EST


From: Mani Tofigh <mt4022@xxxxxxxxxxxx>

One read error on the newest checkpoint pack at mount rolls f2fs back to
the older checkpoint for good. Everything synced since then is lost,
even if the error was transient.

get_checkpoint_version() returns -EIO when a cp block can't be read, and
validate_checkpoint() treats that like a bad CRC.
f2fs_get_valid_checkpoint() then mounts the other pack, and the next
checkpoint overwrites the pack it couldn't read. E.g., with a dm error
target over the first block of the newest pack for the mount only:

write OLD; sync; write NEW; sync; <power cut>
mount /dev/mapper/err /mnt # mounts the older checkpoint
umount /mnt
mount /dev/ram0 /mnt # NEW is missing

Return -EIO from validate_checkpoint() and fail the mount instead, as we
already do when a payload block of the chosen pack can't be read. We
can't tell which pack is newer without reading it, so a read error on
the older pack fails the mount too. A bad CRC or version mismatch still
falls back to the other pack. With the fix, the mount fails and NEW is
there on the next mount.

This bug was identified and confirmed with the help of a deterministic
hypervisor currently under development. The C reproducer below however
hits it every time.

Fixes: 7735730d39d7 ("f2fs: fix to propagate error from __get_meta_page()")
Cc: stable@xxxxxxxxxx
Signed-off-by: Mani Tofigh <mt4022@xxxxxxxxxxxx>
---
Reproducer: https://github.com/manitofigh/files/blob/main/linux-repros/f2fscpeio.c
---
fs/f2fs/checkpoint.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index a9a2b9d93231..cbedd3e1399f 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1178,6 +1178,8 @@ static struct f2fs_cached_block *validate_checkpoint(struct f2fs_sb_info *sbi,

err = get_checkpoint_version(sbi, cp_addr, &cp_block,
&cp_entry_1, version);
+ if (err == -EIO)
+ return ERR_PTR(err);
if (err)
return NULL;

@@ -1193,6 +1195,10 @@ static struct f2fs_cached_block *validate_checkpoint(struct f2fs_sb_info *sbi,
cp_addr += cp_blocks - 1;
err = get_checkpoint_version(sbi, cp_addr, &cp_block,
&cp_entry_2, version);
+ if (err == -EIO) {
+ f2fs_put_cache(cp_entry_1, true);
+ return ERR_PTR(err);
+ }
if (err)
goto invalid_cp;
cur_version = *version;
@@ -1231,11 +1237,19 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
*/
cp_start_blk_no = le32_to_cpu(fsb->cp_blkaddr);
cp1 = validate_checkpoint(sbi, cp_start_blk_no, &cp1_version);
+ if (IS_ERR(cp1)) {
+ err = PTR_ERR(cp1);
+ goto free_fail_no_cp;
+ }

/* The second checkpoint pack should start at the next segment */
cp_start_blk_no += ((unsigned long long)1) <<
le32_to_cpu(fsb->log_blocks_per_seg);
cp2 = validate_checkpoint(sbi, cp_start_blk_no, &cp2_version);
+ if (IS_ERR(cp2)) {
+ err = PTR_ERR(cp2);
+ goto free_fail_no_cp;
+ }

if (cp1 && cp2) {
if (ver_after(cp2_version, cp1_version))

---
base-commit: 648bdfa9bae3850908df31617e5922e0683d5fff
change-id: 20261111-f2fs-cp-read-error-f39b7c1c64f5

Best regards,
--
Mani Tofigh <mt4022@xxxxxxxxxxxx>