From: sashiko-bot@kernel.org
To: "Qiliang Yuan" <qiliang.yuan@linux.dev>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Subject: Re: [PATCH RFC 16/18] selftests: target_core_uring: Add a minimal server
Date: Mon, 16 Nov 2026 01:03:54 +0000 [thread overview]
Message-ID: <sashiko-outbox-215986@kernel.org> (raw)
In-Reply-To: <20261115-feat-target-core-uring-v1-16-28cdc137eac6@linux.dev>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] selftests: target_core_uring: missing FUA sync in zero-copy
handle()
- [Medium] selftests: target_core_uring: tag leak on UD_REG failure in
queue_fn()
- [Medium] selftests: target_core_uring: commit before UD_UNREG in
queue_fn()
- [Medium] selftests: target_core_uring: 32-bit off_t truncation in
copy_data()
- [Low] selftests: target_core_uring: 0-length I/O passed to
start_zero_copy()
- [Low] selftests: target_core_uring: perror() after liburing calls in
queue_fn()
- [Low] selftests: target_core_uring: unchecked calloc() for queues in
main()
--
commit a8d885b7b600468b558a9ffcad7e5d1e7afa97ce
Author: Qiliang Yuan <qiliang.yuan@linux.dev>
selftests: target_core_uring: Add a minimal server
This commit adds tcmur_server, a minimal userspace server for
target_core_uring devices supporting null, RAM, and file backends with
optional zero-copy fixed-buffer I/O.
> diff --git a/tools/testing/selftests/target_core_uring/Makefile b/tools/testing/selftests/target_core_uring/Makefile
> new file mode 100644
> index 0000000000000..438628fd1606b
> --- /dev/null
> +++ b/tools/testing/selftests/target_core_uring/Makefile
> @@ -0,0 +1,7 @@
> +# SPDX-License-Identifier: GPL-2.0
> +CFLAGS += -O2 -Wall -D_GNU_SOURCE $(KHDR_INCLUDES)
> +LDLIBS += -luring -lpthread
> +
> +TEST_GEN_PROGS_EXTENDED := tcmur_server
> +
> +include ../lib.mk
> diff --git a/tools/testing/selftests/target_core_uring/tcmur_server.c b/tools/testing/selftests/target_core_uring/tcmur_server.c
> new file mode 100644
> index 0000000000000..128a0021e7796
> --- /dev/null
> +++ b/tools/testing/selftests/target_core_uring/tcmur_server.c
[ ... ]
> +static int copy_data(struct queue *q, int tag, void *buf, uint32_t len,
> + bool to_cmd)
> +{
> + uint64_t pos = tcmur_buf_pos(q->q_id, tag, 0);
> + ssize_t ret;
> +
> + if (to_cmd)
> + ret = pwrite(dev_fd, buf, len, pos);
> + else
> + ret = pread(dev_fd, buf, len, pos);
> + return ret == len ? 0 : -EIO;
> +}
[Severity: Medium]
Does passing pos to pread() and pwrite() truncate the upper 32 bits on
32-bit architectures?
tcmur_buf_pos() encodes q_id in bits 48..63 and tag in bits 32..47, but
neither the Makefile nor tcmur_server.c defines _FILE_OFFSET_BITS=64, so
off_t is 32-bit on 32-bit targets and every non-zero q_id or tag is lost.
Also, passing -D_GNU_SOURCE in the Makefile conflicts with -D_GNU_SOURCE=
in ../lib.mk, triggering a macro redefinition warning during the build.
[ ... ]
> +/* Start the I/O on the data pages of the command, without copying them */
> +static void start_zero_copy(struct queue *q, int tag, struct tcmur_io_desc *d)
> +{
> + struct io_uring_sqe *sqe;
> +
> + sqe = prep_cmd(q, TCMUR_IO_REGISTER_BUF, tag, 0, UD_REG);
> + sqe->flags |= IOSQE_IO_LINK | IOSQE_CQE_SKIP_SUCCESS;
> +
> + sqe = get_sqe(q);
> + if (d->op == TCMUR_OP_READ)
> + io_uring_prep_read_fixed(sqe, backing_fd, NULL, d->data_len,
> + d->offset, tag);
> + else
> + io_uring_prep_write_fixed(sqe, backing_fd, NULL, d->data_len,
> + d->offset, tag);
> + sqe->flags |= IOSQE_IO_HARDLINK;
> + sqe->user_data = (uint64_t)UD_RW << 16 | tag;
> +
> + sqe = prep_cmd(q, TCMUR_IO_UNREGISTER_BUF, tag, 0, UD_UNREG);
> + sqe->flags |= IOSQE_CQE_SKIP_SUCCESS;
> +}
> +
> +/* Return true if the command completes later */
> +static bool handle(struct queue *q, int tag, int *result)
> +{
> + struct tcmur_io_desc *d = &q->descs[tag];
> + bool rd = d->op == TCMUR_OP_READ;
> + int ret = 0;
> +
> + switch (d->op) {
> + case TCMUR_OP_READ:
> + case TCMUR_OP_WRITE:
> + if (d->offset + d->len > info.dev_size) {
> + ret = -EINVAL;
> + } else if (backend == BACKEND_RAM) {
> + ret = copy_data(q, tag, ram + d->offset, d->data_len,
> + rd);
> + } else if (backend == BACKEND_FILE && zero_copy) {
> + start_zero_copy(q, tag, d);
> + return true;
> + }
[Severity: Low]
What happens in zero-copy mode when a valid 0-sector SCSI READ or WRITE
arrives with d->data_len == 0?
handle() still calls start_zero_copy(), which submits
TCMUR_IO_REGISTER_BUF, and tcmur_register_buf() in
drivers/target/target_core_uring.c rejects !tcmd->desc.data_len with
-EINVAL instead of completing the 0-length transfer with 0 as the non-zero-copy
paths do.
> + } else if (backend == BACKEND_FILE && rd) {
> + if (pread(backing_fd, q->buf, d->data_len, d->offset) !=
> + d->data_len)
> + ret = -EIO;
> + else
> + ret = copy_data(q, tag, q->buf, d->data_len,
> + true);
> + } else if (backend == BACKEND_FILE) {
> + ret = copy_data(q, tag, q->buf, d->data_len, false);
> + if (!ret && pwrite(backing_fd, q->buf, d->data_len,
> + d->offset) != d->data_len)
> + ret = -EIO;
> + }
> + if (!ret && backend == BACKEND_FILE &&
> + (d->flags & TCMUR_IO_F_FUA) && fdatasync(backing_fd))
> + ret = -errno;
> + break;
[Severity: Medium]
Does zero-copy mode ignore TCMUR_IO_F_FUA on writes?
When zero_copy is true, handle() returns early after start_zero_copy() and
skips the fdatasync(backing_fd) check above, while neither
start_zero_copy() (for instance via RWF_DSYNC on sqe->rw_flags) nor the
UD_RW completion path in queue_fn() syncs backing_fd before committing the
command.
[ ... ]
> +static void *queue_fn(void *arg)
> +{
> + struct io_uring_params p = {
> + .flags = IORING_SETUP_SINGLE_ISSUER | IORING_SETUP_DEFER_TASKRUN,
> + };
> + struct queue *q = arg;
> + struct io_uring_cqe *cqe;
> + unsigned int head, n;
> + int tag, kind, result;
> +
> + /* Create the ring here, as only its creator may submit to it */
> + if (io_uring_queue_init_params(info.queue_depth * 4, &q->ring, &p) ||
> + (zero_copy &&
> + io_uring_register_buffers_sparse(&q->ring, info.queue_depth))) {
> + perror("io_uring setup");
> + exit(1);
> + }
> +
> + for (tag = 0; tag < info.queue_depth; tag++)
> + prep_cmd(q, TCMUR_IO_FETCH, tag, 0, UD_FETCH);
> +
> + for (;;) {
> + if (io_uring_submit_and_wait(&q->ring, 1) < 0) {
> + perror("io_uring_submit_and_wait");
> + exit(1);
> + }
[Severity: Low]
Will perror() print a meaningful error after these liburing calls fail?
io_uring_queue_init_params(), io_uring_register_buffers_sparse(), and
io_uring_submit_and_wait() return negative errno values directly without
setting errno.
> +
> + n = 0;
> + io_uring_for_each_cqe(&q->ring, head, cqe) {
> + n++;
> + tag = cqe->user_data & 0xffff;
> + kind = cqe->user_data >> 16;
> +
> + switch (kind) {
> + case UD_FETCH:
> + if (cqe->res < 0)
> + goto out;
> + if (handle(q, tag, &result))
> + continue;
> + break;
> + case UD_RW:
> + result = cqe->res == q->descs[tag].data_len ?
> + 0 : -EIO;
> + break;
> + default:
> + /* Report failures through the I/O that follows */
> + continue;
> + }
[Severity: Medium]
If TCMUR_IO_REGISTER_BUF (UD_REG) fails, does this ignore the only CQE and
leak the tag?
In start_zero_copy(), UD_REG is submitted with
IOSQE_IO_LINK | IOSQE_CQE_SKIP_SUCCESS. When a request with
IOSQE_CQE_SKIP_SUCCESS fails and uses a soft link (IOSQE_IO_LINK),
req_set_fail() sets REQ_F_SKIP_LINK_CQES and io_fail_links() suppresses
CQEs for all subsequent linked requests (both UD_RW and UD_UNREG).
Because the default branch ignores the UD_REG error CQE waiting for a
UD_RW CQE that will never arrive, TCMUR_IO_COMMIT_AND_FETCH is never
issued for tag.
> + prep_cmd(q, TCMUR_IO_COMMIT_AND_FETCH, tag, result,
> + UD_FETCH);
> + }
[Severity: Medium]
Can submitting TCMUR_IO_COMMIT_AND_FETCH on the UD_RW CQE race ahead of
the linked TCMUR_IO_UNREGISTER_BUF (UD_UNREG) request?
In start_zero_copy(), UD_UNREG is linked after UD_RW with
IOSQE_CQE_SKIP_SUCCESS, so UD_RW's CQE is posted to the CQ ring before
UD_UNREG runs:
kernel queue_fn()
------ ----------
UD_RW completes (e.g. via io-wq)
posts UD_RW CQE to CQ ring
io_uring_submit_and_wait(..., 1)
reaps UD_RW CQE
prep_cmd(TCMUR_IO_COMMIT_AND_FETCH)
io_uring_submit_and_wait(..., 1)
__sys_io_uring_enter()
io_submit_sqes()
TCMUR_IO_COMMIT_AND_FETCH completes
fetches new command on same tag
reaps UD_FETCH CQE
start_zero_copy()
prep_cmd(TCMUR_IO_REGISTER_BUF)
io_kernel_buffer_init()
returns -EBUSY <-- slot tag still occupied before UD_UNREG runs
Because __sys_io_uring_enter() processes new SQEs before draining pending
local task_work (or while UD_UNREG is still queued from io-wq), the tag is
committed and reused while fixed-buffer slot tag is still registered.
Linking TCMUR_IO_COMMIT_AND_FETCH after UD_UNREG, or waiting for UD_UNREG
before committing, would avoid this ordering issue.
[ ... ]
> + desc_size = info.queue_depth * sizeof(struct tcmur_io_desc);
> + desc_size = (desc_size + getpagesize() - 1) & ~(getpagesize() - 1);
> + queues = calloc(info.nr_queues, sizeof(*queues));
> + for (i = 0; i < info.nr_queues; i++) {
> + struct queue *q = &queues[i];
> +
> + q->q_id = i;
[Severity: Low]
Can calloc() return NULL here and cause a NULL pointer dereference at
q->q_id = i?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261115-feat-target-core-uring-v1-0-28cdc137eac6@linux.dev?part=16
next prev parent reply other threads:[~2026-11-16 1:03 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 ` [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: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 [this message]
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=sashiko-outbox-215986@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=qiliang.yuan@linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=target-devel@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