]> git.hungrycats.org Git - linux/commit
btrfs: give the read repair bio an end_io for submit failures
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 22 Oct 2026 06:16:13 +0000 (02:16 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 2 Nov 2026 02:04:06 +0000 (21:04 -0500)
commit0d38395f0feed7d91e4ed835d70e1a5291098e68
treef0b767c76b5458ba0d661b5921230010a6d7cd5b
parent460514b5bfe1d127e7f40fdf356c5f78eb804807
btrfs: give the read repair bio an end_io for submit failures

repair_one_sector() initializes the repair bbio with a NULL end_io.  A
repair bio normally completes through btrfs_check_read_bio(), which hands
it to btrfs_end_repair_bio() and never calls end_io.  But
btrfs_submit_chunk() can fail a bio before it reaches a device: when
btrfs_map_block() fails, when btrfs_split_bio() fails, or when
btrfs_lookup_bio_sums() fails for a data read.  It then ends the bio with
btrfs_bio_end_io(), which calls bbio->end_io.  For a repair bio that is a
jump to address 0 in a btrfs-endio worker.  The original read never
completes, and an unmount hangs on it later:

  BUG: kernel NULL pointer dereference, address: 0000000000000000
  Workqueue: btrfs-endio simple_end_io_work
  RIP: 0010:0x0
  Call Trace:
   btrfs_bio_end_io+0x1b7/0x420
   btrfs_submit_bbio+0xc1e/0x1fa0
   btrfs_check_read_bio+0x80e/0x1760
   simple_end_io_work+0xc8/0x190

The repair bio's checksum lookup can fail where the original read's
lookup succeeded, because the two search different trees.  A buffered
read of an extent from a past transaction searches the commit root
(csum_search_commit_root).  The repair bbio leaves that flag clear and
searches the running transaction's csum tree.  When that transaction
aborts, the cleanup frees its dirty tree blocks.  A later lookup reads
such a block from disk, where it was never written, and fails with -EIO:

  BTRFS error (device dm-6 state EA): bad tree block start, mirror 2 want 31490048 have 14842989077554535085
  BTRFS error (device dm-6 state EA): bad tree block start, mirror 1 want 31490048 have 8810637562337132983

This was first seen right after a relocation forced the filesystem
read-only: six btrfs-endio workers oopsed within 1.5 seconds.  It
reproduces with a raid1 filesystem:
- Commit a file, write more data so that the csum leaf holding the file's
  tail is COWed in the running transaction, and corrupt the tail on both
  mirrors.
- Abort the transaction by failing a log commit's superblock write, and
  drop the page cache.
- A buffered read of the tail now oopses.

Give the repair bbio an end_io for this case.  A failed submission does
not depend on the mirror: the mapping and the checksum lookup fail the
same way for every copy.  So give up on the sector the way an exhausted
repair does: mark the original bio failed, drop the repair's count on
the failed_bio, and free the repair bio.  The read then fails with -EIO.

Fixes: 7609afac6775 ("btrfs: handle checksum validation and repair at the storage layer")
Cc: stable@vger.kernel.org # 6.6+
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/bio.c