Skip to content

Commit 6fd53da

Browse files
ptr324martinkpetersen
authored andcommitted
scsi: ufs: core: Fix abnormal scale up after last cmd finish
When ufshcd_clk_scaling_suspend_work (thread A) running and new command coming, ufshcd_clk_scaling_start_busy (thread B) may get host_lock after thread A first time release host_lock. Then thread A second time get host_lock will set clk_scaling.window_start_t = 0 which scale up clock abnormal next polling_ms time. Also inlines another __ufshcd_suspend_clkscaling calls. Below is racing step: 1 hba->clk_scaling.suspend_work (Thread A) ufshcd_clk_scaling_suspend_work 2 spin_lock_irqsave(hba->host->host_lock, irq_flags); 3 hba->clk_scaling.is_suspended = true; 4 spin_unlock_irqrestore(hba->host->host_lock, irq_flags); __ufshcd_suspend_clkscaling 7 spin_lock_irqsave(hba->host->host_lock, flags); 8 hba->clk_scaling.window_start_t = 0; 9 spin_unlock_irqrestore(hba->host->host_lock, flags); ufshcd_send_command (Thread B) ufshcd_clk_scaling_start_busy 5 spin_lock_irqsave(hba->host->host_lock, flags); .... 6 spin_unlock_irqrestore(hba->host->host_lock, flags); Signed-off-by: Peter Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 1d96973 commit 6fd53da

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

drivers/ufs/core/ufshcd.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba);
274274
static int ufshcd_host_reset_and_restore(struct ufs_hba *hba);
275275
static void ufshcd_resume_clkscaling(struct ufs_hba *hba);
276276
static void ufshcd_suspend_clkscaling(struct ufs_hba *hba);
277-
static void __ufshcd_suspend_clkscaling(struct ufs_hba *hba);
278277
static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up);
279278
static irqreturn_t ufshcd_intr(int irq, void *__hba);
280279
static int ufshcd_change_power_mode(struct ufs_hba *hba,
@@ -1357,9 +1356,10 @@ static void ufshcd_clk_scaling_suspend_work(struct work_struct *work)
13571356
return;
13581357
}
13591358
hba->clk_scaling.is_suspended = true;
1359+
hba->clk_scaling.window_start_t = 0;
13601360
spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
13611361

1362-
__ufshcd_suspend_clkscaling(hba);
1362+
devfreq_suspend_device(hba->devfreq);
13631363
}
13641364

13651365
static void ufshcd_clk_scaling_resume_work(struct work_struct *work)
@@ -1536,16 +1536,6 @@ static void ufshcd_devfreq_remove(struct ufs_hba *hba)
15361536
dev_pm_opp_remove(hba->dev, clki->max_freq);
15371537
}
15381538

1539-
static void __ufshcd_suspend_clkscaling(struct ufs_hba *hba)
1540-
{
1541-
unsigned long flags;
1542-
1543-
devfreq_suspend_device(hba->devfreq);
1544-
spin_lock_irqsave(hba->host->host_lock, flags);
1545-
hba->clk_scaling.window_start_t = 0;
1546-
spin_unlock_irqrestore(hba->host->host_lock, flags);
1547-
}
1548-
15491539
static void ufshcd_suspend_clkscaling(struct ufs_hba *hba)
15501540
{
15511541
unsigned long flags;
@@ -1558,11 +1548,12 @@ static void ufshcd_suspend_clkscaling(struct ufs_hba *hba)
15581548
if (!hba->clk_scaling.is_suspended) {
15591549
suspend = true;
15601550
hba->clk_scaling.is_suspended = true;
1551+
hba->clk_scaling.window_start_t = 0;
15611552
}
15621553
spin_unlock_irqrestore(hba->host->host_lock, flags);
15631554

15641555
if (suspend)
1565-
__ufshcd_suspend_clkscaling(hba);
1556+
devfreq_suspend_device(hba->devfreq);
15661557
}
15671558

15681559
static void ufshcd_resume_clkscaling(struct ufs_hba *hba)

0 commit comments

Comments
 (0)