mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ublk: dispatch the next fetch after a batch failure
@ 2026-11-14 16:33 shao.mingyin
  2026-11-15 11:11 ` Ming Lei
  2026-11-15 15:42 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: shao.mingyin @ 2026-11-14 16:33 UTC (permalink / raw)
  To: tom.leiming, linux-block; +Cc: axboe, linux-kernel, stable

From: Shao Mingyin <shao.mingyin@zte.com.cn>

When a batch fetch fails, for example because its provided-buffer group
is empty, ublk_batch_dispatch() removes the failed fetch and returns.
Pending I/O tags stay in evts_fifo even if another fetch with usable
buffers is already queued. With no new I/O or fetch submission to select
it, that fetch and the outstanding block requests cannot make progress.

Claim the next queued fetch under evts_lock before completing and freeing
the failed one, then schedule its dispatch in the proper task context.
Marking it active before dropping the lock also prevents cancellation
from taking it before its task work is queued.

Fixes: a4d883755399 ("ublk: add UBLK_U_IO_FETCH_IO_CMDS for batch I/O processing")
Cc: stable@vger.kernel.org
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
Tested on next-20261105 in an x86_64 QEMU/KVM guest (4 vCPUs, 2 GiB)
with CONFIG_BLK_DEV_UBLK=y and the in-tree kublk batch server. A test-only
userspace change leaves the first fetch's buffer group empty and does
not resubmit that failed fetch. The same server binary is used for both
kernels; there are no test hooks in the driver.

With partition scanning disabled, one 4 KiB O_DIRECT read stalls on the
original kernel after the first fetch returns -ENOBUFS. With the fix,
the already queued second fetch receives the tag and the read completes.
All three independent boots per kernel reproduce this difference. Three
normal-buffer control boots per kernel also complete the read.

 drivers/block/ublk_drv.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 3d322fa1bc83160f51fbd97fb89b17ee94bc1213..6ca62a2ff7453001d005a854f5923e204952adb0 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -835,23 +835,27 @@ static void __ublk_release_fcmd(struct ublk_queue *ubq)
 	WRITE_ONCE(ubq->active_fcmd, NULL);
 }
 
-/*
- * Nothing can move on, so clear ->active_fcmd, and the caller should stop
- * dispatching
- */
-static void ublk_batch_deinit_fetch_buf(struct ublk_queue *ubq,
-					const struct ublk_batch_io_data *data,
-					struct ublk_batch_fetch_cmd *fcmd,
-					int res)
+static struct ublk_batch_fetch_cmd *__ublk_acquire_fcmd(struct ublk_queue *ubq);
+
+/* Remove the failed fetch and claim the next one before dropping its reference. */
+static struct ublk_batch_fetch_cmd *
+ublk_batch_deinit_fetch_buf(struct ublk_queue *ubq,
+			    const struct ublk_batch_io_data *data,
+			    struct ublk_batch_fetch_cmd *fcmd,
+			    int res)
 {
+	struct ublk_batch_fetch_cmd *next_fcmd;
+
 	spin_lock(&ubq->evts_lock);
 	list_del_init(&fcmd->node);
 	WARN_ON_ONCE(fcmd != ubq->active_fcmd);
 	__ublk_release_fcmd(ubq);
+	next_fcmd = __ublk_acquire_fcmd(ubq);
 	spin_unlock(&ubq->evts_lock);
 
 	io_uring_cmd_done(fcmd->cmd, res, data->issue_flags);
 	ublk_batch_free_fcmd(fcmd);
+	return next_fcmd;
 }
 
 static int ublk_batch_fetch_post_cqe(struct ublk_batch_fetch_cmd *fcmd,
@@ -2040,7 +2044,10 @@ again:
 	}
 
 	if (ret < 0) {
-		ublk_batch_deinit_fetch_buf(ubq, data, fcmd, ret);
+		new_fcmd = ublk_batch_deinit_fetch_buf(ubq, data, fcmd, ret);
+		if (new_fcmd)
+			io_uring_cmd_complete_in_task(new_fcmd->cmd,
+						      ublk_batch_tw_cb);
 		return;
 	}
 
-- 
2.43.0

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

* Re: [PATCH] ublk: dispatch the next fetch after a batch failure
  2026-11-14 16:33 [PATCH] ublk: dispatch the next fetch after a batch failure shao.mingyin
@ 2026-11-15 11:11 ` Ming Lei
  2026-11-15 15:42 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Ming Lei @ 2026-11-15 11:11 UTC (permalink / raw)
  To: shao.mingyin; +Cc: linux-block, axboe, linux-kernel, stable

On Sat, Nov 14, 2026 at 10:33 AM <shao.mingyin@zte.com.cn> wrote:
>
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
>
> When a batch fetch fails, for example because its provided-buffer group
> is empty, ublk_batch_dispatch() removes the failed fetch and returns.
> Pending I/O tags stay in evts_fifo even if another fetch with usable
> buffers is already queued. With no new I/O or fetch submission to select
> it, that fetch and the outstanding block requests cannot make progress.
>
> Claim the next queued fetch under evts_lock before completing and freeing
> the failed one, then schedule its dispatch in the proper task context.
> Marking it active before dropping the lock also prevents cancellation
> from taking it before its task work is queued.
>
> Fixes: a4d883755399 ("ublk: add UBLK_U_IO_FETCH_IO_CMDS for batch I/O processing")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>

Reviewed-by: Ming Lei <tom.leiming@gmail.com>

Thanks,
Ming

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

* Re: [PATCH] ublk: dispatch the next fetch after a batch failure
  2026-11-14 16:33 [PATCH] ublk: dispatch the next fetch after a batch failure shao.mingyin
  2026-11-15 11:11 ` Ming Lei
@ 2026-11-15 15:42 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2026-11-15 15:42 UTC (permalink / raw)
  To: tom.leiming, linux-block, shao.mingyin; +Cc: linux-kernel, stable


On Sun, 15 Nov 2026 00:33:52 +0800, shao.mingyin@zte.com.cn wrote:
> When a batch fetch fails, for example because its provided-buffer group
> is empty, ublk_batch_dispatch() removes the failed fetch and returns.
> Pending I/O tags stay in evts_fifo even if another fetch with usable
> buffers is already queued. With no new I/O or fetch submission to select
> it, that fetch and the outstanding block requests cannot make progress.
> 
> Claim the next queued fetch under evts_lock before completing and freeing
> the failed one, then schedule its dispatch in the proper task context.
> Marking it active before dropping the lock also prevents cancellation
> from taking it before its task work is queued.
> 
> [...]

Applied, thanks!

[1/1] ublk: dispatch the next fetch after a batch failure
      commit: a6f37fb3f5747bb7cca5cd6630dfeea4435022a1

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2026-11-15 15:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-14 16:33 [PATCH] ublk: dispatch the next fetch after a batch failure shao.mingyin
2026-11-15 11:11 ` Ming Lei
2026-11-15 15:42 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®