mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Hongjie Fang <hongjiefang@asrmicro.com>,
	alim.akhtar@samsung.com, avri.altman@wdc.com,
	James.Bottomley@HansenPartnership.com,
	martin.petersen@oracle.com, peter.wang@mediatek.com,
	beanhuo@micron.com
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] scsi: ufs: core: handle PM SSU timeout before SCSI EH
Date: Fri, 29 May 2026 14:45:44 -0700	[thread overview]
Message-ID: <88ffd4c6-798c-4e0a-ba72-a3b3a027c39d@acm.org> (raw)
In-Reply-To: <20260528113433.367083-1-hongjiefang@asrmicro.com>

On 5/28/26 4:34 AM, Hongjie Fang wrote:
> @@ -9465,23 +9498,30 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
>   static enum scsi_timeout_action ufshcd_eh_timed_out(struct scsi_cmnd *scmd)
>   {
>   	struct ufs_hba *hba = shost_priv(scmd->device->host);
> +	int ret;
>   
> -	if (!hba->system_suspending) {
> +	if (!hba->pm_op_in_progress || scmd->device != hba->ufs_device_wlun ||
> +	    scmd->cmnd[0] != START_STOP) {
>   		/* Activate the error handler in the SCSI core. */
>   		return SCSI_EH_NOT_HANDLED;
>   	}

Please don't make the code any more complex than necessary. If a power 
management operation is in progress it is guaranteed that no other SCSI
commands are in progress. See also blk_pre_runtime_suspend() and
blk_try_enter_queue(). Hence, for the above if-condition, testing
hba->pm_op_in_progress is sufficient.

>   	/*
> -	 * If we get here we know that no TMFs are outstanding and also that
> -	 * the only pending command is a START STOP UNIT command. Handle the
> -	 * timeout of that command directly to prevent a deadlock between
> -	 * ufshcd_set_dev_pwr_mode() and ufshcd_err_handler().
> +	 * PM START STOP UNIT commands are issued while a PM operation is in
> +	 * progress. Handle such timeouts directly to avoid entering regular
> +	 * SCSI EH, which may deadlock with the PM operation and may also make
> +	 * scsi_execute_cmd() retries fail while the host is still in recovery.
>   	 */

The original comment is fine, isn't it?

> -	return scsi_host_busy(hba->host) ? SCSI_EH_RESET_TIMER : SCSI_EH_DONE;
> +	if (ret)
> +		return SCSI_EH_NOT_HANDLED;

This is wrong because it may activate the SCSI error handler for a START
STOP UNIT command. We don't want this - we want the error to be
propagated to the scsi_execute_cmd() caller.

> +	WARN_ON_ONCE(!test_bit(SCMD_STATE_COMPLETE, &scmd->state));

This is also wrong. According to Documentation/process/coding-style.rst,
WARN*() should only be used for this-should-never-happen situations. If
the above statement is reached it is almost a certainty that
SCMD_STATE_COMPLETE is not set.

The rest of this patch looks good to me.

Thanks,

Bart.

  reply	other threads:[~2026-05-29 21:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-28 11:34 Hongjie Fang
2026-05-29 21:45 ` Bart Van Assche [this message]
2026-05-30 11:26   ` Fang Hongjie(方洪杰)

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=88ffd4c6-798c-4e0a-ba72-a3b3a027c39d@acm.org \
    --to=bvanassche@acm.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=alim.akhtar@samsung.com \
    --cc=avri.altman@wdc.com \
    --cc=beanhuo@micron.com \
    --cc=hongjiefang@asrmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=peter.wang@mediatek.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

all inboxes | Powered by JetHome®