mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/5] btrfs: data integrity fixes
@ 2026-10-30 14:38 Josef Bacik
  2026-10-30 14:38 ` [PATCH 1/5] btrfs: don't drop the error of the last split bio Josef Bacik
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Josef Bacik @ 2026-10-30 14:38 UTC (permalink / raw)
  To: David Sterba, Chris Mason, Naohiro Aota, Johannes Thumshirn,
	Qu Wenruo, Boris Burkov, Filipe Manana
  Cc: linux-btrfs, linux-kernel, stable, Josef Bacik

Hello,

I've been doing some model checking of our trickier paths with Claude's
help, and these are the fixes for the bugs it turned up that actually
lose data, or tell userspace that something is safe when it isn't.
Every one of them was reproduced in a VM on an unpatched kernel and goes
away with the fix, though the fsync and log sync ones needed a delay
injected to hit the window.

The worst one is the fstrim one.  If you run fstrim while a device
replace is running we'll discard everything that has already been copied
to the target device, because the target's alloc_state is empty until
the replace finishes, so the whole device looks unallocated.  The
replace then finishes happily, the source device goes away, and you're
left with zeroes where your metadata used to be.  This has been around
since FITRIM learned to trim unallocated space back in 4.3.

The split bio one is similarly nasty.  If the last piece of a split bio
to complete is one of the split bios and it failed, we drop the error on
the floor, and a buffered read returns success with whatever was sitting
in the page.

The rest are in our error handling.  A delalloc failure in the middle of
a folio leaves blocks dirty that no longer have an ordered extent, a
fast fsync after an error that happened before we submitted the bio can
log extents that were never written (which log replay then happily puts
in place of the data that was there before), and btrfs_sync_log() can
return success for a log transaction that never got committed.

I have a cleanup series for btrfs_sync_log coming, as I had to spend a
lot of time grokking that fix, which is a good indication that the code
is too complicated.

They're all independent of each other and tagged for stable.  This is
against for-next, and it also applies cleanly on top of Qu's
extent-by-extent writeback series.  Thanks,

Josef

---
Josef Bacik (5):
      btrfs: don't drop the error of the last split bio
      btrfs: clear dirty blocks after a delalloc failure
      btrfs: make fsync wait after pre-submission errors
      btrfs: don't report success for a skipped log sync
      btrfs: don't trim the target of a device replace

 fs/btrfs/bio.c          |  9 ++++---
 fs/btrfs/extent-tree.c  |  8 +++++++
 fs/btrfs/extent_io.c    | 10 ++++++++
 fs/btrfs/ordered-data.c | 62 ++++++++++++++++++++++++-------------------------
 fs/btrfs/tree-log.c     | 20 ++++++++++++++--
 5 files changed, 73 insertions(+), 36 deletions(-)
---
base-commit: 2789b2c034d7c0c8687355921a38c5ac41a565fa
change-id: 20261029-b4-btrfs-data-integrity-eb753b57300f


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-10-30 21:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-30 14:38 [PATCH 0/5] btrfs: data integrity fixes Josef Bacik
2026-10-30 14:38 ` [PATCH 1/5] btrfs: don't drop the error of the last split bio Josef Bacik
2026-10-30 21:03   ` Qu Wenruo
2026-10-30 14:38 ` [PATCH 2/5] btrfs: clear dirty blocks after a delalloc failure Josef Bacik
2026-10-30 20:57   ` Qu Wenruo
2026-10-30 14:38 ` [PATCH 3/5] btrfs: make fsync wait after pre-submission errors Josef Bacik
2026-10-30 21:06   ` Qu Wenruo
2026-10-30 14:38 ` [PATCH 4/5] btrfs: don't report success for a skipped log sync Josef Bacik
2026-10-30 14:38 ` [PATCH 5/5] btrfs: don't trim the target of a device replace Josef Bacik
2026-10-30 21:02   ` Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®