From: Ming Lei <tom.leiming@gmail.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Ming Lei <tom.leiming@gmail.com>,
Caleb Sander Mateos <csander@purestorage.com>,
Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 3/5] ublk: don't complete a short request in full
Date: Sun, 29 Nov 2026 20:39:28 -0600 [thread overview]
Message-ID: <20261130023937.606428-4-tom.leiming@gmail.com> (raw)
In-Reply-To: <20261130023937.606428-1-tom.leiming@gmail.com>
Since commit a8a79eba22dc ("ublk: lift checks out of
ublk_{,un}map_io()"), __ublk_complete_rq() ends the request in full and
ignores io->res when there is nothing to copy back: every WRITE, and
every request on a user copy, zero copy or auto buffer registration
device. A short write or read from the server is reported as complete.
Shmem zero copy requests have had the same problem since commit
4d4a512a1f87 ("ublk: add PFN-based buffer matching in I/O path").
Skip only the copy step, and complete READ and WRITE by io->res through
blk_update_request() again, requeueing the rest. Other requests are
still ended directly, including report zones, whose reply can be short.
Fixes: a8a79eba22dc ("ublk: lift checks out of ublk_{,un}map_io()")
Fixes: 4d4a512a1f87 ("ublk: add PFN-based buffer matching in I/O path")
Cc: stable@vger.kernel.org
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
drivers/block/ublk_drv.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index db1b049b7ac0..69778b34ffd0 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -1569,7 +1569,6 @@ static void ublk_end_request(struct request *req, blk_status_t error)
local_bh_enable();
}
-/* todo: handle partial completion */
static inline void __ublk_complete_rq(struct request *req, struct ublk_io *io,
bool need_map, struct io_comp_batch *iob)
{
@@ -1594,10 +1593,24 @@ static inline void __ublk_complete_rq(struct request *req, struct ublk_io *io,
goto exit;
}
- /* shmem zero copy: no data to unmap, pages already shared */
+ /*
+ * FLUSH, DISCARD, WRITE_ZEROES and zone management requests usually
+ * don't return a byte count, so end them directly. So is report zones
+ * (DRV_IN): its reply can be shorter than the buffer, and a requeued
+ * rest would rerun the report. So is zone append: a requeued rest would
+ * be appended again at a moved write pointer.
+ */
+ if (req_op(req) != REQ_OP_READ && req_op(req) != REQ_OP_WRITE)
+ goto exit;
+
+ /*
+ * Nothing to copy for WRITE, user copy, zero copy, auto buffer
+ * registration or shmem zero copy, but io->res still tells how many
+ * bytes are done.
+ */
if (!need_map || !ublk_need_unmap_req(req) ||
ublk_iod_is_shmem_zc(req->mq_hctx->driver_data, req->tag))
- goto exit;
+ goto update;
/* for READ request, writing data in iod->addr to rq buffers */
unmapped_bytes = ublk_unmap_io(req, io);
@@ -1618,6 +1631,7 @@ static inline void __ublk_complete_rq(struct request *req, struct ublk_io *io,
io->res = unmapped_bytes;
}
+update:
/*
* Run bio->bi_end_io() with softirqs disabled. If the final fput
* happens off this path, then that will prevent ublk's blkdev_release()
--
2.56.1
next prev parent reply other threads:[~2026-11-30 2:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 2:39 [PATCH 0/5] ublk: fix completion of short READ/WRITE Ming Lei
2026-11-30 2:39 ` [PATCH 1/5] ublk: fail READ/WRITE if the result from the server is invalid Ming Lei
2026-11-30 2:39 ` [PATCH 2/5] selftests: ublk: complete a striped request with its full length Ming Lei
2026-11-30 2:39 ` Ming Lei [this message]
2026-11-30 2:39 ` [PATCH 4/5] ublk: fail a short zone append Ming Lei
2026-11-30 2:39 ` [PATCH 5/5] selftests: ublk: test that a short request isn't completed in full Ming Lei
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=20261130023937.606428-4-tom.leiming@gmail.com \
--to=tom.leiming@gmail.com \
--cc=axboe@kernel.dk \
--cc=csander@purestorage.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
/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