Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Can Guo" <can.guo@oss.qualcomm.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4 06/12] scsi: ufs: core: Add helpers to pause and resume command processing
Date: Thu, 13 Aug 2026 22:29:49 +0000	[thread overview]
Message-ID: <20260813222950.8C1581F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260321031021.1722459-7-can.guo@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] AB-BA deadlock between block layer tagset quiesce and clk_scaling_lock during concurrent device management commands.
- [High] Missing ufshcd_hold() allows concurrent UIC commands and Hibern8 transitions from the clock gating worker.
- [High] Incomplete quiescence allows BSG and TMF commands to disrupt hardware state during paused operations.
--

--- Patch [6]: [PATCH v4 06/12] scsi: ufs: core: Add helpers to pause and resume command processing ---
commit fb401ec0f2366dbaa8f0c8881fcde7ff615bb4d2
Author: Can Guo <can.guo@oss.qualcomm.com>

scsi: ufs: core: Add helpers to pause and resume command processing

In preparation for supporting TX Equalization refreshing, introduce helper
functions to safely pause and resume command processing.
ufshcd_pause_command_processing() ensures the host is in a quiescent state,
and ufshcd_resume_command_processing() restores it.

> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index b2050281f3f89..71bda9dd60729 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
[ ... ]
> @@ -1364,6 +1364,48 @@ static int ufshcd_wait_for_pending_cmds(struct ufs_hba *hba,
>  	return ret;
>  }
>  
> +/**
> + * ufshcd_pause_command_processing - Pause command processing
> + * @hba: per-adapter instance
> + * @timeout_us: timeout in microseconds to wait for pending commands to finish
> + *
> + * This function stops new command submissions and waits for existing commands
> + * to complete.
> + *
> + * Return: 0 on success, %-EBUSY if commands did not finish within @timeout_us.
> + * On failure, all acquired locks are released and the tagset is unquiesced.
> + */
> +int ufshcd_pause_command_processing(struct ufs_hba *hba, u64 timeout_us)
> +{
> +	int ret = 0;
> +
> +	mutex_lock(&hba->host->scan_mutex);
> +	blk_mq_quiesce_tagset(&hba->host->tag_set);

[Severity: High]
Does quiescing only the SCSI host tagset leave the independent Task Management
(hba->tmf_queue) and BSG (hba->bsg_queue) queues active?

A userspace application could concurrently issue operations via the BSG device
node, bypassing the scan_mutex and clk_scaling_lock, and write directly to
hardware doorbell registers (REG_UTP_TASK_REQ_DOOR_BELL and REG_UIC_COMMAND)
while the controller is undergoing maintenance.

> +	down_write(&hba->clk_scaling_lock);

[Severity: High]
Does quiescing the tagset before waiting on clk_scaling_lock create an AB-BA
deadlock with concurrent device management commands?

If a concurrent device management operation calls ufshcd_dev_man_lock() and
acquires down_read(&hba->clk_scaling_lock), it then submits a request to the
pseudo_sdev via blk_execute_rq(). 

Because the pseudo_sdev shares the SCSI host tagset which was just quiesced
above, the request is queued but never dispatched. Since it is never
dispatched, the block layer timeout timer never starts. The management
operation waits infinitely in wait_for_completion() holding the
clk_scaling_lock, while this pause function waits infinitely here for the
same lock.

> +
> +	if (ufshcd_wait_for_pending_cmds(hba, timeout_us)) {
> +		ret = -EBUSY;
> +		up_write(&hba->clk_scaling_lock);
> +		blk_mq_unquiesce_tagset(&hba->host->tag_set);
> +		mutex_unlock(&hba->host->scan_mutex);
> +	}
> +
> +	return ret;

[Severity: High]
If this function successfully returns without bumping the PM usage counter
(e.g., via ufshcd_hold()), couldn't the asynchronous ufshcd_gate_work fire?

Once pending SCSI commands complete, the queue becomes idle and active_reqs
drops to zero. This allows the clock gating worker to put the link into
Hibern8 mode and disable clocks, which could disrupt the caller of this pause
function if it attempts low-level PHY operations assuming the link is fully
active.

> +}
> +
> +/**
> + * ufshcd_resume_command_processing - Resume command processing
> + * @hba: per-adapter instance
> + *
> + * This function resumes command submissions.
> + */
> +void ufshcd_resume_command_processing(struct ufs_hba *hba)
> +{
> +	up_write(&hba->clk_scaling_lock);
> +	blk_mq_unquiesce_tagset(&hba->host->tag_set);
> +	mutex_unlock(&hba->host->scan_mutex);

[Severity: High]
If ufshcd_hold() is added to ufshcd_pause_command_processing(), would a
matching ufshcd_release() be needed here to restore normal clock gating?

> +}
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260321031021.1722459-1-can.guo@oss.qualcomm.com?part=6

  parent reply	other threads:[~2026-08-13 22:29 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-21  3:10 [PATCH v4 00/12] scsi: ufs: Add TX Equalization support for UFS 5.0 Can Guo
2026-03-21  3:10 ` [PATCH v4 01/12] scsi: ufs: core: Introduce a new ufshcd vops negotiate_pwr_mode() Can Guo
2026-03-23  9:10   ` Bean Huo
2026-03-21  3:10 ` [PATCH v4 02/12] scsi: ufs: core: Pass force_pmc to ufshcd_config_pwr_mode() as a parameter Can Guo
2026-03-23  9:11   ` Bean Huo
2026-03-21  3:10 ` [PATCH v4 03/12] scsi: ufs: core: Add UFS_HS_G6 and UFS_HS_GEAR_MAX to enum ufs_hs_gear_tag Can Guo
2026-03-23  9:11   ` Bean Huo
2026-03-21  3:10 ` [PATCH v4 04/12] scsi: ufs: core: Add support for TX Equalization Can Guo
2026-03-22  9:48   ` Bean Huo
2026-03-22 14:26     ` Bean Huo
2026-03-23  6:05       ` Can Guo
2026-03-23  9:15   ` Bean Huo
2026-03-24  7:46   ` Peter Wang (王信友)
2026-03-24 10:09     ` Can Guo
2026-03-24 11:54       ` Peter Wang (王信友)
2026-03-24 12:32         ` Can Guo
2026-03-21  3:10 ` [PATCH v4 05/12] scsi: ufs: core: Add debugfs entries for TX Equalization params Can Guo
2026-03-23  9:16   ` Bean Huo
2026-03-21  3:10 ` [PATCH v4 06/12] scsi: ufs: core: Add helpers to pause and resume command processing Can Guo
2026-03-23  9:17   ` Bean Huo
2026-08-13 22:29   ` sashiko-bot [this message]
2026-03-21  3:10 ` [PATCH v4 07/12] scsi: ufs: core: Add support to retrain TX Equalization via debugfs Can Guo
2026-03-22 13:36   ` Bean Huo
2026-03-23  6:13     ` Can Guo
2026-03-23  9:21   ` Bean Huo
2026-03-21  3:10 ` [PATCH v4 08/12] scsi: ufs: ufs-qcom: Fixup PAM-4 TX L0_L1_L2_L3 adaptation pattern length Can Guo
2026-03-23  9:22   ` Bean Huo
2026-03-21  3:10 ` [PATCH v4 09/12] scsi: ufs: ufs-qcom: Implement vops tx_eqtr_notify() Can Guo
2026-03-23  9:23   ` Bean Huo
2026-03-21  3:10 ` [PATCH v4 10/12] scsi: ufs: ufs-qcom: Implement vops get_rx_fom() Can Guo
2026-03-23  9:24   ` Bean Huo
2026-03-21  3:10 ` [PATCH v4 11/12] scsi: ufs: ufs-qcom: Implement vops apply_tx_eqtr_settings() Can Guo
2026-03-23  9:24   ` Bean Huo
2026-03-21  3:10 ` [PATCH v4 12/12] scsi: ufs: ufs-qcom: Enable TX Equalization Can Guo
2026-03-23  9:25   ` Bean Huo
2026-03-23 16:50 ` [PATCH v4 00/12] scsi: ufs: Add TX Equalization support for UFS 5.0 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=20260813222950.8C1581F00A3E@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=can.guo@oss.qualcomm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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