Linux SCSI subsystem development
 help / color / mirror / Atom feed
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 04/18] scsi: target: uring: Map the command descriptors into the server
Date: Sun, 15 Nov 2026 19:17:57 -0500	[thread overview]
Message-ID: <20261115-feat-target-core-uring-v1-4-28cdc137eac6@linux.dev> (raw)
In-Reply-To: <20261115-feat-target-core-uring-v1-0-28cdc137eac6@linux.dev>

Each queue of a target_core_uring device has an array of command
descriptors that the kernel fills.

The server cannot read the descriptors yet.

Let the server mmap() the descriptors of queue q_id at offset
q_id * TCMUR_DESC_AREA_SIZE of the character device. Refuse writable
mappings, as only the kernel writes descriptors.

Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
 drivers/target/target_core_uring.c     | 22 +++++++++++++++++++++-
 include/uapi/linux/target_core_uring.h |  6 +++++-
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/drivers/target/target_core_uring.c b/drivers/target/target_core_uring.c
index d1ca4f16e7d0b..904ce2a613618 100644
--- a/drivers/target/target_core_uring.c
+++ b/drivers/target/target_core_uring.c
@@ -31,7 +31,7 @@ struct tcmur_dev;
 
 /**
  * struct tcmur_queue - One command queue
- * @descs:	Command descriptors, indexed by tag
+ * @descs:	Command descriptors, indexed by tag and mapped by the server
  * @udev:	Device the queue belongs to
  */
 struct tcmur_queue {
@@ -79,6 +79,25 @@ static size_t tcmur_desc_area_size(struct tcmur_dev *udev)
 	return PAGE_ALIGN(udev->queue_depth * sizeof(struct tcmur_io_desc));
 }
 
+static int tcmur_ch_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+	struct tcmur_dev *udev = filp->private_data;
+	u64 off = (u64)vma->vm_pgoff << PAGE_SHIFT;
+	u32 rem;
+	u64 q_id = div_u64_rem(off, TCMUR_DESC_AREA_SIZE, &rem);
+
+	if (rem || q_id >= udev->nr_queues ||
+	    vma->vm_end - vma->vm_start != tcmur_desc_area_size(udev))
+		return -EINVAL;
+
+	/* Refuse writable mappings, as only the kernel writes descriptors */
+	if (vma->vm_flags & VM_WRITE)
+		return -EPERM;
+	vm_flags_clear(vma, VM_MAYWRITE);
+
+	return remap_vmalloc_range(vma, udev->queues[q_id].descs, 0);
+}
+
 static long tcmur_ch_ioctl(struct file *filp, unsigned int cmd,
 			   unsigned long arg)
 {
@@ -125,6 +144,7 @@ static const struct file_operations tcmur_ch_fops = {
 	.owner		= THIS_MODULE,
 	.open		= tcmur_ch_open,
 	.release	= tcmur_ch_release,
+	.mmap		= tcmur_ch_mmap,
 	.unlocked_ioctl	= tcmur_ch_ioctl,
 	.compat_ioctl	= compat_ptr_ioctl,
 };
diff --git a/include/uapi/linux/target_core_uring.h b/include/uapi/linux/target_core_uring.h
index c23e01e7638a2..d2b8ffe40bf7a 100644
--- a/include/uapi/linux/target_core_uring.h
+++ b/include/uapi/linux/target_core_uring.h
@@ -54,7 +54,8 @@ enum tcmur_io_op {
  * @data_len:	Bytes of data to transfer
  * @reserved:	Zero
  *
- * The descriptors of a queue form an array indexed by tag.
+ * The descriptors of a queue form an array indexed by tag, which the server
+ * maps read-only at offset q_id * TCMUR_DESC_AREA_SIZE of the file.
  */
 struct tcmur_io_desc {
 	__u32	op;
@@ -65,4 +66,7 @@ struct tcmur_io_desc {
 	__u32	reserved;
 };
 
+#define TCMUR_DESC_AREA_SIZE \
+	(TCMUR_MAX_QUEUE_DEPTH * sizeof(struct tcmur_io_desc))
+
 #endif /* _UAPI_LINUX_TARGET_CORE_URING_H */

-- 
2.43.0


  parent reply	other threads:[~2026-11-16  0:18 UTC|newest]

Thread overview: 29+ 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:38   ` sashiko-bot
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:33   ` sashiko-bot
2026-11-16  0:17 ` Qiliang Yuan [this message]
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:46   ` sashiko-bot
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:41   ` sashiko-bot
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:37   ` sashiko-bot
2026-11-16  0:18 ` [PATCH RFC 12/18] scsi: target: uring: Support SYNCHRONIZE CACHE Qiliang Yuan
2026-11-16  0:40   ` sashiko-bot
2026-11-16  0:18 ` [PATCH RFC 13/18] scsi: target: uring: Implement UNMAP Qiliang Yuan
2026-11-16  0:45   ` sashiko-bot
2026-11-16  0:18 ` [PATCH RFC 14/18] scsi: target: uring: Handle WRITE SAME Qiliang Yuan
2026-11-16  0:44   ` sashiko-bot
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  1:03   ` sashiko-bot
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:49   ` sashiko-bot
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-4-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