All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] loop: nowait aio bug fixes
@ 2025-11-19  9:38 Ming Lei
  2025-11-19  9:38 ` [PATCH 1/3] loop: move kiocb_start_write to aio prep phase Ming Lei
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ming Lei @ 2025-11-19  9:38 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: Ming Lei

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.

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 +++++++++++++++++++---------
 include/linux/blkdev.h |  2 ++
 2 files changed, 21 insertions(+), 9 deletions(-)

-- 
2.47.0


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

* [PATCH 1/3] loop: move kiocb_start_write to aio prep phase
  2025-11-19  9:38 [PATCH 0/3] loop: nowait aio bug fixes Ming Lei
@ 2025-11-19  9:38 ` Ming Lei
  2025-11-19  9:38 ` [PATCH 2/3] loop: fix error handling in aio functions Ming Lei
  2025-11-19  9:38 ` [PATCH 3/3] loop: disable writeback throttling and fix nowait support Ming Lei
  2 siblings, 0 replies; 5+ messages in thread
From: Ming Lei @ 2025-11-19  9:38 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: Ming Lei

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")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/loop.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 9b842d767381..64295c141b97 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -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);
-- 
2.47.0


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

* [PATCH 2/3] loop: fix error handling in aio functions
  2025-11-19  9:38 [PATCH 0/3] loop: nowait aio bug fixes Ming Lei
  2025-11-19  9:38 ` [PATCH 1/3] loop: move kiocb_start_write to aio prep phase Ming Lei
@ 2025-11-19  9:38 ` Ming Lei
  2025-11-19  9:38 ` [PATCH 3/3] loop: disable writeback throttling and fix nowait support Ming Lei
  2 siblings, 0 replies; 5+ messages in thread
From: Ming Lei @ 2025-11-19  9:38 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: 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")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/loop.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 64295c141b97..705373b9668d 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -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;
-- 
2.47.0


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

* [PATCH 3/3] loop: disable writeback throttling and fix nowait support
  2025-11-19  9:38 [PATCH 0/3] loop: nowait aio bug fixes Ming Lei
  2025-11-19  9:38 ` [PATCH 1/3] loop: move kiocb_start_write to aio prep phase Ming Lei
  2025-11-19  9:38 ` [PATCH 2/3] loop: fix error handling in aio functions Ming Lei
@ 2025-11-19  9:38 ` Ming Lei
  2025-11-19 12:45   ` kernel test robot
  2 siblings, 1 reply; 5+ messages in thread
From: Ming Lei @ 2025-11-19  9:38 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: 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")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/loop.c   | 13 ++++++++++++-
 include/linux/blkdev.h |  2 ++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 705373b9668d..107760085ac5 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -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,
@@ -2250,6 +2259,8 @@ static int loop_add(int i)
 	lo->idr_visible = true;
 	mutex_unlock(&loop_ctl_mutex);
 
+	wbt_disable_default(disk);
+
 	return i;
 
 out_cleanup_disk:
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index cb4ba09959ee..4ed2248c19ea 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -449,6 +449,8 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_op op,
 		sector_t sectors, sector_t nr_sectors);
 int blk_revalidate_disk_zones(struct gendisk *disk);
 
+void wbt_disable_default(struct gendisk *disk);
+
 /*
  * Independent access ranges: struct blk_independent_access_range describes
  * a range of contiguous sectors that can be accessed using device command
-- 
2.47.0


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

* Re: [PATCH 3/3] loop: disable writeback throttling and fix nowait support
  2025-11-19  9:38 ` [PATCH 3/3] loop: disable writeback throttling and fix nowait support Ming Lei
@ 2025-11-19 12:45   ` kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-11-19 12:45 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe, linux-block; +Cc: oe-kbuild-all, Ming Lei

Hi Ming,

kernel test robot noticed the following build errors:

[auto build test ERROR on axboe/for-next]
[also build test ERROR on next-20251119]
[cannot apply to linus/master v6.18-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Ming-Lei/loop-move-kiocb_start_write-to-aio-prep-phase/20251119-174659
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux.git for-next
patch link:    https://lore.kernel.org/r/20251119093855.3405421-4-ming.lei%40redhat.com
patch subject: [PATCH 3/3] loop: disable writeback throttling and fix nowait support
config: nios2-allnoconfig (https://download.01.org/0day-ci/archive/20251119/202511192025.ApZLv3Ly-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251119/202511192025.ApZLv3Ly-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511192025.ApZLv3Ly-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from block/elevator.c:45:
>> block/blk-wbt.h:19:20: error: static declaration of 'wbt_disable_default' follows non-static declaration
      19 | static inline void wbt_disable_default(struct gendisk *disk)
         |                    ^~~~~~~~~~~~~~~~~~~
   In file included from block/elevator.c:28:
   include/linux/blkdev.h:452:6: note: previous declaration of 'wbt_disable_default' with type 'void(struct gendisk *)'
     452 | void wbt_disable_default(struct gendisk *disk);
         |      ^~~~~~~~~~~~~~~~~~~


vim +/wbt_disable_default +19 block/blk-wbt.h

e34cbd307477ae Jens Axboe        2016-11-09  18  
04aad37be1a88d Christoph Hellwig 2023-02-03 @19  static inline void wbt_disable_default(struct gendisk *disk)
e34cbd307477ae Jens Axboe        2016-11-09  20  {
e34cbd307477ae Jens Axboe        2016-11-09  21  }
04aad37be1a88d Christoph Hellwig 2023-02-03  22  static inline void wbt_enable_default(struct gendisk *disk)
e34cbd307477ae Jens Axboe        2016-11-09  23  {
e34cbd307477ae Jens Axboe        2016-11-09  24  }
e34cbd307477ae Jens Axboe        2016-11-09  25  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2025-11-19 12:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-19  9:38 [PATCH 0/3] loop: nowait aio bug fixes Ming Lei
2025-11-19  9:38 ` [PATCH 1/3] loop: move kiocb_start_write to aio prep phase Ming Lei
2025-11-19  9:38 ` [PATCH 2/3] loop: fix error handling in aio functions Ming Lei
2025-11-19  9:38 ` [PATCH 3/3] loop: disable writeback throttling and fix nowait support Ming Lei
2025-11-19 12:45   ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.