mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: <shao.mingyin@zte.com.cn>
To: <tom.leiming@gmail.com>, <linux-block@vger.kernel.org>
Cc: <axboe@kernel.dk>, <linux-kernel@vger.kernel.org>,
	<stable@vger.kernel.org>
Subject: [PATCH] ublk: dispatch the next fetch after a batch failure
Date: Sun, 15 Nov 2026 00:33:52 +0800 (CST)	[thread overview]
Message-ID: <20261115003352168cE_tyVxSyZV124AM31htL@zte.com.cn> (raw)

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

             reply	other threads:[~2026-11-14 16:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 16:33 shao.mingyin [this message]
2026-11-15 11:11 ` Ming Lei
2026-11-15 15:42 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261115003352168cE_tyVxSyZV124AM31htL@zte.com.cn \
    --to=shao.mingyin@zte.com.cn \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tom.leiming@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®