Linux SCSI subsystem development
 help / color / mirror / Atom feed
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 11/18] scsi: target: uring: Drop aborted commands that are still queued
Date: Mon, 16 Nov 2026 00:37:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-215958@kernel.org> (raw)
In-Reply-To: <20261115-feat-target-core-uring-v1-11-28cdc137eac6@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] scsi: target: uring: missing CMD_T_ABORTED check in
  tcmur_queue_cmd()
--

commit 84783430b27d7a40ed74a32ae69a8126b2da14ae
Author: Qiliang Yuan <qiliang.yuan@linux.dev>

scsi: target: uring: Drop aborted commands that are still queued

This commit implements tmr_notify() for target_core_uring so that aborted
commands still waiting on a queue's pending list are removed and completed
immediately with SAM_STAT_TASK_ABORTED instead of waiting to time out.

> diff --git a/drivers/target/target_core_uring.c b/drivers/target/target_core_uring.c
> index 0f83bdc55e06a..629419a4c8f46 100644
> --- a/drivers/target/target_core_uring.c
> +++ b/drivers/target/target_core_uring.c
[ ... ]
> @@ -207,6 +208,7 @@ static void tcmur_queue_cmd(struct tcmur_dev *udev, struct tcmur_cmd *tcmd)
>  		io->ucmd = NULL;
>  		tcmur_io_start(q, io, tcmd);
>  	} else {
> +		tcmd->se_cmd->priv = tcmd;
>  		list_add_tail(&tcmd->node, &q->pending);
>  	}
>  	spin_unlock(&q->lock);
> @@ -255,6 +257,31 @@ static sense_reason_t tcmur_execute_rw(struct se_cmd *se_cmd,
>  			    se_cmd->data_length, sgl, sgl_nents);
>  }
>  
> +static void tcmur_tmr_notify(struct se_device *dev, enum tcm_tmreq_table tmf,
> +			     struct list_head *aborted_cmds)
> +{
> +	struct tcmur_dev *udev = TCMUR_DEV(dev);
> +	struct tcmur_cmd *tcmd;
> +	struct tcmur_queue *q;
> +	struct se_cmd *se_cmd;
> +
> +	/* Drop the aborted commands that no server has picked up yet */
> +	list_for_each_entry(se_cmd, aborted_cmds, state_list) {
> +		q = tcmur_cmd_queue(udev, se_cmd);
> +
> +		spin_lock(&q->lock);
> +		tcmd = se_cmd->priv;
> +		if (tcmd) {
> +			se_cmd->priv = NULL;
> +			list_del(&tcmd->node);
> +		}
> +		spin_unlock(&q->lock);
> +
> +		if (tcmd)
> +			tcmur_cmd_end(tcmd, SAM_STAT_TASK_ABORTED);
> +	}
> +}

[Severity: High]
Can tcmur_queue_cmd() queue a command onto q->pending after
tcmur_tmr_notify() has already run for it?

transport_generic_new_cmd() places se_cmd on state_list before the command
reaches tcmur_queue_cmd():

CPU0                                    CPU1
transport_generic_new_cmd()
  target_add_to_state_list(se_cmd)
  target_execute_cmd(se_cmd)
    ...
                                        core_tmr_abort_task()
                                          __target_check_io_state()
                                            se_cmd->transport_state |=
                                              CMD_T_ABORTED
                                            list_move_tail(..., &aborted)
                                          tcmur_tmr_notify()
                                            spin_lock(&q->lock)
                                            tcmd = se_cmd->priv  <-- NULL
                                            spin_unlock(&q->lock)
      tcmur_queue_cmd()
        spin_lock(&q->lock)
        tcmd->se_cmd->priv = tcmd
        list_add_tail(&tcmd->node,
                      &q->pending)      <-- queued after tmr_notify()
        spin_unlock(&q->lock)
                                          target_put_cmd_and_wait()

The same ordering also happens without a narrow race when a command on
dev->delayed_cmd_list is aborted while se_cmd->priv is still NULL and is
later dispatched by target_do_delayed_work() -> __target_execute_cmd().

Once tcmd is placed on q->pending after tcmur_tmr_notify() finishes,
se_cmd is no longer on state_list, so nothing removes tcmd if no server
fetches it.  target_put_cmd_and_wait() then blocks for up to cmd_timeout
seconds, or hangs indefinitely when cmd_time_out is 0.

Should tcmur_queue_cmd() check se_cmd->transport_state & CMD_T_ABORTED
under q->lock before starting or queueing tcmd, similar to
tcmu_queue_cmd() in target_core_user.c?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261115-feat-target-core-uring-v1-0-28cdc137eac6@linux.dev?part=11

  reply	other threads:[~2026-11-16  0:37 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 [this message]
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=sashiko-outbox-215958@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