[PATCH] ublk: dispatch the next fetch after a batch failure
From: shao.mingyin
Date: Sat Nov 14 2026 - 11:35:28 EST
From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
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@xxxxxxxxxxxxxxx
Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
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