From: Qiliang Yuan <qiliang.yuan@linux.dev>
To: "Martin K. Petersen" <mkp@kernel.org>,
Shuah Khan <shuah@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>
Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
target-devel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-doc@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
io-uring@vger.kernel.org,
Mike Christie <michael.christie@oracle.com>,
Bodo Stroesser <bostroesser@gmail.com>,
Ming Lei <tom.leiming@gmail.com>,
Qiliang Yuan <qiliang.yuan@linux.dev>
Subject: [PATCH RFC 15/18] scsi: target: uring: Register command data as io_uring fixed buffers
Date: Sun, 15 Nov 2026 19:18:08 -0500 [thread overview]
Message-ID: <20261115-feat-target-core-uring-v1-15-28cdc137eac6@linux.dev> (raw)
In-Reply-To: <20261115-feat-target-core-uring-v1-0-28cdc137eac6@linux.dev>
The server of a target_core_uring device copies the data of each command
with pread() or pwrite().
For large commands that copy dominates, although the server often only
passes the data on to a file, a block device or a socket.
Add TCMUR_IO_REGISTER_BUF, which registers the pages of a command as a
fixed buffer of the server's io_uring, and TCMUR_IO_UNREGISTER_BUF. The
server then uses the buffer in fixed read and write requests on its
backing store. Let the buffer hold a reference on the command, so that
the command completes only after the buffer is released.
Exporting a 2 GiB device through tcm_loop to fio (io_uring, direct I/O,
iodepth 32 for 4k and 8 for 1M, 6 seconds per job) on a 32 CPU VM, with
32 queues and a server that keeps the data in a tmpfs file, copying
through a bounce buffer or using fixed buffers. Small commands are
slower with fixed buffers, as each one takes two more io_uring requests;
the server can choose per command. Three alternating runs (median,
min-max in parentheses):
workload copy (MB/s) fixed buffer (MB/s) change
4k randread, 16 jobs 5808 (5463-5944) 5217 (5090-5463) -10%
4k randwrite, 16 jobs 2023 (1831-2101) 1845 (1571-1850) -9%
1M read, 4 jobs 21516 (10137-22138) 44973 (31086-45013) +109%
1M write, 4 jobs 5997 (5669-7364) 7430 (5970-8002) +24%
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
drivers/target/target_core_uring.c | 60 ++++++++++++++++++++++++++++++++--
include/uapi/linux/target_core_uring.h | 13 ++++++--
2 files changed, 69 insertions(+), 4 deletions(-)
diff --git a/drivers/target/target_core_uring.c b/drivers/target/target_core_uring.c
index 42283a1ae1512..4f5cf18b1ec07 100644
--- a/drivers/target/target_core_uring.c
+++ b/drivers/target/target_core_uring.c
@@ -48,8 +48,8 @@ struct tcmur_dev;
* @sgl: Data pages of the command
* @sgl_nents: Number of entries in @sgl
* @desc: What the server is asked to do
- * @ref: Held by the tag or the pending list and by data copies in
- * progress
+ * @ref: Held by the tag or the pending list, by data copies in
+ * progress and by registered buffers
* @deadline: When to give up waiting for the server
* @done: Complete this instead of @se_cmd when the last reference goes
* @status: SAM status to complete @se_cmd with
@@ -489,6 +489,56 @@ static int tcmur_commit(struct tcmur_queue *q, struct tcmur_io *io, int result)
return 0;
}
+static void tcmur_buf_release(void *priv)
+{
+ tcmur_cmd_put(priv);
+}
+
+static int tcmur_register_buf(struct tcmur_dev *udev, u16 q_id, u16 tag,
+ struct io_uring_cmd *ucmd, unsigned int index,
+ unsigned int issue_flags)
+{
+ struct tcmur_cmd *tcmd = tcmur_get_cmd(udev, q_id, tag);
+ unsigned int len, n = 0;
+ struct scatterlist *sg;
+ struct bio_vec *bvs;
+ int ret = -EINVAL;
+ u32 left;
+ int i;
+
+ if (!tcmd)
+ return -EINVAL;
+ if (!tcmd->desc.data_len)
+ goto put_cmd;
+
+ bvs = kmalloc_array(tcmd->sgl_nents, sizeof(*bvs), GFP_KERNEL);
+ if (!bvs) {
+ ret = -ENOMEM;
+ goto put_cmd;
+ }
+
+ left = tcmd->desc.data_len;
+ for_each_sg(tcmd->sgl, sg, tcmd->sgl_nents, i) {
+ len = min(sg->length, left);
+ bvec_set_page(&bvs[n++], sg_page(sg), len, sg->offset);
+ left -= len;
+ if (!left)
+ break;
+ }
+
+ /* Keep the command reference until the buffer is released */
+ ret = io_buffer_register_bvec(ucmd, bvs, n, tcmur_buf_release, tcmd,
+ tcmd->desc.op == TCMUR_OP_READ ?
+ IO_BUF_DEST : IO_BUF_SOURCE,
+ index, issue_flags);
+ kfree(bvs);
+ if (!ret)
+ return 0;
+put_cmd:
+ tcmur_cmd_put(tcmd);
+ return ret;
+}
+
static int tcmur_ch_uring_cmd_local(struct io_uring_cmd *ucmd,
unsigned int issue_flags)
{
@@ -515,6 +565,12 @@ static int tcmur_ch_uring_cmd_local(struct io_uring_cmd *ucmd,
if (ret)
return ret;
return tcmur_fetch(q, io, ucmd, issue_flags);
+ case TCMUR_IO_REGISTER_BUF:
+ return tcmur_register_buf(udev, q_id, tag, ucmd,
+ READ_ONCE(ioc->addr), issue_flags);
+ case TCMUR_IO_UNREGISTER_BUF:
+ return io_buffer_unregister(ucmd, READ_ONCE(ioc->addr),
+ issue_flags);
default:
return -EOPNOTSUPP;
}
diff --git a/include/uapi/linux/target_core_uring.h b/include/uapi/linux/target_core_uring.h
index 469340b152f15..92d3d2fc9c25e 100644
--- a/include/uapi/linux/target_core_uring.h
+++ b/include/uapi/linux/target_core_uring.h
@@ -45,13 +45,14 @@ struct tcmur_dev_info {
* @tag: Tag the command is for
* @result: TCMUR_IO_COMMIT_AND_FETCH: 0, or a negative errno if the
* command failed
- * @reserved1: Zero
+ * @addr: TCMUR_IO_REGISTER_BUF and TCMUR_IO_UNREGISTER_BUF: index in the
+ * buffer table of the ring
*/
struct tcmur_io_cmd {
__u16 q_id;
__u16 tag;
__s32 result;
- __u64 reserved1;
+ __u64 addr;
};
/*
@@ -64,6 +65,14 @@ struct tcmur_io_cmd {
#define TCMUR_IO_FETCH _IOWR(0xBB, 0x08, struct tcmur_io_cmd)
#define TCMUR_IO_COMMIT_AND_FETCH _IOWR(0xBB, 0x09, struct tcmur_io_cmd)
+/*
+ * TCMUR_IO_REGISTER_BUF: register the data pages of the command of
+ * (q_id, tag) as fixed buffer @addr of the ring, so that the server can
+ * do I/O on them without copying. TCMUR_IO_UNREGISTER_BUF removes it.
+ */
+#define TCMUR_IO_REGISTER_BUF _IOWR(0xBB, 0x0a, struct tcmur_io_cmd)
+#define TCMUR_IO_UNREGISTER_BUF _IOWR(0xBB, 0x0b, struct tcmur_io_cmd)
+
enum tcmur_io_op {
TCMUR_OP_READ,
TCMUR_OP_WRITE,
--
2.43.0
next prev parent reply other threads:[~2026-11-16 0:19 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 0:17 [PATCH RFC 00/18] scsi: target: Add target_core_uring, an io_uring based user backstore Qiliang Yuan
2026-11-16 0:17 ` [PATCH RFC 01/18] scsi: target: uring: Introduce " Qiliang Yuan
2026-11-16 0:17 ` [PATCH RFC 02/18] scsi: target: uring: Allocate per-queue command descriptors Qiliang Yuan
2026-11-16 0:17 ` [PATCH RFC 03/18] scsi: target: uring: Create a character device per backstore device Qiliang Yuan
2026-11-16 0:17 ` [PATCH RFC 04/18] scsi: target: uring: Map the command descriptors into the server Qiliang Yuan
2026-11-16 0:17 ` [PATCH RFC 05/18] scsi: target: uring: Queue commands until a server fetches them Qiliang Yuan
2026-11-16 0:17 ` [PATCH RFC 06/18] scsi: target: uring: Hand commands out through TCMUR_IO_FETCH Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 07/18] scsi: target: uring: Complete commands with TCMUR_IO_COMMIT_AND_FETCH Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 08/18] scsi: target: uring: Copy command data with pread() and pwrite() Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 09/18] scsi: target: uring: Fail in-flight commands when the server exits Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 10/18] scsi: target: uring: Time out commands the server does not complete Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 11/18] scsi: target: uring: Drop aborted commands that are still queued Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 12/18] scsi: target: uring: Support SYNCHRONIZE CACHE Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 13/18] scsi: target: uring: Implement UNMAP Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 14/18] scsi: target: uring: Handle WRITE SAME Qiliang Yuan
2026-11-16 0:18 ` Qiliang Yuan [this message]
2026-11-16 0:18 ` [PATCH RFC 16/18] selftests: target_core_uring: Add a minimal server Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 17/18] selftests: target_core_uring: Test a device exported through tcm_loop Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 18/18] Documentation: target: Describe the uring backstore Qiliang Yuan
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=20261115-feat-target-core-uring-v1-15-28cdc137eac6@linux.dev \
--to=qiliang.yuan@linux.dev \
--cc=axboe@kernel.dk \
--cc=bostroesser@gmail.com \
--cc=corbet@lwn.net \
--cc=io-uring@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=michael.christie@oracle.com \
--cc=mkp@kernel.org \
--cc=rdunlap@infradead.org \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=target-devel@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®