Skip to contentSkip to conversation

scsi: ufs: fixup active period of ufshcd interrupt

PATCH Applied Stanley Chu 4 participants 9 messages Dec 7, 2019 – Dec 19, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover scsi: ufs: fixup active period of ufshcd interrupt

This patchset fixes up active duration of ufshcd interrupt to avoid potential system hang issues.

Stanley Chu (2):
scsi: ufs: disable irq before disabling clocks
scsi: ufs: disable interrupt during clock-gating

 drivers/scsi/ufs/ufshcd.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/2 scsi: ufs: disable irq before disabling clocks

During suspend flow, interrupt shall be disabled before disabling clocks to avoid potential system hang due to accessing host registers after host clocks are disabled.

For example, if an interrupt comes with IRQF_IRQPOLL flag configured with the misrouted interrupt recovery feature enabled, ufshcd ISR may be triggered even if nothing shall be done for UFS. In this case, system hang may happen if UFS interrupt status register is accessed with host clocks disabled.

---
 drivers/scsi/ufs/ufshcd.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/scsi/ufs/ufshcd.c +6 -5
index b5966faf3e98..f80bd4e811cb 100644
@@ -7908,6 +7908,11 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 	ret = ufshcd_vops_suspend(hba, pm_op);
 	if (ret)
 		goto set_link_active;
+	/*
+	 * Disable the host irq as host controller as there won't be any
+	 * host controller transaction expected till resume.
+	 */
+	ufshcd_disable_irq(hba);
 
 	if (!ufshcd_is_link_active(hba))
 		ufshcd_setup_clocks(hba, false);
@@ -7917,11 +7922,7 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 
 	hba->clk_gating.state = CLKS_OFF;
 	trace_ufshcd_clk_gating(dev_name(hba->dev), hba->clk_gating.state);
-	/*
-	 * Disable the host irq as host controller as there won't be any
-	 * host controller transaction expected till resume.
-	 */
-	ufshcd_disable_irq(hba);
+
 	/* Put the host controller in low power mode if possible */
 	ufshcd_hba_vreg_set_lpm(hba);
 	goto out;
Signature · 1 line
2.18.0
#2 lore raw

PATCH 2/2 scsi: ufs: disable interrupt during clock-gating

In reply to Stanley Chu

Similar to suspend, ufshcd interrupt can be disabled since there won't be any host controller transaction expected till clocks ungated.

---
 drivers/scsi/ufs/ufshcd.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/scsi/ufs/ufshcd.c +4 -0
index f80bd4e811cb..5de105e82c32 100644
@@ -1490,6 +1490,8 @@ static void ufshcd_ungate_work(struct work_struct *work)
 	spin_unlock_irqrestore(hba->host->host_lock, flags);
 	ufshcd_setup_clocks(hba, true);
 
+	ufshcd_enable_irq(hba);
+
 	/* Exit from hibern8 */
 	if (ufshcd_can_hibern8_during_gating(hba)) {
 		/* Prevent gating in this path */
@@ -1636,6 +1638,8 @@ static void ufshcd_gate_work(struct work_struct *work)
 		ufshcd_set_link_hibern8(hba);
 	}
 
+	ufshcd_disable_irq(hba);
+
 	if (!ufshcd_is_link_active(hba))
 		ufshcd_setup_clocks(hba, false);
 	else
Signature · 1 line
2.18.0
#3 lore raw

Re: [PATCH v1 2/2] scsi: ufs: disable interrupt during clock-gating

Quoted 24 lines · Stanley Chu

Similar to suspend, ufshcd interrupt can be disabled since there won't be any host controller transaction expected till clocks ungated.

---
  drivers/scsi/ufs/ufshcd.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/scsi/ufs/ufshcd.c +2 -0
index f80bd4e811cb..5de105e82c32 100644
@@ -1490,6 +1490,8 @@ static void ufshcd_ungate_work(struct work_struct *work)
  	spin_unlock_irqrestore(hba->host->host_lock, flags);
  	ufshcd_setup_clocks(hba, true);
 
+	ufshcd_enable_irq(hba);
+
  	/* Exit from hibern8 */
  	if (ufshcd_can_hibern8_during_gating(hba)) {
  		/* Prevent gating in this path */

drivers/scsi/ufs/ufshcd.c static void ufshcd_gate_work(struct work_struct *work) · line 1645

Quoted 8 lines
drivers/scsi/ufs/ufshcd.c +2 -0
@@ -1636,6 +1638,8 @@ static void ufshcd_gate_work(struct work_struct *work)
  		ufshcd_set_link_hibern8(hba);
  	}
 
+	ufshcd_disable_irq(hba);
+
  	if (!ufshcd_is_link_active(hba))
  		ufshcd_setup_clocks(hba, false);
  	else

Hi,
Does this save significant power? I see that gate/ungate of clocks happen far too frequently than suspend/resume.

Have you considered how much latency this would add to the gating/ungating path?

-asd

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
Linux Foundation Collaborative Project
#4 lore raw

Re: [PATCH v1 2/2] scsi: ufs: disable interrupt during clock-gating

Hi Asutosh,

Quoted 11 lines · Asutosh Das (asd)
Quoted 1 line

Hi,
Does this save significant power? I see that gate/ungate of clocks happen far too frequently than suspend/resume.

Have you considered how much latency this would add to the gating/ungating path?

-asd

Yes, we have measured 200 times clk-gating/clk-ungating and latency data is showed as below,

For clk-gating with interrupt disabling toggled,

Average latency of each clk-gating: 55.117 us Average latency of irq-disabling during clk-gating: 4.2 us

For clk-ungating with interrupt enabling toggled,
Average latency of each clk-ungating: 118.324 us Average latency of irq-enabling during clk-ungating: 2.9 us

The evaluation here is based on below Can's patch therefore the interrupt control (enable_irq/disable_irq) latency is much shorter than before (request_irq/free_irq).

scsi: ufs: Do not free irq in suspend
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/scsi/ufs/ufshcd.c?id=8709c1f68536e256668812788af5b2bb027f49c3

BTW, the main purpose of this patch is aimed to protect ufshcd register from accessing while host clocks are disabled to fix potential system hang issue. The possible scenario is mentioned in commit message of patch "scsi: ufs: disable irq before disabling clocks" in the same series.

Thanks
Stanley

Reviewed-by
#5 lore raw

Re: [PATCH v1 2/2] scsi: ufs: disable interrupt during clock-gating

Quoted 34 lines · Stanley Chu

Hi Asutosh,

Quoted 11 lines · Asutosh Das (asd)
Quoted 1 line

Hi,
Does this save significant power? I see that gate/ungate of clocks happen far too frequently than suspend/resume.

Have you considered how much latency this would add to the gating/ungating path?

-asd

Yes, we have measured 200 times clk-gating/clk-ungating and latency data is showed as below,

For clk-gating with interrupt disabling toggled,

Average latency of each clk-gating: 55.117 us Average latency of irq-disabling during clk-gating: 4.2 us

For clk-ungating with interrupt enabling toggled,
Average latency of each clk-ungating: 118.324 us Average latency of irq-enabling during clk-ungating: 2.9 us

The evaluation here is based on below Can's patch therefore the interrupt control (enable_irq/disable_irq) latency is much shorter than before (request_irq/free_irq).

scsi: ufs: Do not free irq in suspend
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/scsi/ufs/ufshcd.c?id=8709c1f68536e256668812788af5b2bb027f49c3

Quoted 9 lines

BTW, the main purpose of this patch is aimed to protect ufshcd register from accessing while host clocks are disabled to fix potential system hang issue. The possible scenario is mentioned in commit message of patch "scsi: ufs: disable irq before disabling clocks" in the same series.

Thanks
Stanley

Thanks for the data.
It'd be interesting to know more on the - misrouted interrupt recovery feature though.

-
Thanks
Asutosh

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
Linux Foundation Collaborative Project
#6 lore raw
In reply to Stanley Chu

Dear reviewers,

Gentle ping for this patch set.

Quoted 9 lines · Stanley Chu

This patchset fixes up active duration of ufshcd interrupt to avoid potential system hang issues.

Stanley Chu (2):
scsi: ufs: disable irq before disabling clocks
scsi: ufs: disable interrupt during clock-gating

 drivers/scsi/ufs/ufshcd.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Thanks,
Stanley

Reviewed-by
#7 lore raw

Looks good to me.

Quoted 15 lines · Stanley Chu
Quoted 1 line

This patchset fixes up active duration of ufshcd interrupt to avoid potential

system hang issues.

Quoted 8 lines

Stanley Chu (2):
scsi: ufs: disable irq before disabling clocks
scsi: ufs: disable interrupt during clock-gating

 drivers/scsi/ufs/ufshcd.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Thanks,
Stanley

#8 lore raw
In reply to Stanley Chu

Stanley,

Quoted 2 lines

This patchset fixes up active duration of ufshcd interrupt to avoid potential system hang issues.

Applied to 5.6/scsi-queue, thanks!

Signature · 6 lines
Martin K. Petersen	Oracle Linux Engineering

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel