Skip to contentSkip to conversation

block: don't use submit_bio_noacct_nocheck in blk_zone_wplug_bio_work

PATCH Applied Christoph Hellwig 5 participants 13 messages Jun 11, 2025 – Jun 25, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: don't use submit_bio_noacct_nocheck in blk_zone_wplug_bio_work

Bios queued up in the zone write plug have already gone through all all preparation in the submit_bio path, including the freeze protection.

Submitting them through submit_bio_noacct_nocheck duplicates the work and can can cause deadlocks when freezing a queue with pending bio write plugs.

Go straight to ->submit_bio or blk_mq_submit_bio to bypass the superfluous extra freeze protection and checks.

Fixes 9b1ce7f0c6f8 ("block: Implement zone append emulation")
---
 block/blk-zoned.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
block/blk-zoned.c +5 -2
index 8f15d1aa6eb8..45c91016cef3 100644
@@ -1306,7 +1306,6 @@ static void blk_zone_wplug_bio_work(struct work_struct *work)
 	spin_unlock_irqrestore(&zwplug->lock, flags);
 
 	bdev = bio->bi_bdev;
-	submit_bio_noacct_nocheck(bio);
 
 	/*
 	 * blk-mq devices will reuse the extra reference on the request queue
@@ -1314,8 +1313,12 @@ static void blk_zone_wplug_bio_work(struct work_struct *work)
 	 * path for BIO-based devices will not do that. So drop this extra
 	 * reference here.
 	 */
-	if (bdev_test_flag(bdev, BD_HAS_SUBMIT_BIO))
+	if (bdev_test_flag(bdev, BD_HAS_SUBMIT_BIO)) {
+		bdev->bd_disk->fops->submit_bio(bio);
 		blk_queue_exit(bdev->bd_disk->queue);
+	} else {
+		blk_mq_submit_bio(bio);
+	}
 
 put_zwplug:
 	/* Drop the reference we took in disk_zone_wplug_schedule_bio_work(). */
Signature · 1 line
2.47.2
maintainer Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 7 lines · Christoph Hellwig

Bios queued up in the zone write plug have already gone through all all preparation in the submit_bio path, including the freeze protection.

Submitting them through submit_bio_noacct_nocheck duplicates the work and can can cause deadlocks when freezing a queue with pending bio write plugs.

Quoted 6 lines

Go straight to ->submit_bio or blk_mq_submit_bio to bypass the superfluous extra freeze protection and checks.

Fixes 9b1ce7f0c6f8 ("block: Implement zone append emulation")
Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer Applied
#3 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

Bios queued up in the zone write plug have already gone through all all preparation in the submit_bio path, including the freeze protection.

Submitting them through submit_bio_noacct_nocheck duplicates the work and can can cause deadlocks when freezing a queue with pending bio write plugs.

[...]

Applied, thanks!

[1/1] block: don't use submit_bio_noacct_nocheck in blk_zone_wplug_bio_work

      commit: cf625013d8741c01407bbb4a60c111b61b9fa69d

Best regards,

Signature · 1 line
Jens Axboe
Reviewed-by on v1 1/1
#4 lore raw
In reply to Christoph Hellwig
Quoted 9 lines · Christoph Hellwig

Bios queued up in the zone write plug have already gone through all all preparation in the submit_bio path, including the freeze protection.

Submitting them through submit_bio_noacct_nocheck duplicates the work and can can cause deadlocks when freezing a queue with pending bio write plugs.

Go straight to ->submit_bio or blk_mq_submit_bio to bypass the superfluous extra freeze protection and checks.

Although this patch has already been applied:

#5 lore raw
In reply to Christoph Hellwig
Quoted 16 lines · Christoph Hellwig
block/blk-zoned.c +0 -1
index 8f15d1aa6eb8..45c91016cef3 100644
@@ -1306,7 +1306,6 @@ static void blk_zone_wplug_bio_work(struct work_struct *work)
  	spin_unlock_irqrestore(&zwplug->lock, flags);
 
  	bdev = bio->bi_bdev;
-	submit_bio_noacct_nocheck(bio);
 
  	/*
  	 * blk-mq devices will reuse the extra reference on the request queue
@@ -1314,8 +1313,12 @@ static void blk_zone_wplug_bio_work(struct work_struct *work)
  	 * path for BIO-based devices will not do that. So drop this extra
  	 * reference here.
  	 */

block/blk-zoned.c static void blk_zone_wplug_bio_work(struct work_struct *work) · line 1324

Quoted 10 lines
block/blk-zoned.c +5 -1
-	if (bdev_test_flag(bdev, BD_HAS_SUBMIT_BIO))
+	if (bdev_test_flag(bdev, BD_HAS_SUBMIT_BIO)) {
+		bdev->bd_disk->fops->submit_bio(bio);
  		blk_queue_exit(bdev->bd_disk->queue);
+	} else {
+		blk_mq_submit_bio(bio);
+	}
 
  put_zwplug:
  	/* Drop the reference we took in disk_zone_wplug_schedule_bio_work(). */

This patch is necessary but not sufficient. With this patch applied, if I run the deadlock reproducer (tests/zbd/013) with Jens' for-next branch, the deadlock shown below is reported. The first call stack shows the familiar queue_ra_store() invocation. The second call stack is new and shows a dm_split_and_process_bio() invocation.

sysrq: Show Blocked State
task:check state:D stack:27208 pid:2728 tgid:2728 ppid:2697
task_flags:0x480040 flags:0x00004002

Call Trace:
 __schedule+0x8be/0x1c10
 schedule+0xdd/0x270
 blk_mq_freeze_queue_wait+0xfd/0x140
 blk_mq_freeze_queue_nomemsave+0x1e/0x30
 queue_ra_store+0x155/0x2a0
 queue_attr_store+0x24d/0x2d0
 sysfs_kf_write+0xdc/0x120
 kernfs_fop_write_iter+0x39f/0x5a0
 vfs_write+0x4fa/0x1300
 ksys_write+0x109/0x1f0
 __x64_sys_write+0x76/0xb0
 x64_sys_call+0x276/0x17d0
 do_syscall_64+0x94/0x3a0
 entry_SYSCALL_64_after_hwframe+0x4b/0x53
task:kworker/52:2H   state:D stack:26528 pid:2873  tgid:2873  ppid:2 
 task_flags:0x4208060 flags:0x00004000
Workqueue: dm-0_zwplugs blk_zone_wplug_bio_work
Call Trace:
 __schedule+0x8be/0x1c10
 schedule+0xdd/0x270
 __bio_queue_enter+0x32d/0x7c0
 __submit_bio+0x1dd/0x6c0
 __submit_bio_noacct+0x147/0x580
 submit_bio_noacct_nocheck+0x4de/0x620
 submit_bio_noacct+0x8f4/0x1a50
 dm_split_and_process_bio+0x8a1/0x1c00 [dm_mod 
14a6a78a54cd51bfc1d6559d48b0c80b677774ec]
 dm_submit_bio+0x137/0x490 [dm_mod 
14a6a78a54cd51bfc1d6559d48b0c80b677774ec]
 blk_zone_wplug_bio_work+0x455/0x630
 process_one_work+0xe29/0x1420
 worker_thread+0x5ed/0xff0
 kthread+0x3cd/0x840
 ret_from_fork+0x412/0x520
 ret_from_fork_asm+0x11/0x20

Bart.

maintainer
#6 lore raw
Quoted 25 lines · Bart Van Assche
Quoted 24 lines · Christoph Hellwig
block/blk-zoned.c +5 -2
index 8f15d1aa6eb8..45c91016cef3 100644
@@ -1306,7 +1306,6 @@ static void blk_zone_wplug_bio_work(struct work_struct *work)
  	spin_unlock_irqrestore(&zwplug->lock, flags);
 
  	bdev = bio->bi_bdev;
-	submit_bio_noacct_nocheck(bio);
 
  	/*
  	 * blk-mq devices will reuse the extra reference on the request queue
@@ -1314,8 +1313,12 @@ static void blk_zone_wplug_bio_work(struct work_struct *work)
  	 * path for BIO-based devices will not do that. So drop this extra
  	 * reference here.
  	 */
-	if (bdev_test_flag(bdev, BD_HAS_SUBMIT_BIO))
+	if (bdev_test_flag(bdev, BD_HAS_SUBMIT_BIO)) {
+		bdev->bd_disk->fops->submit_bio(bio);
  		blk_queue_exit(bdev->bd_disk->queue);
+	} else {
+		blk_mq_submit_bio(bio);
+	}
 
Quoted 8 lines

block/blk-zoned.c static void blk_zone_wplug_bio_work(struct work_struct *work) · line 1324

Quoted 2 lines
block/blk-zoned.c +0 -0
  put_zwplug:
  	/* Drop the reference we took in disk_zone_wplug_schedule_bio_work(). */

This patch is necessary but not sufficient. With this patch applied, if I run the deadlock reproducer (tests/zbd/013) with Jens' for-next branch, the deadlock shown below is reported. The first call stack shows the familiar queue_ra_store() invocation. The second call stack is new and shows a dm_split_and_process_bio() invocation.

That function may call bio_split_to_limits() which trigger the call chain

__bio_split_to_limits() -> bio_split_xxx() -> bio_submit_split() -> submit_bio_noacct() -> submit_bio_noacct_nocheck()

And we then should endup doing:

	if (current->bio_list)
		bio_list_add(&current->bio_list[0], bio);

Since this is a split from within the original submitter context... Well, I think we should be. If we endup calling again __submit_bio_noacct() directly here, we would be reentering the submission path, at the risk of a stack overflow, which is what the current->bio_list tries to avoid.
So I am confused why you endup seeing this issue... Can you check exactly the path that is being followed ? (your backtrace does not seem to have everything)

Depending on the BIO, dm_split_and_process_bio may also trigger the path:

__split_and_process_bio() -> __map_bio() -> dm_submit_bio_remap() -> submit_bio_noacct()

But that should be for submission of cloned BIOs to the block device used as the backing dev of the DM device. So that should not cause an issue since that is a different bdev. Or is this maybe confusing lockdep ?

Quoted 43 lines

sysrq: Show Blocked State
task:check state:D stack:27208 pid:2728 tgid:2728 ppid:2697
task_flags:0x480040 flags:0x00004002

Call Trace:
  __schedule+0x8be/0x1c10
  schedule+0xdd/0x270
  blk_mq_freeze_queue_wait+0xfd/0x140
  blk_mq_freeze_queue_nomemsave+0x1e/0x30
  queue_ra_store+0x155/0x2a0
  queue_attr_store+0x24d/0x2d0
  sysfs_kf_write+0xdc/0x120
  kernfs_fop_write_iter+0x39f/0x5a0
  vfs_write+0x4fa/0x1300
  ksys_write+0x109/0x1f0
  __x64_sys_write+0x76/0xb0
  x64_sys_call+0x276/0x17d0
  do_syscall_64+0x94/0x3a0
  entry_SYSCALL_64_after_hwframe+0x4b/0x53
task:kworker/52:2H   state:D stack:26528 pid:2873  tgid:2873  ppid:2 
  task_flags:0x4208060 flags:0x00004000
Workqueue: dm-0_zwplugs blk_zone_wplug_bio_work
Call Trace:
  __schedule+0x8be/0x1c10
  schedule+0xdd/0x270
  __bio_queue_enter+0x32d/0x7c0
  __submit_bio+0x1dd/0x6c0
  __submit_bio_noacct+0x147/0x580
  submit_bio_noacct_nocheck+0x4de/0x620
  submit_bio_noacct+0x8f4/0x1a50
  dm_split_and_process_bio+0x8a1/0x1c00 [dm_mod 
14a6a78a54cd51bfc1d6559d48b0c80b677774ec]
  dm_submit_bio+0x137/0x490 [dm_mod 
14a6a78a54cd51bfc1d6559d48b0c80b677774ec]
  blk_zone_wplug_bio_work+0x455/0x630
  process_one_work+0xe29/0x1420
  worker_thread+0x5ed/0xff0
  kthread+0x3cd/0x840
  ret_from_fork+0x412/0x520
  ret_from_fork_asm+0x11/0x20

Bart.

Signature · 2 lines
Damien Le Moal
Western Digital Research
#7 lore raw
Quoted 2 lines · Damien Le Moal

Can you check exactly the path that is being followed ? (your backtrace does not seem to have everything)

Hmm ... it is not clear to me why this information is required? My understanding is that the root cause is the same as for the deadlock fixed by Christoph:
1. A bio is queued onto zwplug->bio_list. Before this happens, the
queue reference count is increased by one.
2. A value is written into a block device sysfs attribute and queue
freezing starts. The queue freezing code waits for completion of
all bios on zwplug->bio_list because the reference count owned by
these bios is only released when these bios complete.
3. blk_zone_wplug_bio_work() dequeues a bio from zwplug->bio_list,
calls dm_submit_bio() through a function pointer, dm_submit_bio()
calls submit_bio_noacct() indirectly and submit_bio_noacct() calls
bio_queue_enter() indirectly. bio_queue_enter() sees that queue
freezing has started and waits until the queue is unfrozen.
4. A deadlock occurs because (2) and (3) wait for each other
indefinitely.

Thanks,

Bart.

maintainer
#8 lore raw
Quoted 5 lines · Bart Van Assche
Quoted 2 lines · Damien Le Moal

Can you check exactly the path that is being followed ? (your backtrace does not seem to have everything)

Quoted 16 lines

Hmm ... it is not clear to me why this information is required? My understanding is that the root cause is the same as for the deadlock fixed by Christoph:
1. A bio is queued onto zwplug->bio_list. Before this happens, the queue reference count is increased by one.
2. A value is written into a block device sysfs attribute and queue freezing starts. The queue freezing code waits for completion of all bios on zwplug->bio_list because the reference count owned by these bios is only released when these bios complete.
3. blk_zone_wplug_bio_work() dequeues a bio from zwplug->bio_list, calls dm_submit_bio() through a function pointer, dm_submit_bio() calls submit_bio_noacct() indirectly and submit_bio_noacct() calls bio_queue_enter() indirectly. bio_queue_enter() sees that queue freezing has started and waits until the queue is unfrozen.
4. A deadlock occurs because (2) and (3) wait for each other indefinitely.

Then we need to split DM BIOs immediately on submission, always. So something like this totally untested patch should solve the issue. Care to test ?

block/blk-zoned.c +0 -0
index 55e64ca869d7..12aa56352176 100644
@@ -1129,6 +1129,44 @@ static void

blk_zone_wplug_handle_native_zone_append(struct bio *bio)

        disk_put_zone_wplug(zwplug);

}

+/**
+ * bio_needs_zone_write_plugging - Check if a BIO needs to be handled with zone
+ * write plugging
+ * @bio: The BIO being submitted
+ *
+ * Return true whenever @bio execution needs to be handled through zone
+ * write plugging. Return false otherwise.
+ */
+bool bio_needs_zone_write_plugging(struct bio *bio)
+{
+ if (!bdev_is_zoned(bio->bi_bdev))
+ return false;
+
+ /* Already handled ? */
+ if (bio_flagged(bio, BIO_ZONE_WRITE_PLUGGING))
+ return false;
+
+ /* Ignore empty flush */
+ if (op_is_flush(bio->bi_opf) && !bio_sectors(bio))
+ return false;
+
+ /*

+        * Regular writes and write zeroes need to be handled through zone
+        * write plugging. Zone append operations only need zone write plugging
+        * if they are emulated.
+        */

+ switch (bio_op(bio)) {
+ case REQ_OP_ZONE_APPEND:
+ return bdev_emulates_zone_append(bio->bi_bdev);
+ case REQ_OP_WRITE:
+ case REQ_OP_WRITE_ZEROES:
+ return true;
+ default:
+ return false;
+ }
+}
+EXPORT_SYMBOL_GPL(bio_needs_zone_write_plugging);
+
/**
* blk_zone_plug_bio - Handle a zone write BIO with zone write plugging
* @bio: The BIO being submitted

drivers/md/dm.c +0 -0
index 21920991ab28..5c2d98a5fdf8 100644
@@ -1771,16 +1771,6 @@ static void init_clone_info(struct clone_info *ci, struct

dm_io *io,
}

#ifdef CONFIG_BLK_DEV_ZONED
-static inline bool dm_zone_bio_needs_split(struct mapped_device *md,
- struct bio *bio)
-{
- /*

-        * For mapped device that need zone append emulation, we must
-        * split any large BIO that straddles zone boundaries.
-        */

- return dm_emulate_zone_append(md) && bio_straddles_zones(bio) &&
- !bio_flagged(bio, BIO_ZONE_WRITE_PLUGGING);
-}
static inline bool dm_zone_plug_bio(struct mapped_device *md, struct bio *bio)

 {
        return dm_emulate_zone_append(md) && blk_zone_plug_bio(bio, 0);

@@ -1899,11 +1889,6 @@ static blk_status_t __send_zone_reset_all(struct clone_info *ci)
}

#else
-static inline bool dm_zone_bio_needs_split(struct mapped_device *md,
- struct bio *bio)
-{
- return false;
-}
static inline bool dm_zone_plug_bio(struct mapped_device *md, struct bio *bio)

 {
        return false;
@@ -1928,8 +1913,7 @@ static void dm_split_and_process_bio(struct mapped_device *md,
        is_abnormal = is_abnormal_io(bio);
        if (static_branch_unlikely(&zoned_enabled)) {
                /* Special case REQ_OP_ZONE_RESET_ALL as it cannot be split. */
-               need_split = (bio_op(bio) != REQ_OP_ZONE_RESET_ALL) &&
-                       (is_abnormal || dm_zone_bio_needs_split(md, bio));
+               need_split = is_abnormal || bio_needs_zone_write_plugging(bio);
        } else {
                need_split = is_abnormal;
        }
include/linux/blkdev.h +2 -0
index c2b3ddea8b6d..c3cab300e4c2 100644
@@ -984,6 +984,8 @@ static inline bool bio_straddles_zones(struct bio *bio)
                disk_zone_no(bio->bi_bdev->bd_disk, bio_end_sector(bio) - 1);
 }
 
+bool bio_needs_zone_write_plugging(struct bio *bio);
+
 /*
  * Return how much within the boundary is left to be used for I/O at a given
  * offset.
Signature · 2 lines
Damien Le Moal
Western Digital Research
#9 lore raw
Quoted 23 lines · Damien Le Moal
Quoted 5 lines · Bart Van Assche
Quoted 2 lines · Damien Le Moal

Can you check exactly the path that is being followed ? (your backtrace does not seem to have everything)

Quoted 16 lines

Hmm ... it is not clear to me why this information is required? My understanding is that the root cause is the same as for the deadlock fixed by Christoph:
1. A bio is queued onto zwplug->bio_list. Before this happens, the queue reference count is increased by one.
2. A value is written into a block device sysfs attribute and queue freezing starts. The queue freezing code waits for completion of all bios on zwplug->bio_list because the reference count owned by these bios is only released when these bios complete.
3. blk_zone_wplug_bio_work() dequeues a bio from zwplug->bio_list, calls dm_submit_bio() through a function pointer, dm_submit_bio() calls submit_bio_noacct() indirectly and submit_bio_noacct() calls bio_queue_enter() indirectly. bio_queue_enter() sees that queue freezing has started and waits until the queue is unfrozen.
4. A deadlock occurs because (2) and (3) wait for each other indefinitely.

Quoted 3 lines

Then we need to split DM BIOs immediately on submission, always. So something like this totally untested patch should solve the issue. Care to test ?

(back in the office after four days off work)

Hi Damien,

Hmm ... it is not clear to me how a patch that modifies when bios are split could address the deadlock scenario described above? What am I missing? Additionally, hadn't Christoph requested not to split bios at the top of the device driver stack?

The patch that I posted one month ago is sufficient to fix this deadlock. See also
https://lore.kernel.org/linux-block/[email protected]/

Thanks,

Bart.

maintainer
#10 lore raw
Quoted 28 lines · Bart Van Assche
Quoted 23 lines · Damien Le Moal
Quoted 5 lines · Bart Van Assche
Quoted 1 line · Damien Le Moal

Can you check exactly the path that is being followed ? (your

  > backtrace does not seem to have everything)

Quoted 16 lines

Hmm ... it is not clear to me why this information is required? My understanding is that the root cause is the same as for the deadlock fixed by Christoph:
1. A bio is queued onto zwplug->bio_list. Before this happens, the queue reference count is increased by one.
2. A value is written into a block device sysfs attribute and queue freezing starts. The queue freezing code waits for completion of all bios on zwplug->bio_list because the reference count owned by these bios is only released when these bios complete.
3. blk_zone_wplug_bio_work() dequeues a bio from zwplug->bio_list, calls dm_submit_bio() through a function pointer, dm_submit_bio() calls submit_bio_noacct() indirectly and submit_bio_noacct() calls bio_queue_enter() indirectly. bio_queue_enter() sees that queue freezing has started and waits until the queue is unfrozen.
4. A deadlock occurs because (2) and (3) wait for each other indefinitely.

Quoted 3 lines

Then we need to split DM BIOs immediately on submission, always. So something like this totally untested patch should solve the issue. Care to test ?

Quoted 8 lines

(back in the office after four days off work)

Hi Damien,

Hmm ... it is not clear to me how a patch that modifies when bios are split could address the deadlock scenario described above? What am I missing? Additionally, hadn't Christoph requested not to split bios at the top of the device driver stack?

DM already calls bio split to limits at the top of its submission path. Not for all BIOs though.

I encourage you to look at the DM code more closely to understand the issue here. What is happening is that DM in general does *NOT* split write BIOs. But a DM target driver is free to do so using dm_accept_partial_bio() and that will cause the reminder of a BIO to be issued again but *NOT* necessarily from the same context. Because of zone write plugging, this may happen from the zone write plug BIO work, thus causing going through the queue enter which can deadlock with freeze when a BIO for the same zone is already plugged.

Zone write plugging heavily relies on the fact that once plugged, BIOs should *NOT* be split again, as otherwise we can deadlock. DM dm_accept_partial_bio() breaks that contract.

Quoted 3 lines

The patch that I posted one month ago is sufficient to fix this deadlock. See also
https://lore.kernel.org/linux-block/[email protected]/

I do not like this. This is playing weird games with the queue enter/exit which are very hard to understand. And I think Jens will not accept this as he does not want to see zone stuff all over the place (and I agree).

For a nicer solution, which is mostly DM-based, combine what I sent you to force write BIOs to be split early for zoned DM devices together with the patch [1], which I sent already but needs more work. This combination was tested by Shin'ichiro and he could not reproduce the hang with both patches applied.

[1] https://lore.kernel.org/dm-devel/[email protected]/

As far as I can tell, dm-crypt is the only DM target driver supporting zones that splits write operations "under the hood". But I will check again.

Signature · 2 lines
Damien Le Moal
Western Digital Research
#11 lore raw
Quoted 9 lines · Damien Le Moal

For a nicer solution, which is mostly DM-based, combine what I sent you to force write BIOs to be split early for zoned DM devices together with the patch [1], which I sent already but needs more work. This combination was tested by Shin'ichiro and he could not reproduce the hang with both patches applied.

[1] https://lore.kernel.org/dm-devel/[email protected]/

As far as I can tell, dm-crypt is the only DM target driver supporting zones that splits write operations "under the hood". But I will check again.

Hi Damien,

With both patches applied on top of Jens' for-next branch (2d5a3220c1f5 ("Merge branch 'block-6.16' into for-next"), I can't reproduce the deadlock anymore. This is unexpected because the deadlock happens between the queue freezing mechanism and zwplug->bio_list. No matter how bios are split, if bios are queued faster than these are processed, one or more bios end up on zwplug->bio_list and this deadlock can happen.

Did I perhaps overlook or misunderstand something?

Thanks,

Bart.

maintainer
#12 lore raw
Quoted 21 lines · Bart Van Assche
Quoted 9 lines · Damien Le Moal

For a nicer solution, which is mostly DM-based, combine what I sent you to force write BIOs to be split early for zoned DM devices together with the patch [1], which I sent already but needs more work. This combination was tested by Shin'ichiro and he could not reproduce the hang with both patches applied.

[1] https://lore.kernel.org/dm-devel/[email protected]/

As far as I can tell, dm-crypt is the only DM target driver supporting zones that splits write operations "under the hood". But I will check again.

Hi Damien,

With both patches applied on top of Jens' for-next branch (2d5a3220c1f5 ("Merge branch 'block-6.16' into for-next"), I can't reproduce the deadlock anymore. This is unexpected because the deadlock happens between the queue freezing mechanism and zwplug->bio_list. No matter how bios are split, if bios are queued faster than these are processed, one or more bios end up on zwplug->bio_list and this deadlock can happen.

Quoted 1 line

Did I perhaps overlook or misunderstand something?

Yes, because you focused on the block layer when the actual issue is in DM.

Any zoned DM target that uses zone append emulation will use zone write plugging. If in addition to this, the target driver uses dm_accept_partial_bio() to internally split BIOs, it can happen that a BIO that was plugged and issued from a zone write plug bio work is split using dm_accept_partial_bio(). In this case, the reminder of the BIO is issued again and thus there is a call to blk_queue_enter() which will block if a queue freeze is ongoing. This blocking is in the zone write plug bio work, which result in no forward progress: BIOs plugged are never unplugged and processed. Here is your deadlock.

So the solution is to force a split to the DM device limits of any write BIO in dm core, before the BIO is passed to the DM target map() function, *AND* prevent the target driver from further splitting a write BIO using dm_accept_partial_bio().

Only dm-crypt is affected by this. dm-flakey supports zoned targets and uses dm_accept_partial_bio() but it does not require zone append emulation so does not use zone write plugging.

Sending clean patches in a short while. I tested with your zbd/013 reproducer and all is good.

Signature · 2 lines
Damien Le Moal
Western Digital Research