From: Bart Van Assche <bvanassche@acm.org>
Date: Fri, 3 Dec 2021 15:19:48 -0800
Subject: scsi: ufs: Stop using the clock scaling lock in the error handler
Git-commit: 5675c381ea51360b4968b78f23aefda73e3de90d
Patch-mainline: v5.17-rc1
References: git-fixes
Instead of locking and unlocking the clock scaling lock, surround the
command queueing code with an RCU reader lock and call synchronize_rcu().
This patch prepares for removal of the clock scaling lock.
[lduncan: refreshed to apply.]
Link: https://lore.kernel.org/r/20211203231950.193369-16-bvanassche@acm.org
Tested-by: Bean Huo <beanhuo@micron.com>
Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Acked-by: Lee Duncan <lduncan@suse.com>
---
drivers/scsi/ufs/ufshcd.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -2717,6 +2717,12 @@ static int ufshcd_queuecommand(struct Sc
if (!down_read_trylock(&hba->clk_scaling_lock))
return SCSI_MLQUEUE_HOST_BUSY;
+ /*
+ * Allows the UFS error handler to wait for prior ufshcd_queuecommand()
+ * calls.
+ */
+ rcu_read_lock();
+
switch (hba->ufshcd_state) {
case UFSHCD_STATE_OPERATIONAL:
case UFSHCD_STATE_EH_SCHEDULED_NON_FATAL:
@@ -2789,7 +2795,10 @@ static int ufshcd_queuecommand(struct Sc
wmb();
ufshcd_send_command(hba, tag);
+
out:
+ rcu_read_unlock();
+
up_read(&hba->clk_scaling_lock);
return err;
}
@@ -5929,8 +5938,7 @@ static void ufshcd_err_handling_prepare(
}
ufshcd_scsi_block_requests(hba);
/* Drain ufshcd_queuecommand() */
- down_write(&hba->clk_scaling_lock);
- up_write(&hba->clk_scaling_lock);
+ synchronize_rcu();
cancel_work_sync(&hba->eeh_work);
}