linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stanley Jhu" <stanleyjhu@google.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 5/5] scsi: ufs: core: Clear stale UIC result byte before peer DME retries
Date: Thu, 15 Oct 2026 00:32:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-172056@kernel.org> (raw)
In-Reply-To: <20261015001855.3450573-6-stanleyjhu@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ufs: race in ufshcd_dispatch_uic_cmd() between retry and late interrupt
--

commit 2dc892f166dff54aa2e190ad9b52806532df339b
Author: Stanley Jhu <stanleyjhu@google.com>

scsi: ufs: core: Clear stale UIC result byte before peer DME retries

This commit clears the stale UIC result byte and restores argument3 when an
attempt fails before peer DME retries. This prevents a transient failure from
becoming a hard failure after retries due to uncleared error codes.

> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index bcc2512bf34b8..7532fd916bfd9 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -4400,9 +4400,12 @@ int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel,
>  	do {
>  		/* for peer attributes we retry upon failure */
>  		ret = ufshcd_send_uic_cmd(hba, &uic_cmd);
> -		if (ret)
> +		if (ret) {
>  			dev_dbg(hba->dev, "%s: attr-id 0x%x val 0x%x error code %d\n",
>  				set, UIC_GET_ATTR_ID(attr_sel), mib_val, ret);
> +			uic_cmd.argument2 &= ~MASK_UIC_COMMAND_RESULT;
> +			uic_cmd.argument3 = mib_val;
> +		}
>  	} while (ret && peer && --retries);

[Severity: High]
Can a retried UIC command be prematurely completed by a late interrupt from a
previous timed-out command?

If a call to ufshcd_send_uic_cmd() times out, the retry loop immediately
invokes it again. In ufshcd_dispatch_uic_cmd(), the new command is assigned
to hba->active_uic_cmd without holding the host_lock:

drivers/ufs/core/ufshcd.c:ufshcd_dispatch_uic_cmd() {
    ...
    hba->active_uic_cmd = uic_cmd;
    ...
}

If a late interrupt from the previously timed-out command fires right after
this assignment, the ISR will read the new command under host_lock and
complete it prematurely:

drivers/ufs/core/ufshcd.c:ufshcd_uic_cmd_compl() {
    ...
    guard(spinlock_irqsave)(&hba->host->host_lock);
    cmd = hba->active_uic_cmd;
    if (!cmd) {
    ...
}

This could lead to invalid configuration and potential controller
desynchronization, since the new command is completed using the old command's
result.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261015001855.3450573-1-stanleyjhu@google.com?part=5

  reply	other threads:[~2026-10-15  0:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  0:18 [PATCH v2 0/5] scsi: ufs: Fix UIC result byte and BSG request handling Stanley Jhu
2026-10-15  0:18 ` [PATCH v2 1/5] scsi: ufs: bsg: Complete the job on error Stanley Jhu
2026-10-15  0:32   ` sashiko-bot
2026-10-15  0:41     ` Stanley Jhu
2026-10-15  0:18 ` [PATCH v2 2/5] scsi: ufs: bsg: Clear the reply buffer before use Stanley Jhu
2026-10-15  0:34   ` sashiko-bot
2026-10-15  0:41     ` Stanley Jhu
2026-10-15  0:18 ` [PATCH v2 3/5] scsi: ufs: bsg: Validate request_len before accessing request Stanley Jhu
2026-10-15  0:18 ` [PATCH v2 4/5] scsi: ufs: bsg: Reject UIC commands with a non-zero result byte Stanley Jhu
2026-10-15  0:18 ` [PATCH v2 5/5] scsi: ufs: core: Clear stale UIC result byte before peer DME retries Stanley Jhu
2026-10-15  0:32   ` sashiko-bot [this message]
2026-10-15  0:43     ` Stanley Jhu
2026-10-15  4:39 ` [PATCH v2 0/5] scsi: ufs: Fix UIC result byte and BSG request handling Peter Wang
2026-10-15 17:53 ` Bart Van Assche

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-172056@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=stanleyjhu@google.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;
as well as URLs for NNTP newsgroup(s).