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 02/18] scsi: target: uring: Allocate per-queue command descriptors
Date: Sun, 15 Nov 2026 19:17:55 -0500 [thread overview]
Message-ID: <20261115-feat-target-core-uring-v1-2-28cdc137eac6@linux.dev> (raw)
In-Reply-To: <20261115-feat-target-core-uring-v1-0-28cdc137eac6@linux.dev>
A target_core_uring device only has a size and a block size so far.
The server needs to learn what each command asks for, and commands
submitted on different CPUs should not share state.
Add the nr_queues and queue_depth parameters and allocate that many
queues when the device is configured. Give each queue an array of
struct tcmur_io_desc, one per tag, that describes a command as an
operation, an offset and a length. Define the descriptor in a new uAPI
header and allocate the array with vmalloc_user() so that it can be
mapped later.
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
MAINTAINERS | 1 +
drivers/target/target_core_uring.c | 90 +++++++++++++++++++++++++++++++++-
include/uapi/linux/target_core_uring.h | 43 ++++++++++++++++
3 files changed, 133 insertions(+), 1 deletion(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 3e31de6e2ebfb..07148430d9ea6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -25330,6 +25330,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git
F: Documentation/target/
F: drivers/target/
F: include/target/
+F: include/uapi/linux/target_core_uring.h
SCTP PROTOCOL
M: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
diff --git a/drivers/target/target_core_uring.c b/drivers/target/target_core_uring.c
index 13981e608a85c..135435748d367 100644
--- a/drivers/target/target_core_uring.c
+++ b/drivers/target/target_core_uring.c
@@ -7,20 +7,40 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
+#include <linux/mm.h>
#include <linux/parser.h>
#include <linux/slab.h>
+#include <linux/vmalloc.h>
#include <target/target_core_base.h>
#include <target/target_core_backend.h>
+#include <uapi/linux/target_core_uring.h>
#define TCMUR_VERSION "1.0"
#define TCMUR_MAX_IO_SIZE (4U << 20)
+#define TCMUR_DEF_QUEUE_DEPTH 128
#define TCMUR_DEF_BLOCK_SIZE 512
+struct tcmur_dev;
+
+/**
+ * struct tcmur_queue - One command queue
+ * @descs: Command descriptors, indexed by tag
+ * @udev: Device the queue belongs to
+ */
+struct tcmur_queue {
+ struct tcmur_io_desc *descs;
+ struct tcmur_dev *udev;
+} ____cacheline_aligned_in_smp;
+
struct tcmur_dev {
struct se_device se_dev;
u64 dev_size;
u32 block_size;
+ u16 nr_queues;
+ u16 queue_depth;
+
+ struct tcmur_queue *queues;
};
static struct tcmur_dev *TCMUR_DEV(struct se_device *dev)
@@ -36,6 +56,47 @@ static sense_reason_t tcmur_execute_rw(struct se_cmd *se_cmd,
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
}
+static size_t tcmur_desc_area_size(struct tcmur_dev *udev)
+{
+ return PAGE_ALIGN(udev->queue_depth * sizeof(struct tcmur_io_desc));
+}
+
+static void tcmur_free_queues(struct tcmur_dev *udev)
+{
+ unsigned int i;
+
+ if (!udev->queues)
+ return;
+
+ for (i = 0; i < udev->nr_queues; i++)
+ vfree(udev->queues[i].descs);
+ kvfree(udev->queues);
+ udev->queues = NULL;
+}
+
+static int tcmur_alloc_queues(struct tcmur_dev *udev)
+{
+ struct tcmur_queue *q;
+ unsigned int i;
+
+ udev->queues = kvcalloc(udev->nr_queues, sizeof(*udev->queues),
+ GFP_KERNEL);
+ if (!udev->queues)
+ return -ENOMEM;
+
+ for (i = 0; i < udev->nr_queues; i++) {
+ q = &udev->queues[i];
+
+ q->udev = udev;
+ q->descs = vmalloc_user(tcmur_desc_area_size(udev));
+ if (!q->descs) {
+ tcmur_free_queues(udev);
+ return -ENOMEM;
+ }
+ }
+ return 0;
+}
+
static void tcmur_dev_call_rcu(struct rcu_head *p)
{
struct se_device *dev = container_of(p, struct se_device, rcu_head);
@@ -61,6 +122,8 @@ static struct se_device *tcmur_alloc_device(struct se_hba *hba,
if (!udev)
return NULL;
+ udev->nr_queues = 1;
+ udev->queue_depth = TCMUR_DEF_QUEUE_DEPTH;
udev->block_size = TCMUR_DEF_BLOCK_SIZE;
return &udev->se_dev;
@@ -69,14 +132,20 @@ static struct se_device *tcmur_alloc_device(struct se_hba *hba,
static int tcmur_configure_device(struct se_device *dev)
{
struct tcmur_dev *udev = TCMUR_DEV(dev);
+ int ret;
if (!udev->dev_size || (udev->dev_size & (udev->block_size - 1))) {
pr_err("dev_size must be a multiple of the block size\n");
return -EINVAL;
}
+ ret = tcmur_alloc_queues(udev);
+ if (ret)
+ return ret;
+
dev->dev_attrib.hw_block_size = udev->block_size;
dev->dev_attrib.hw_max_sectors = TCMUR_MAX_IO_SIZE / udev->block_size;
+ dev->dev_attrib.hw_queue_depth = udev->nr_queues * udev->queue_depth;
dev->dev_attrib.is_nonrot = 1;
return 0;
@@ -84,6 +153,9 @@ static int tcmur_configure_device(struct se_device *dev)
static void tcmur_destroy_device(struct se_device *dev)
{
+ struct tcmur_dev *udev = TCMUR_DEV(dev);
+
+ tcmur_free_queues(udev);
}
static void tcmur_free_device(struct se_device *dev)
@@ -92,12 +164,14 @@ static void tcmur_free_device(struct se_device *dev)
}
enum {
- Opt_dev_size, Opt_block_size, Opt_err,
+ Opt_dev_size, Opt_block_size, Opt_nr_queues, Opt_queue_depth, Opt_err,
};
static const match_table_t tcmur_tokens = {
{ Opt_dev_size, "dev_size=%s" },
{ Opt_block_size, "block_size=%u" },
+ { Opt_nr_queues, "nr_queues=%u" },
+ { Opt_queue_depth, "queue_depth=%u" },
{ Opt_err, NULL }
};
@@ -141,6 +215,18 @@ static ssize_t tcmur_set_configfs_dev_params(struct se_device *dev,
else
udev->block_size = val;
break;
+ case Opt_nr_queues:
+ if (!val || val > TCMUR_MAX_NR_QUEUES)
+ ret = -EINVAL;
+ else
+ udev->nr_queues = val;
+ break;
+ case Opt_queue_depth:
+ if (!val || val > TCMUR_MAX_QUEUE_DEPTH)
+ ret = -EINVAL;
+ else
+ udev->queue_depth = val;
+ break;
}
}
@@ -155,6 +241,8 @@ static ssize_t tcmur_show_configfs_dev_params(struct se_device *dev, char *b)
bl += sprintf(b + bl, "Size: %llu Block size: %u", udev->dev_size,
udev->block_size);
+ bl += sprintf(b + bl, " Queues: %u Queue depth: %u", udev->nr_queues,
+ udev->queue_depth);
bl += sprintf(b + bl, "\n");
return bl;
}
diff --git a/include/uapi/linux/target_core_uring.h b/include/uapi/linux/target_core_uring.h
new file mode 100644
index 0000000000000..64fa1dfcd011f
--- /dev/null
+++ b/include/uapi/linux/target_core_uring.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_LINUX_TARGET_CORE_URING_H
+#define _UAPI_LINUX_TARGET_CORE_URING_H
+
+#include <linux/types.h>
+
+/*
+ * target_core_uring hands the block commands of a LIO device to a userspace
+ * server.
+ */
+
+#define TCMUR_MAX_NR_QUEUES 512
+#define TCMUR_MAX_QUEUE_DEPTH 4096
+
+enum tcmur_io_op {
+ TCMUR_OP_READ,
+ TCMUR_OP_WRITE,
+};
+
+/* Put the write on stable storage before completing it */
+#define TCMUR_IO_F_FUA (1U << 0)
+
+/**
+ * struct tcmur_io_desc - Describe one command
+ * @op: Operation, one of enum tcmur_io_op
+ * @flags: TCMUR_IO_F_*
+ * @offset: Start of the range in bytes
+ * @len: Length of the range in bytes
+ * @data_len: Bytes of data to transfer
+ * @reserved: Zero
+ *
+ * The descriptors of a queue form an array indexed by tag.
+ */
+struct tcmur_io_desc {
+ __u32 op;
+ __u32 flags;
+ __u64 offset;
+ __u64 len;
+ __u32 data_len;
+ __u32 reserved;
+};
+
+#endif /* _UAPI_LINUX_TARGET_CORE_URING_H */
--
2.43.0
next prev parent reply other threads:[~2026-11-16 0:18 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 ` Qiliang Yuan [this message]
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 ` [PATCH RFC 15/18] scsi: target: uring: Register command data as io_uring fixed buffers Qiliang Yuan
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-2-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