]> git.hungrycats.org Git - linux/commitdiff
replace-finish-deadlock: new series, re-export after the rf1109 misc-next promotion
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Tue, 10 Nov 2026 16:47:26 +0000 (11:47 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Tue, 10 Nov 2026 16:47:26 +0000 (11:47 -0500)
misc-next testing d249ec595c9c, zb64 efaeb5436501 (base 83cd81353093;
kdave and btrfs fetched first, no public commit with the base's tree,
so no base-commit line).

- New series topics/replace-finish-deadlock (2 patches, Zygo), the
  dev-replace bio counter deadlocks found by rh1108: "btrfs: do not wait
  for device replace in the bio completion workers" (Fixes: 7609afac6775)
  and "btrfs: do not hold the bio counter across the data csum lookup"
  (Fixes: 1c2b3ee3b0ec).  Cover letter is a DRAFT for Zygo's review
  (no Cc stable, no tool-use note, like the other covers); TESTING.md
  has the misc-next and 6.18 rounds, 7.3 follows after its gate.
- README: series table row and the integration ORDER.
- fixups/post-merge.patch unchanged (the series merges cleanly last).
- The zb64-only "'btrfs replace' hangs at end of replacing a device"
  commit dropped from misc-next zb64 was never exported; no change.
- The other covers changed only in their Date: headers (reverted).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
README.md
topics/replace-finish-deadlock/0000-cover-letter.patch [new file with mode: 0644]
topics/replace-finish-deadlock/0001-btrfs-do-not-wait-for-device-replace-in-the-bio-comp.patch [new file with mode: 0644]
topics/replace-finish-deadlock/0002-btrfs-do-not-hold-the-bio-counter-across-the-data-cs.patch [new file with mode: 0644]
topics/replace-finish-deadlock/TESTING.md [new file with mode: 0644]

index de16b3c8b98d132b34ca71a764b43d899a9d3f1b..076390c77c5d34b4570add7545717bdfe6aa3f27 100644 (file)
--- a/README.md
+++ b/README.md
@@ -132,6 +132,7 @@ series applies on top of; the others apply to the base.
 | `dev-stats` | 1 | | Zygo | behaviour change, offered for rejection |
 | `resize-missing` | 1 | | Qu Wenruo, rewritten by Zygo | Zygo's Signed-off-by to be added before sending |
 | `reflink-inline-fixes` | 2 | | Zygo | |
+| `replace-finish-deadlock` | 2 | | Zygo | two dev-replace deadlocks since v6.3 (Fixes tags); Cc stable is Zygo's call |
 
 ## Applying one series
 
@@ -172,7 +173,7 @@ ORDER="logical-ino-costs balance-resume remap-balance-leak compress-fixes deadlo
        delalloc-fixes dev-extent-defrag prealloc-size raid56-fixes read-repair-fixes
        raid56-scrub-replace reclaim-fixes stripe-alloc low-space
        allocator-hints read-policies replace-fixes dev-stats resize-missing
-       reflink-inline-fixes"
+       reflink-inline-fixes replace-finish-deadlock"
 declare -A ON=([raid56-scrub-replace]=read-repair-fixes
        [stripe-alloc]=reclaim-fixes [low-space]=stripe-alloc)
 
diff --git a/topics/replace-finish-deadlock/0000-cover-letter.patch b/topics/replace-finish-deadlock/0000-cover-letter.patch
new file mode 100644 (file)
index 0000000..46e63b6
--- /dev/null
@@ -0,0 +1,67 @@
+From 850a7c69a81a4b461ebbbf4a97e124d071e1eb54 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Tue, 10 Nov 2026 11:44:18 -0500
+Subject: [PATCH 0/2] btrfs: device replace hangs at the end with the bio counter held
+To: linux-btrfs@vger.kernel.org
+
+A device replace can hang forever after "btrfs replace status" already
+reports it finished.  btrfs_dev_replace_finishing() sets
+BTRFS_FS_STATE_DEV_REPLACING and waits for the dev-replace bio counter to
+drop to zero, and every bio btrfs_submit_chunk() counts holds its
+reference until it completes.  Both patches fix a task that waits for
+replace to finish while replace waits, directly or not, for that task.
+Both deadlocks are in the code since v6.3.
+
+Patch 1: read repair runs in the bio completion workers (btrfs-endio for
+mirrored profiles, btrfs-rmw for RAID56), and it waits there for replace
+to finish when it submits the next repair read or writes the good copy
+back.  Those workers also complete the counted bios replace waits for:
+RAID56 bios and mirrored writes drop their references only when their
+completion work runs.  Once every worker of the pool waits in read
+repair, nothing completes them.  Replacing a missing RAID5 or RAID6
+device while its data is read hits this easily, because every such read
+is repaired by a rebuild and written back to the replace target.  The
+patch moves the parts of read repair that take the bio counter to a new
+workqueue that no bio completion waits for.
+
+Patch 2: btrfs_submit_chunk() holds the bio counter across the data
+checksum lookup of a read.  When the checksum leaf is not cached, its
+read takes the counter again, and if replace finishing has set the flag
+in between, the reader sleeps with its first reference held.  The patch
+drops the counter and the mapping for the lookup and maps the bio again
+afterwards, to the same mirror.  This one does not depend on the RAID
+profile.
+
+Tested on KASAN and non-KASAN kernels with a stress test that replaces
+the missing device of a degraded 4-device array while 8 O_DIRECT readers
+and 2 writers run, and checks that every replace returns, a scrub is
+clean and every file reads back intact:
+- RAID5 data: without the series about half the replaces hang; with
+  thread_pool=64 the pool limit is gone and patch 2's deadlock appears
+  instead (counter 2, two readers sleeping under the checksum lookup).
+  With the series, none of 48 replaces hung, nor 24 with
+  thread_pool=64.
+- RAID6 data with the P strips corrupted, so a rebuild from P fails its
+  checksum and read repair goes on to rebuild from Q: without the series
+  the first replace hangs, all 8 btrfs-rmw workers waiting to submit the
+  repair read.  With the series, none of 48 replaces hung.
+- RAID1 data with one mirror corrupted and a present device replaced
+  (repairs in btrfs-endio): none of 48 hung with the series; this did not
+  hang without it either (0 of 24).
+Each hang was confirmed with drgn, matching the counter against the
+bios held behind the waiting workers.  The device replace, scrub and
+read repair regression tests pass.
+
+Zygo Blaxell (2):
+  btrfs: do not wait for device replace in the bio completion workers
+  btrfs: do not hold the bio counter across the data csum lookup
+
+ fs/btrfs/bio.c     | 117 ++++++++++++++++++++++++++++++++++++++++-----
+ fs/btrfs/disk-io.c |   4 ++
+ fs/btrfs/fs.h      |   2 +
+ 3 files changed, 110 insertions(+), 13 deletions(-)
+
+
+-- 
+2.47.3
+
diff --git a/topics/replace-finish-deadlock/0001-btrfs-do-not-wait-for-device-replace-in-the-bio-comp.patch b/topics/replace-finish-deadlock/0001-btrfs-do-not-wait-for-device-replace-in-the-bio-comp.patch
new file mode 100644 (file)
index 0000000..3992421
--- /dev/null
@@ -0,0 +1,210 @@
+From 0545110141e28b6526e0da88bb59070174e47ae4 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Mon, 9 Nov 2026 23:44:08 -0500
+Subject: [PATCH 1/2] btrfs: do not wait for device replace in the bio
+ completion workers
+To: linux-btrfs@vger.kernel.org
+
+Device replace can hang forever at the end, after "replace status"
+already reports it finished, when data that needs read repair is read
+while it finishes:
+
+  btrfs replace start   btrfs_rm_dev_replace_blocked <- btrfs_dev_replace_finishing
+  btrfs-rmw (all 8)     btrfs_bio_counter_inc_blocked <- btrfs_repair_bbio_failure
+                        <- btrfs_check_read_bio <- btrfs_raid56_end_io
+                        <- rbio_orig_end_io <- recover_rbio
+
+and every other task submitting bios to the filesystem blocks behind
+them.
+
+btrfs_dev_replace_finishing() sets BTRFS_FS_STATE_DEV_REPLACING and
+waits for the bio counter to drop to zero.  Every bio that
+btrfs_submit_chunk() counted keeps its reference until its completion
+runs: a RAID56 bio until btrfs_raid56_end_io() runs in the btrfs-rmw
+worker that completes its rbio, a mirrored write until
+orig_write_end_io_work() runs in btrfs-endio.  Both workqueues run at
+most thread_pool workers at a time.
+
+Read repair runs in those same workers: btrfs_check_read_bio() is called
+by simple_end_io_work() in btrfs-endio and by btrfs_raid56_end_io() in
+btrfs-rmw.  It takes the bio counter when it submits a repair read to
+the next mirror (repair_one_sector() and btrfs_end_repair_bio(), through
+btrfs_submit_chunk()), and when it writes the good copy back
+(btrfs_repair_bbio_failure()).  While replace finishing has the flag
+set, both wait for replace to finish.  Once every worker of the pool
+waits there, the counted bios queued behind them never complete, and
+replace never finishes.
+
+This is easy to hit when a missing device is replaced while its data is
+read: each such read fails, is repaired by a rebuild read through
+btrfs-rmw, and writes the rebuilt block back to the replace target.  On
+a 4-device RAID5 with one device missing, 8 O_DIRECT readers and 2
+writers, it hangs in about half the replaces.  At one hang the counter
+was 15: 2 rebuild rbios queued on btrfs-rmw behind the 8 workers waiting
+in the write-back, and 13 rebuild rbios waiting for the stripe locks
+those 2 hold, one bio each.  On RAID6, a repair read that rebuilds a
+sector from P and fails its csum goes on to rebuild from Q, and that
+submission waits the same way: with the P strips corrupted, the same
+test hung in the first replace, with all 8 btrfs-rmw workers in
+btrfs_end_repair_bio() -> btrfs_submit_bbio() and a counter of 68 = 23
+rebuild rbios queued on btrfs-rmw + 45 waiting for their stripe locks.
+
+Run the parts of read repair that take the bio counter in a new
+workqueue, btrfs-repair, that no bio completion waits for.  A worker
+that waits there for replace to finish holds nothing replace waits for:
+the repair bbio is not submitted yet, and the read being repaired is
+held back by fbio->repair_count, which is not counted.
+
+As before, the read being repaired completes once the write-back is
+done; while replace finishes, that is once replace has finished.
+
+Fixes: 7609afac67754 ("btrfs: handle checksum validation and repair at the storage layer")
+---
+ fs/btrfs/bio.c     | 68 ++++++++++++++++++++++++++++++++++++++--------
+ fs/btrfs/disk-io.c |  4 +++
+ fs/btrfs/fs.h      |  2 ++
+ 3 files changed, 62 insertions(+), 12 deletions(-)
+
+diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
+index 2c6234f6182f8..2952022c73776 100644
+--- a/fs/btrfs/bio.c
++++ b/fs/btrfs/bio.c
+@@ -164,6 +164,55 @@ static void btrfs_repair_done(struct btrfs_failed_bio *fbio)
+       }
+ }
+ 
++/*
++ * Read repair runs in bio completion context: btrfs_check_read_bio() is called
++ * by the btrfs-endio workers and, for RAID56, by the btrfs-rmw worker that
++ * completes the rbio.  The repair read and the write-back of the good copy both
++ * take the bio counter, which waits while device replace is finishing, and
++ * replace finishing waits for every counted bio to complete.  Counted bios
++ * complete in those same workers too (RAID56 bios in btrfs-rmw, mirrored writes
++ * in btrfs-endio), and both pools have only thread_pool workers: once all of a
++ * pool's workers wait for replace, the counted bios queued behind them never
++ * complete and replace never finishes.
++ *
++ * So the parts of read repair that take the bio counter run in
++ * fs_info->repair_workers, which no bio completion waits for.  A repair bbio
++ * is not in flight while it is queued there, so its end_io_work is free.
++ */
++static void btrfs_repair_read_work(struct work_struct *work)
++{
++      struct btrfs_bio *repair_bbio = container_of(work, struct btrfs_bio, end_io_work);
++
++      btrfs_submit_bbio(repair_bbio, repair_bbio->mirror_num);
++}
++
++static void btrfs_queue_repair_read(struct btrfs_bio *repair_bbio, int mirror)
++{
++      struct btrfs_fs_info *fs_info = repair_bbio->inode->root->fs_info;
++
++      repair_bbio->mirror_num = mirror;
++      INIT_WORK(&repair_bbio->end_io_work, btrfs_repair_read_work);
++      queue_work(fs_info->repair_workers, &repair_bbio->end_io_work);
++}
++
++/* Write the good copy in @repair_bbio back to the mirrors that failed before it. */
++static void btrfs_repair_write_work(struct work_struct *work)
++{
++      struct btrfs_bio *repair_bbio = container_of(work, struct btrfs_bio, end_io_work);
++      struct btrfs_failed_bio *fbio = repair_bbio->private;
++      struct btrfs_fs_info *fs_info = repair_bbio->inode->root->fs_info;
++      int mirror = repair_bbio->mirror_num;
++
++      do {
++              mirror = prev_repair_mirror(fbio, mirror);
++              btrfs_repair_bbio_failure(repair_bbio, &repair_bbio->saved_iter,
++                                        fs_info->sectorsize, mirror);
++      } while (mirror != fbio->bbio->mirror_num);
++
++      btrfs_repair_done(fbio);
++      bio_put(&repair_bbio->bio);
++}
++
+ static void btrfs_end_repair_bio(struct btrfs_bio *repair_bbio,
+                                struct btrfs_device *dev)
+ {
+@@ -184,22 +233,17 @@ static void btrfs_end_repair_bio(struct btrfs_bio *repair_bbio,
+               if (mirror == fbio->bbio->mirror_num) {
+                       btrfs_debug(fs_info, "no mirror left");
+                       fbio->bbio->bio.bi_status = BLK_STS_IOERR;
+-                      goto done;
++                      btrfs_repair_done(fbio);
++                      bio_put(&repair_bbio->bio);
++                      return;
+               }
+ 
+-              btrfs_submit_bbio(repair_bbio, mirror);
++              btrfs_queue_repair_read(repair_bbio, mirror);
+               return;
+       }
+ 
+-      do {
+-              mirror = prev_repair_mirror(fbio, mirror);
+-              btrfs_repair_bbio_failure(repair_bbio, &repair_bbio->saved_iter,
+-                                        fs_info->sectorsize, mirror);
+-      } while (mirror != fbio->bbio->mirror_num);
+-
+-done:
+-      btrfs_repair_done(fbio);
+-      bio_put(&repair_bbio->bio);
++      INIT_WORK(&repair_bbio->end_io_work, btrfs_repair_write_work);
++      queue_work(fs_info->repair_workers, &repair_bbio->end_io_work);
+ }
+ 
+ /*
+@@ -268,7 +312,7 @@ static struct btrfs_failed_bio *repair_one_sector(struct btrfs_bio *failed_bbio,
+ 
+       mirror = next_repair_mirror(fbio, failed_bbio->mirror_num);
+       btrfs_debug(fs_info, "submitting repair read to mirror %d", mirror);
+-      btrfs_submit_bbio(repair_bbio, mirror);
++      btrfs_queue_repair_read(repair_bbio, mirror);
+       return fbio;
+ }
+ 
+diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
+index 6afcd6ca2a8a8..59bd23092812c 100644
+--- a/fs/btrfs/disk-io.c
++++ b/fs/btrfs/disk-io.c
+@@ -1779,6 +1779,8 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
+               destroy_workqueue(fs_info->endio_workers);
+       if (fs_info->rmw_workers)
+               destroy_workqueue(fs_info->rmw_workers);
++      if (fs_info->repair_workers)
++              destroy_workqueue(fs_info->repair_workers);
+       btrfs_destroy_workqueue(fs_info->endio_write_workers);
+       btrfs_destroy_workqueue(fs_info->delayed_workers);
+       btrfs_destroy_workqueue(fs_info->caching_workers);
+@@ -2007,6 +2009,7 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info)
+       fs_info->endio_meta_workers =
+               alloc_workqueue("btrfs-endio-meta", flags, max_active);
+       fs_info->rmw_workers = alloc_workqueue("btrfs-rmw", flags, max_active);
++      fs_info->repair_workers = alloc_workqueue("btrfs-repair", flags, max_active);
+       fs_info->endio_write_workers =
+               btrfs_alloc_workqueue(fs_info, "endio-write", flags,
+                                     max_active, 2);
+@@ -2023,6 +2026,7 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info)
+             fs_info->delalloc_workers && fs_info->flush_workers &&
+             fs_info->endio_workers && fs_info->endio_meta_workers &&
+             fs_info->endio_write_workers && fs_info->rmw_workers &&
++            fs_info->repair_workers &&
+             fs_info->caching_workers && fs_info->fixup_workers &&
+             fs_info->delayed_workers && fs_info->qgroup_rescan_workers &&
+             fs_info->discard_ctl.discard_workers)) {
+diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h
+index 2dd167c32d612..d728e19464866 100644
+--- a/fs/btrfs/fs.h
++++ b/fs/btrfs/fs.h
+@@ -710,6 +710,8 @@ struct btrfs_fs_info {
+       struct workqueue_struct *endio_workers;
+       struct workqueue_struct *endio_meta_workers;
+       struct workqueue_struct *rmw_workers;
++      /* Read repair I/O, which must not wait in the bio completion workers. */
++      struct workqueue_struct *repair_workers;
+       struct btrfs_workqueue *endio_write_workers;
+       struct btrfs_workqueue *caching_workers;
+ 
+-- 
+2.47.3
+
diff --git a/topics/replace-finish-deadlock/0002-btrfs-do-not-hold-the-bio-counter-across-the-data-cs.patch b/topics/replace-finish-deadlock/0002-btrfs-do-not-hold-the-bio-counter-across-the-data-cs.patch
new file mode 100644 (file)
index 0000000..0989c1c
--- /dev/null
@@ -0,0 +1,113 @@
+From 850a7c69a81a4b461ebbbf4a97e124d071e1eb54 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Sun, 8 Nov 2026 20:40:09 -0500
+Subject: [PATCH 2/2] btrfs: do not hold the bio counter across the data csum
+ lookup
+To: linux-btrfs@vger.kernel.org
+
+Device replace can hang forever at the end, after "replace status"
+already reports it finished, when data is read while it finishes:
+
+  btrfs replace start   btrfs_rm_dev_replace_blocked <- btrfs_dev_replace_finishing
+  reader                btrfs_bio_counter_inc_blocked <- btrfs_submit_bbio
+                        <- read_extent_buffer_pages <- read_block_for_search
+                        <- btrfs_search_slot <- btrfs_lookup_csum
+                        <- btrfs_lookup_bio_sums <- btrfs_submit_bbio
+                        <- btrfs_dio_submit_io
+
+btrfs_submit_chunk() takes the bio counter before mapping the bio, and
+for a data read it then looks up the data checksums.  When the csum tree
+leaf is not cached, the lookup reads it, and that read goes through
+btrfs_submit_chunk() and btrfs_bio_counter_inc_blocked() again.  If
+btrfs_dev_replace_finishing() has set BTRFS_FS_STATE_DEV_REPLACING in
+between, the reader sleeps on the second reference while it holds the
+first, and replace finishing waits for the first to be dropped.  Every
+other bio submission then blocks behind them.
+
+On a 4-device RAID5 with one device missing, mounted with thread_pool=64,
+8 O_DIRECT readers and 2 writers, replacing the missing device hung in
+round 7.  The counter was 2, and exactly two readers were sleeping in
+the nested btrfs_bio_counter_inc_blocked() under btrfs_lookup_bio_sums().
+This does not depend on the RAID profile.
+
+The counter only keeps the result of btrfs_map_block() valid until the
+bio is submitted.  So drop it, and the mapping, for the csum lookup, take
+it again afterwards and map the bio again.  That costs one more
+btrfs_map_block() call per data read bio.  The mirror picked by the first
+mapping is passed back in, so the bio is mapped to the same copy.
+
+Fixes: 1c2b3ee3b0ec4 ("btrfs: pre-load data checksum for reads in btrfs_submit_bio")
+---
+ fs/btrfs/bio.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
+ 1 file changed, 48 insertions(+), 1 deletion(-)
+
+diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
+index 2952022c73776..bffc9a21cc6b6 100644
+--- a/fs/btrfs/bio.c
++++ b/fs/btrfs/bio.c
+@@ -759,6 +759,53 @@ static u64 btrfs_append_map_length(struct btrfs_bio *bbio, u64 map_length)
+       return map_length;
+ }
+ 
++/*
++ * Look up the data checksums of a read without holding the bio counter, then
++ * map the bio again.
++ *
++ * The lookup can read csum tree blocks, and those reads go through
++ * btrfs_submit_chunk() and btrfs_bio_counter_inc_blocked() again.  If device
++ * replace starts finishing in between, it waits for our counter reference to
++ * be dropped while we wait for it to finish, and every new bio blocks behind
++ * it.  The counter only protects the mapping, so drop both for the lookup.
++ *
++ * Called and returns with the bio counter held.
++ */
++static int btrfs_lookup_sums_and_remap(struct btrfs_bio *bbio,
++                                     struct btrfs_io_context **bioc,
++                                     struct btrfs_io_stripe *smap, int *mirror_num)
++{
++      struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info;
++      struct bio *bio = &bbio->bio;
++      const u64 logical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
++      const u64 length = bio->bi_iter.bi_size;
++      u64 map_length = length;
++      int ret;
++
++      btrfs_put_bioc(*bioc);
++      *bioc = NULL;
++      btrfs_bio_counter_dec(fs_info);
++
++      ret = btrfs_lookup_bio_sums(bbio);
++
++      btrfs_bio_counter_inc_blocked(fs_info);
++      if (ret)
++              return ret;
++
++      /* @mirror_num is the mirror the first mapping picked, so this maps the same copy. */
++      ret = btrfs_map_block(fs_info, btrfs_op(bio), logical, &map_length, bioc,
++                            smap, mirror_num);
++      if (ret)
++              return ret;
++      /* The chunk can not change under a read of it. */
++      if (WARN_ON_ONCE(map_length < length)) {
++              btrfs_put_bioc(*bioc);
++              *bioc = NULL;
++              return -EUCLEAN;
++      }
++      return 0;
++}
++
+ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
+ {
+       struct btrfs_inode *inode = bbio->inode;
+@@ -819,7 +866,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
+        */
+       if (bio_op(bio) == REQ_OP_READ && is_data_inode(bbio->inode)) {
+               bbio->saved_iter = bio->bi_iter;
+-              ret = btrfs_lookup_bio_sums(bbio);
++              ret = btrfs_lookup_sums_and_remap(bbio, &bioc, &smap, &mirror_num);
+               status = errno_to_blk_status(ret);
+               if (status)
+                       goto fail;
+-- 
+2.47.3
+
diff --git a/topics/replace-finish-deadlock/TESTING.md b/topics/replace-finish-deadlock/TESTING.md
new file mode 100644 (file)
index 0000000..2b3ba7b
--- /dev/null
@@ -0,0 +1,109 @@
+# Testing: replace-finish-deadlock
+
+Two patches for device replace hanging forever at the end, after "replace
+status" already reports it finished.  `btrfs_dev_replace_finishing()` sets
+`BTRFS_FS_STATE_DEV_REPLACING` and waits for `dev_replace.bio_counter` to
+reach 0, and every bio counted by `btrfs_submit_chunk()` keeps its reference
+until its completion runs.
+
+- Patch 1 "btrfs: do not wait for device replace in the bio completion
+  workers" (M1, Fixes 7609afac67754, v6.3): read repair runs in btrfs-endio /
+  btrfs-rmw completion work and sleeps in `btrfs_bio_counter_inc_blocked()`
+  when it submits the next repair read or writes the good copy back.  When
+  every worker of the pool sleeps there, the counted RAID56 bios (and
+  mirrored writes) queued behind them never complete.  The patch moves the
+  counter-taking parts of read repair to a new workqueue, btrfs-repair.
+- Patch 2 "btrfs: do not hold the bio counter across the data csum lookup"
+  (M2, Fixes 1c2b3ee3b0ec4, v6.3): `btrfs_submit_chunk()` holds the counter
+  across `btrfs_lookup_bio_sums()`, whose csum leaf read takes it again.  The
+  patch drops the counter and mapping for the lookup and maps again
+  afterwards, to the same mirror.
+
+To verify: replacing a missing device of a degraded RAID5 / RAID6 array
+under read load (every read of the missing device is repaired by a rebuild
+and written back to the target) must not hang; RAID6 repair that has to go
+on to the Q rebuild (P corrupt) must not hang; mirrored-profile repair keeps
+working; ordinary read repair, scrub and replace behave as before.
+
+Found by rh1108 (2026-11-08; forensics `raid56-wh-harness/forensics/rh1108/`),
+which proved both cycles with drgn on live hangs by accounting for the whole
+counter.  The RAID6 third-copy case (a repair read resubmitted to mirror 3
+from completion context) was the gap left by rh1108's first fix
+(tryinc/nowait, which only skipped the write-back); rf1109 reproduced it and
+replaced that fix with the btrfs-repair workqueue (patch 1 as it is now).
+
+Promoted 2026-11-10 (rf1109): misc-next topic 850a7c69a81a (testing
+d249ec595c9c, zb64 efaeb5436501; the same promotion dropped zb64's
+"'btrfs replace' hangs at end of replacing a device (v5.10.82)" commit,
+which only turned the replace_wait wake-up into a barrier one and is
+superseded); 6.18 topic 011ce9c6fc1a on read-repair-fixes (testing
+27ece222af65, zb64 f3ecfc5af7f8); 7.3 topic 0b22c35e0e7b (testing and results: added after the 7.3 gate).
+
+Tested kernels: candidates refs/cand/rf1109/<lane>/zb64 (before lr1109b
+moved the lanes; topic commits identical) and the re-merged
+refs/cand/rf1109/<lane>/zb64-2 that were promoted.  KASAN kernels add
+FAULT_INJECTION/FAIL_FUNCTION for the inject arm.  Rigs ahive and bhive.
+Forensics: `raid56-wh-harness/forensics/rf1109/`; scripts
+`vm-scripts/rf1109/` (rbio-replace-stress.sh, stress-arms.sh, gate-rf.sh).
+
+### Stress: replace of a missing device under read load
+
+rbio-replace-stress.sh, 12 replaces per arm (delays -1 0 0 1 2 3 4 6 8 s
+before the replace starts), 4 devices, 8 O_DIRECT readers + 2 writers;
+a round fails on a replace that does not return, a scrub that is not
+clean, a file that does not read back, taint or lost lockdep.  Arms: r5
+(RAID5 data, devid 3 missing); r5tp64 (same, thread_pool=64: exposes
+patch 2); r6p (RAID6 data, raid1c3 metadata, P strips corrupted so the
+repair goes on to the Q rebuild = mirror 3; 4 GiB devices); r1 (RAID1 x4,
+data mirror 2 corrupted, present devid 3 replaced: repair in btrfs-endio).
+
+| kernel | r5 | r5tp64 | r6p | r1 |
+|---|---|---|---|---|
+| rh1108 first fix (7.3.0+ #40, tryinc/nowait) | | | HANG in round 1 (drgn: counter 68 = 23 queued + 45 plugged behind 8 btrfs-rmw workers) | 0/24 hangs (rh1108) |
+| misc-next KASAN+FI #11 (ebde7615596e) | 12/12 | 12/12 | 12/12 | 12/12 |
+| misc-next non-KASAN #10 (ebde7615596e) | 12/12 | | 12/12 | 12/12 |
+| misc-next zb64-2 non-KASAN #329 (efaeb5436501, boot smoke) | 4/4 | | 4/4 | 4/4 |
+| 6.18 KASAN #324 (02c8a58382aa) | 12/12 | | 12/12 | 12/12 |
+| 6.18 non-KASAN #325 (02c8a58382aa) | 12/12 | 12/12 | 12/12 | 12/12 |
+
+Without the series (rh1108, misc-next): r5 hangs in about half the
+replaces; r5tp64 hangs in patch 2's cycle (counter 2, two readers asleep
+under the csum lookup).  RAID6 with 2 GiB devices fails at replace start
+with ENOSPC ("failed setting block group ro: -28": test setup, not data
+loss), hence 4 GiB.  A bpftrace detector on 6.18 KASAN (2 r6p rounds)
+counted 28084 repair reads queued to mirror 2 and 28084 to mirror 3 via
+btrfs_repair_read_work and 28084 write-backs via btrfs_repair_write_work:
+the Q path runs on btrfs-repair.
+
+### Regression gate (gate-rf.sh, KASAN+FI kernels)
+
+replace-fixes, raid56-scrub-replace and read-repair-fixes TESTING.md
+tests, alloc-hints-replace, rb1028 replace arms.  All steps: taint 0,
+debug_locks 1, 0 KASAN/lockdep/WARN signatures except the fail_function
+"FAULT_INJECTION: forcing a failure" stack dumps of the inject arm;
+unwritten-on-end lines 0.
+
+| step | misc-next #11 | 6.18 #326 (f3ecfc5af7f8) |
+|---|---|---|
+| rb1028 (replace-uncorrectable, scrub-uncorrectable-rc, failing-member-scrub) | PASS (VERDICT ok) | PASS (VERDICT ok) |
+| read-repair-submit-fail: repair x2 | PASS, PASS | PASS, INVALID (no read hit the bad mirror); rerun PASS, PASS |
+| read-repair-submit-fail: abortgood | PASS | PASS |
+| read-repair-submit-fail: scrubabort | INVALID (by design since replace-fixes p10: scrub stops at the fs error) | INVALID (same) |
+| read-repair-submit-fail: shutdown | PASS | (no shutdown ioctl on 6.18) |
+| read-repair-submit-fail: inject x3 | first run INVALID (harness: the repair stack is now btrfs_repair_read_work; fixed c9345315); rerun PASS x3 (EIO in ~1 s) | first run INVALID (same, + /dev/loopN naming); rerun PASS x3 (EIO in ~5 s) |
+| corrupt-recovery | PASS | PASS |
+| replace-status | PASS (= replace-fixes TESTING.md expectations) | same |
+| replace-cancel-persist | PASS (CANCELED/CANCELED/FINISHED, remounts ok) | same |
+| scrub-repair-werr | PASS | PASS |
+| scrub-fserror-stop | replace PASS, scrub INVALID ended_at_abort (known) | same |
+| replace-resume-gap | 3/3 PASS | 3/3 PASS |
+| alloc-hints-replace | PASS | PASS |
+| replace-discard (11 cases incl. dsync-raid1) | 11/11 PASS | 11/11 PASS |
+| unwritten-readback | PASS | FAIL: known retry-artifact class (arm C, 9 stripes; parity, scrub and degraded reads ok) |
+| replace-abort | 10/10 PASS | 10/10 PASS |
+| r5two (sa1 abortflag) | done, M0..M3 as predicted | same |
+
+No FAIL is ENOSPC or loss of acked data except the r6p 2 GiB setup
+ENOSPC above; the 6.18 unwritten-readback FAIL is the known harness
+retry artifact (no data lost: every reported block reads back through
+parity, scrub clean).