From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.13 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794788352; b=TwEsFQB25RbOVHe3ShxROdXUPTq1GpKLBK5NYSeg66POUzfEJKc3Fbfn8l+MKK5NHQ8f u4LqMYWmOa0ThdjGyZMPO59T8vuSxC6/K4czj6OtgStHNkgD3Yolcu0jHkFPg4ZtHNSrX SHjrswx5qobFrQGC/WJDJiMGvLOP8wQq0qk66O5Xd1Q9Han5wHVzkyPDIScoFvq0IdIUP fUCTa40nB+wLTsjft8kW0D1CxkQJ64oojDIPkkIivvz2JFltdBSDd7JZaffyrBfZS2tiG cR19+9EFpUdOkcffcTMhvlGu/eAsHhzOF2EG64SDO0RhCpJ5Ho1HsLRHLpsdJfWCGjQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794788352; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=qJUANPBrcmUXZH9q6jSZaPiBplp1K6wLWEwNFELnjHc=; b=JtfPEaaoLghmm04V0SeNQD4yRW3v6Hyi73qkEV39J2E1YHHQMtIdl+hiu0pfx3AAM2yL ZCd+F4KmweTtaaPC+BjM1tykQeV0e2pPlqXvuULO01cpF/zlbp3o44J1w8QqO6PJMImUB ZHjxVaQu7f1PwWU3jwDWrEipIkPSVT3IM8GJmVy66DEb99HGfibtLZ+AojlEU8X7VNWQo 3+ceL093/CZgJbLRdgQQsCeu2A3pjwMP5fn9HUOIEX+h8H6kQ2Pt0rXbv4/u+Yt8ZifrR fzMkmtwLMDk5/g0RosxeSWRQXAfSWlpiVd3K1ziBq8EbrSXzcl5NQrr/d3x/7L09RrA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=IPf8vUhi; arc=none smtp.remote-ip=91.218.175.13 Received: from mta0.migadu.com (out-13.mta0.migadu.com [91.218.175.13]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E695606A331 for ; Mon, 16 Nov 2026 00:19:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6E695606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=IPf8vUhi X-Envelope-To: linux-kselftest@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=rM6vS4HAjcmUGcm6Libw2HvbeosH2oHmDxlTZorpgpA=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794788349; v=1; x=1795393149; b=IPf8vUhi4/FBP7UUxW0m2AntbR2pvza2o00XTjEwRgG+X5+LECVZ3NXEZwyRElbxBd8v8UZ2 pIrCcffnsO4xLZPlzOiZwPF9umBW+eHjhph/dRkOQs5bV1YFeYYD7p6FKbHhNQDnwsvv3YasNLB 0pAPWosra1k8gtOJ+Reg9Y+c= X-Envelope-To: linux-kselftest@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id ba3022391c40b343; Mon, 16 Nov 2026 00:19:09 +0000 X-Mizu-Trace-ID: ba3022391c40b343 X-Migadu-Flow: FLOW_OUT From: Qiliang Yuan Date: Sun, 15 Nov 2026 19:18:01 -0500 Subject: [PATCH RFC 08/18] scsi: target: uring: Copy command data with pread() and pwrite() X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261115-feat-target-core-uring-v1-8-28cdc137eac6@linux.dev> References: <20261115-feat-target-core-uring-v1-0-28cdc137eac6@linux.dev> In-Reply-To: <20261115-feat-target-core-uring-v1-0-28cdc137eac6@linux.dev> To: "Martin K. Petersen" , Shuah Khan , Jonathan Corbet , Shuah Khan , Randy Dunlap 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 , io-uring@vger.kernel.org, Mike Christie , Bodo Stroesser , Ming Lei , Qiliang Yuan X-Mailer: b4 0.13.0 The server of a target_core_uring device fetches commands and commits their results. It has no access to the data of reads and writes. Let the server pwrite() the data of a read command and pread() the data of a write command on the character device, at a position that encodes the queue, the tag and the offset in the command. Copy straight between the pages of the command and the buffer of the server, so that the data is copied once. Hold a reference on the command during the copy, so that it does not complete underneath. 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 TCM/USER and a single-threaded handler, then with this backstore, 32 queues and one server thread per queue. Both servers keep the data in memory. A single job is slower; the gain comes with concurrency and with large I/O. Three alternating runs (median, min-max in parentheses): workload TCM/USER (MB/s) uring (MB/s) change 4k randread, 1 job 426 (409-463) 354 (348-378) -17% 4k randread, 4 jobs 1165 (1072-1253) 1466 (1451-1518) +26% 4k randread, 16 jobs 920 (916-1162) 6500 (6173-6769) +607% 4k randwrite, 16 jobs 793 (711-886) 6070 (5966-6216) +665% 1M read, 4 jobs 6019 (5857-6047) 47687 (32175-49464) +692% 1M write, 4 jobs 2791 (2649-2907) 28295 (27152-29050) +914% Signed-off-by: Qiliang Yuan --- drivers/target/target_core_uring.c | 89 +++++++++++++++++++++++++++++++++- include/uapi/linux/target_core_uring.h | 15 ++++++ 2 files changed, 103 insertions(+), 1 deletion(-) diff --git a/drivers/target/target_core_uring.c b/drivers/target/target_core_uring.c index 770bb665fbe00..3a6f8d25d28e5 100644 --- a/drivers/target/target_core_uring.c +++ b/drivers/target/target_core_uring.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,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 + * @ref: Held by the tag or the pending list and by data copies in + * progress * @status: SAM status to complete @se_cmd with */ struct tcmur_cmd { @@ -232,6 +234,26 @@ static sense_reason_t tcmur_execute_rw(struct se_cmd *se_cmd, se_cmd->data_length, sgl, sgl_nents); } +/* Take a reference on the command the server works on in (@q_id, @tag) */ +static struct tcmur_cmd *tcmur_get_cmd(struct tcmur_dev *udev, u16 q_id, + u16 tag) +{ + struct tcmur_cmd *tcmd; + struct tcmur_queue *q; + + if (q_id >= udev->nr_queues || tag >= udev->queue_depth) + return NULL; + + q = &udev->queues[q_id]; + spin_lock(&q->lock); + tcmd = q->ios[tag].cmd; + if (tcmd) + refcount_inc(&tcmd->ref); + spin_unlock(&q->lock); + + return tcmd; +} + static void tcmur_cancel_fetch(struct io_uring_cmd *ucmd, unsigned int issue_flags) { @@ -363,6 +385,69 @@ static int tcmur_ch_uring_cmd(struct io_uring_cmd *ucmd, return tcmur_ch_uring_cmd_local(ucmd, issue_flags); } +/* Copy between the data pages of a command and the buffer of the server */ +static ssize_t tcmur_ch_copy(struct kiocb *iocb, struct iov_iter *iter, + bool to_cmd) +{ + struct tcmur_dev *udev = iocb->ki_filp->private_data; + u32 off = iocb->ki_pos & TCMUR_BUF_OFF_MASK; + u16 tag = iocb->ki_pos >> TCMUR_BUF_TAG_SHIFT; + u16 q_id = iocb->ki_pos >> TCMUR_BUF_QID_SHIFT; + size_t count, n, copied; + struct tcmur_cmd *tcmd; + struct scatterlist *sg; + ssize_t done = 0; + int i; + + tcmd = tcmur_get_cmd(udev, q_id, tag); + if (!tcmd) + return -EINVAL; + + if (to_cmd != (tcmd->desc.op == TCMUR_OP_READ) || + off > tcmd->desc.data_len) { + done = -EINVAL; + goto put_cmd; + } + + count = min(iov_iter_count(iter), tcmd->desc.data_len - off); + for_each_sg(tcmd->sgl, sg, tcmd->sgl_nents, i) { + if (!count) + break; + if (off >= sg->length) { + off -= sg->length; + continue; + } + + n = min(sg->length - off, count); + if (to_cmd) + copied = copy_page_from_iter(sg_page(sg), + sg->offset + off, n, iter); + else + copied = copy_page_to_iter(sg_page(sg), + sg->offset + off, n, iter); + done += copied; + count -= copied; + if (copied != n) + break; + off = 0; + } + if (!done && count) + done = -EFAULT; +put_cmd: + tcmur_cmd_put(tcmd); + return done; +} + +static ssize_t tcmur_ch_read_iter(struct kiocb *iocb, struct iov_iter *to) +{ + return tcmur_ch_copy(iocb, to, false); +} + +static ssize_t tcmur_ch_write_iter(struct kiocb *iocb, struct iov_iter *from) +{ + return tcmur_ch_copy(iocb, from, true); +} + static size_t tcmur_desc_area_size(struct tcmur_dev *udev) { return PAGE_ALIGN(udev->queue_depth * sizeof(struct tcmur_io_desc)); @@ -433,6 +518,8 @@ static const struct file_operations tcmur_ch_fops = { .owner = THIS_MODULE, .open = tcmur_ch_open, .release = tcmur_ch_release, + .read_iter = tcmur_ch_read_iter, + .write_iter = tcmur_ch_write_iter, .uring_cmd = tcmur_ch_uring_cmd, .mmap = tcmur_ch_mmap, .unlocked_ioctl = tcmur_ch_ioctl, diff --git a/include/uapi/linux/target_core_uring.h b/include/uapi/linux/target_core_uring.h index a662a23fca9ab..8b95be853753c 100644 --- a/include/uapi/linux/target_core_uring.h +++ b/include/uapi/linux/target_core_uring.h @@ -96,4 +96,19 @@ struct tcmur_io_desc { #define TCMUR_DESC_AREA_SIZE \ (TCMUR_MAX_QUEUE_DEPTH * sizeof(struct tcmur_io_desc)) +/* + * The data of a command is read (TCMUR_OP_WRITE) or written + * (TCMUR_OP_READ) with pread()/pwrite() on the file, at the position + * returned by tcmur_buf_pos(). + */ +#define TCMUR_BUF_TAG_SHIFT 32 +#define TCMUR_BUF_QID_SHIFT 48 +#define TCMUR_BUF_OFF_MASK ((1ULL << TCMUR_BUF_TAG_SHIFT) - 1) + +static inline __u64 tcmur_buf_pos(__u16 q_id, __u16 tag, __u32 off) +{ + return ((__u64)q_id << TCMUR_BUF_QID_SHIFT) | + ((__u64)tag << TCMUR_BUF_TAG_SHIFT) | off; +} + #endif /* _UAPI_LINUX_TARGET_CORE_URING_H */ -- 2.43.0