Skip to contentSkip to conversation

loop: nowait aio bug fixes

PATCH Superseded Ming Lei 1 participant 4 messages Nov 19, 2025 Block layer

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

v2 cover loop: nowait aio bug fixes

Hi Jens,

The 1st two patches fix error handling code paths for nowait aio.

The last patch fixes IO hang issue because of writeback throttle.

V2:
- use QUEUE_FLAG_DISABLE_WBT_DEF to disable wbt, so that check of QUEUE_FLAG_QOS_ENABLED can work as expected

Ming Lei (3):
loop: move kiocb_start_write to aio prep phase
loop: fix error handling in aio functions
loop: disable writeback throttling and fix nowait support

 drivers/block/loop.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)
Signature · 1 line
2.47.0
author
#1 lore raw

PATCH v2 1/3 loop: move kiocb_start_write to aio prep phase

Move the kiocb_start_write() call from lo_submit_rw_aio() to lo_rw_aio_prep() to initialize write accounting earlier in the I/O preparation phase rather than during submission.

Make sure both kiocb_start_write() and kiocb_end_write() are called just once.

Fixes 0ba93a906dda ("loop: try to handle loop aio command via NOWAIT IO first")
---
 drivers/block/loop.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/block/loop.c +5 -4
index 9b842d767381..64295c141b97 100644
@@ -402,6 +402,9 @@ static int lo_rw_aio_prep(struct loop_device *lo, struct loop_cmd *cmd,
 		cmd->iocb.ki_complete = NULL;
 		cmd->iocb.ki_flags = 0;
 	}
+
+	if (req_op(rq) == REQ_OP_WRITE)
+		kiocb_start_write(&cmd->iocb);
 	return 0;
 }
 
@@ -431,11 +434,9 @@ static int lo_submit_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
 	}
 	atomic_set(&cmd->ref, 2);
 
-
-	if (rw == ITER_SOURCE) {
-		kiocb_start_write(&cmd->iocb);
+	if (rw == ITER_SOURCE)
 		ret = file->f_op->write_iter(&cmd->iocb, &iter);
-	} else
+	else
 		ret = file->f_op->read_iter(&cmd->iocb, &iter);
 
 	lo_rw_aio_do_completion(cmd);
Signature · 1 line
2.47.0
author
#2 lore raw

PATCH v2 2/3 loop: fix error handling in aio functions

In reply to Ming Lei

Replace goto fail with direct return in lo_rw_aio() and lo_rw_aio_nowait() error paths.

We can't call lo_rw_aio_complete() for early completion when lo request reference isn't initialized yet.

Fixes 0ba93a906dda ("loop: try to handle loop aio command via NOWAIT IO first")
---
 drivers/block/loop.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/block/loop.c +2 -4
index 64295c141b97..705373b9668d 100644
@@ -458,12 +458,11 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
 	if (!cmd->use_aio || !lo_backfile_support_nowait(lo)) {
 		ret = lo_rw_aio_prep(lo, cmd, nr_bvec, pos);
 		if (unlikely(ret))
-			goto fail;
+			return ret;
 	}
 
 	cmd->iocb.ki_flags &= ~IOCB_NOWAIT;
 	ret = lo_submit_rw_aio(lo, cmd, nr_bvec, rw);
-fail:
 	if (ret != -EIOCBQUEUED)
 		lo_rw_aio_complete(&cmd->iocb, ret);
 	return -EIOCBQUEUED;
@@ -505,14 +504,13 @@ static int lo_rw_aio_nowait(struct loop_device *lo, struct loop_cmd *cmd,
 	int ret = lo_rw_aio_prep(lo, cmd, nr_bvec, pos);
 
 	if (unlikely(ret))
-		goto fail;
+		return ret;
 
 	if (!lo_aio_try_nowait(lo, cmd))
 		return -EAGAIN;
 
 	cmd->iocb.ki_flags |= IOCB_NOWAIT;
 	ret = lo_submit_rw_aio(lo, cmd, nr_bvec, rw);
-fail:
 	if (ret != -EIOCBQUEUED && ret != -EAGAIN)
 		lo_rw_aio_complete(&cmd->iocb, ret);
 	return ret;
Signature · 1 line
2.47.0
author
#3 lore raw

PATCH v2 3/3 loop: disable writeback throttling and fix nowait support

In reply to Ming Lei

Disable writeback throttling by default for loop devices to avoid deadlock scenarios when RQOS features are enabled. This way is fine for loop because the backing device covers writeback throttle too.

Update lo_backfile_support_nowait() to check both backing file's FMODE_NOWAIT support and the queue's QOS enablement status. This prevents deadlocks in submit_bio() code path when RQOS takes online wait and blocks backing file IOs.

Fixes 0ba93a906dda ("loop: try to handle loop aio command via NOWAIT IO first")
---
 drivers/block/loop.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/block/loop.c +12 -1
index 705373b9668d..31be3db02caa 100644
@@ -443,9 +443,18 @@ static int lo_submit_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
 	return ret;
 }
 
+/*
+ * Allow NOWAIT only if the backing file supports it, and loop disk's
+ * RQOS feature isn't enabled.
+ *
+ * RQOS takes online wait in submit_bio() code path, and IOs to backing
+ * file may be blocked, then deadlock is caused, see
+ * submit_bio_noacct_nocheck().
+ */
 static bool lo_backfile_support_nowait(const struct loop_device *lo)
 {
-	return lo->lo_backing_file->f_mode & FMODE_NOWAIT;
+	return (lo->lo_backing_file->f_mode & FMODE_NOWAIT) &&
+		!test_bit(QUEUE_FLAG_QOS_ENABLED, &lo->lo_queue->queue_flags);
 }
 
 static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
@@ -2205,6 +2214,8 @@ static int loop_add(int i)
 	}
 	lo->lo_queue = lo->lo_disk->queue;
 
+	blk_queue_flag_set(QUEUE_FLAG_DISABLE_WBT_DEF, lo->lo_queue);
+
 	/*
 	 * Disable partition scanning by default. The in-kernel partition
 	 * scanning can be requested individually per-device during its
Signature · 1 line
2.47.0