Skip to contentSkip to conversation

Fix the error path in ufshcd_async_scan()

PATCH Applied Bart Van Assche 4 participants 12 messages Dec 18, 2023 – Jan 4, 2024

Subsystems (3)
lore
Share & tools
lore

Bart Van Assche

author reviewer
#0 lore raw

cover Fix the error path in ufshcd_async_scan()

Hi Martin,

This patch series fixes a kernel crash triggered by the error path of ufshcd_async_scan(). Please consider this patch series for the next merge window.

Thanks,

Bart.

Bart Van Assche (2):
scsi: ufs: Simplify power management during async scan
scsi: ufs: Remove the ufshcd_hba_exit() call from ufshcd_async_scan()

 drivers/ufs/core/ufshcd.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
author reviewer
#1 lore raw

PATCH 1/2 scsi: ufs: Simplify power management during async scan

ufshcd_init() calls pm_runtime_get_sync() before it calls async_schedule(). ufshcd_async_scan() calls pm_runtime_put_sync() directly or indirectly from ufshcd_add_lus(). Simplify ufshcd_async_scan() by always calling pm_runtime_put_sync() from ufshcd_async_scan().

---
 drivers/ufs/core/ufshcd.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/ufs/core/ufshcd.c +3 -4
index d6ae5d17892c..0ad8bde39cd1 100644
@@ -8711,7 +8711,6 @@ static int ufshcd_add_lus(struct ufs_hba *hba)
 
 	ufs_bsg_probe(hba);
 	scsi_scan_host(hba->host);
-	pm_runtime_put_sync(hba->dev);
 
 out:
 	return ret;
@@ -8980,15 +8979,15 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
 
 	/* Probe and add UFS logical units  */
 	ret = ufshcd_add_lus(hba);
+
 out:
+	pm_runtime_put_sync(hba->dev);
 	/*
 	 * If we failed to initialize the device or the device is not
 	 * present, turn off the power/clocks etc.
 	 */
-	if (ret) {
-		pm_runtime_put_sync(hba->dev);
+	if (ret)
 		ufshcd_hba_exit(hba);
-	}
 }
 
 static enum scsi_timeout_action ufshcd_eh_timed_out(struct scsi_cmnd *scmd)
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] scsi: ufs: Simplify power management during async scan

Quoted 33 lines · Bart Van Assche

ufshcd_init() calls pm_runtime_get_sync() before it calls async_schedule(). ufshcd_async_scan() calls pm_runtime_put_sync() directly or indirectly from ufshcd_add_lus(). Simplify ufshcd_async_scan() by always calling pm_runtime_put_sync() from ufshcd_async_scan().

---
  drivers/ufs/core/ufshcd.c | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)
drivers/ufs/core/ufshcd.c +2 -1
index d6ae5d17892c..0ad8bde39cd1 100644
@@ -8711,7 +8711,6 @@ static int ufshcd_add_lus(struct ufs_hba *hba)
 
  	ufs_bsg_probe(hba);
  	scsi_scan_host(hba->host);
-	pm_runtime_put_sync(hba->dev);
 
  out:
  	return ret;
@@ -8980,15 +8979,15 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
 
  	/* Probe and add UFS logical units  */
  	ret = ufshcd_add_lus(hba);
+
  out:
+	pm_runtime_put_sync(hba->dev);
  	/*
  	 * If we failed to initialize the device or the device is not

drivers/ufs/core/ufshcd.c static void ufshcd_async_scan(void *data, async_cookie_t cookie) · line 8993

Quoted 10 lines
drivers/ufs/core/ufshcd.c +1 -3
  	 * present, turn off the power/clocks etc.
  	 */
-	if (ret) {
-		pm_runtime_put_sync(hba->dev);
+	if (ret)
  		ufshcd_hba_exit(hba);
-	}
  }
 
  static enum scsi_timeout_action ufshcd_eh_timed_out(struct scsi_cmnd *scmd)
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] scsi: ufs: Simplify power management during async scan

In reply to Bart Van Assche
Quoted 7 lines · Bart Van Assche

ufshcd_init() calls pm_runtime_get_sync() before it calls async_schedule(). ufshcd_async_scan() calls pm_runtime_put_sync() directly or indirectly from ufshcd_add_lus(). Simplify ufshcd_async_scan() by always calling pm_runtime_put_sync() from ufshcd_async_scan().

No fixes tag?

Quoted 1 line

- Mani

Quoted 35 lines
---
 drivers/ufs/core/ufshcd.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/ufs/core/ufshcd.c +3 -4
index d6ae5d17892c..0ad8bde39cd1 100644
@@ -8711,7 +8711,6 @@ static int ufshcd_add_lus(struct ufs_hba *hba)
 
 	ufs_bsg_probe(hba);
 	scsi_scan_host(hba->host);
-	pm_runtime_put_sync(hba->dev);
 
 out:
 	return ret;
@@ -8980,15 +8979,15 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
 
 	/* Probe and add UFS logical units  */
 	ret = ufshcd_add_lus(hba);
+
 out:
+	pm_runtime_put_sync(hba->dev);
 	/*
 	 * If we failed to initialize the device or the device is not
 	 * present, turn off the power/clocks etc.
 	 */
-	if (ret) {
-		pm_runtime_put_sync(hba->dev);
+	if (ret)
 		ufshcd_hba_exit(hba);
-	}
 }
 
 static enum scsi_timeout_action ufshcd_eh_timed_out(struct scsi_cmnd *scmd)
Signature · 1 line
மணிவண்ணன் சதாசிவம்
author reviewer
#4 lore raw

Re: [PATCH 1/2] scsi: ufs: Simplify power management during async scan

Quoted 10 lines · Manivannan Sadhasivam
Quoted 7 lines · Bart Van Assche

ufshcd_init() calls pm_runtime_get_sync() before it calls async_schedule(). ufshcd_async_scan() calls pm_runtime_put_sync() directly or indirectly from ufshcd_add_lus(). Simplify ufshcd_async_scan() by always calling pm_runtime_put_sync() from ufshcd_async_scan().

No fixes tag?

There is no Fixes: tag because this patch does not change the behavior of the UFS driver. The Cc: stable tag is present because the next patch in this series has a Fixes: tag and depends on this patch.

Thanks,

Bart.

#5 lore raw

Re: [PATCH 1/2] scsi: ufs: Simplify power management during async scan

Quoted 8 lines · Bart Van Assche
Quoted 7 lines · Manivannan Sadhasivam
Quoted 6 lines · Bart Van Assche

ufshcd_init() calls pm_runtime_get_sync() before it calls async_schedule(). ufshcd_async_scan() calls pm_runtime_put_sync() directly or indirectly from ufshcd_add_lus(). Simplify ufshcd_async_scan() by always calling pm_runtime_put_sync() from ufshcd_async_scan().

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

No fixes tag?

There is no Fixes: tag because this patch does not change the behavior of the UFS driver. The Cc: stable tag is present because the next patch in this series has a Fixes: tag and depends on this patch.

Ok.

- Mani

Quoted 3 lines

Thanks,

Bart.

Signature · 1 line
மணிவண்ணன் சதாசிவம்
author reviewer
#6 lore raw

PATCH 2/2 scsi: ufs: Remove the ufshcd_hba_exit() call from ufshcd_async_scan()

In reply to Bart Van Assche

Calling ufshcd_hba_exit() from a function that is called asynchronously from ufshcd_init() is wrong because this triggers multiple race conditions. Instead of calling ufshcd_hba_exit(), log an error message.

Fixes 1d337ec2f35e ("ufs: improve init sequence")
---
 drivers/ufs/core/ufshcd.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/ufs/core/ufshcd.c +2 -5
index 0ad8bde39cd1..7c59d7a02243 100644
@@ -8982,12 +8982,9 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
 
 out:
 	pm_runtime_put_sync(hba->dev);
-	/*
-	 * If we failed to initialize the device or the device is not
-	 * present, turn off the power/clocks etc.
-	 */
+
 	if (ret)
-		ufshcd_hba_exit(hba);
+		dev_err(hba->dev, "%s failed: %d\n", __func__, ret);
 }
 
 static enum scsi_timeout_action ufshcd_eh_timed_out(struct scsi_cmnd *scmd)
Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] scsi: ufs: Remove the ufshcd_hba_exit() call from ufshcd_async_scan()

Quoted 20 lines · Bart Van Assche

Calling ufshcd_hba_exit() from a function that is called asynchronously from ufshcd_init() is wrong because this triggers multiple race conditions. Instead of calling ufshcd_hba_exit(), log an error message.

Fixes 1d337ec2f35e ("ufs: improve init sequence")
---
  drivers/ufs/core/ufshcd.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
drivers/ufs/core/ufshcd.c +0 -1
index 0ad8bde39cd1..7c59d7a02243 100644
@@ -8982,12 +8982,9 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
 
  out:
  	pm_runtime_put_sync(hba->dev);
-	/*

drivers/ufs/core/ufshcd.c static void ufshcd_async_scan(void *data, async_cookie_t cookie) · line 8990

Quoted 10 lines
drivers/ufs/core/ufshcd.c +2 -4
-	 * If we failed to initialize the device or the device is not
-	 * present, turn off the power/clocks etc.
-	 */
+
  	if (ret)
-		ufshcd_hba_exit(hba);
+		dev_err(hba->dev, "%s failed: %d\n", __func__, ret);
  }
 
  static enum scsi_timeout_action ufshcd_eh_timed_out(struct scsi_cmnd *scmd)
Reviewed-by on v1 2/2
#8 lore raw

Re: [PATCH 2/2] scsi: ufs: Remove the ufshcd_hba_exit() call from ufshcd_async_scan()

In reply to Bart Van Assche
Quoted 4 lines · Bart Van Assche

Calling ufshcd_hba_exit() from a function that is called asynchronously from ufshcd_init() is wrong because this triggers multiple race conditions. Instead of calling ufshcd_hba_exit(), log an error message.

This also means that during failure, resources will not be powered OFF. IMO, a justification is needed why it is OK to left them powered ON.

Quoted 2 lines
Fixes 1d337ec2f35e ("ufs: improve init sequence")

No need to backport this patch?

Quoted 1 line

- Mani

Quoted 23 lines
---
 drivers/ufs/core/ufshcd.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/ufs/core/ufshcd.c +2 -5
index 0ad8bde39cd1..7c59d7a02243 100644
@@ -8982,12 +8982,9 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
 
 out:
 	pm_runtime_put_sync(hba->dev);
-	/*
-	 * If we failed to initialize the device or the device is not
-	 * present, turn off the power/clocks etc.
-	 */
+
 	if (ret)
-		ufshcd_hba_exit(hba);
+		dev_err(hba->dev, "%s failed: %d\n", __func__, ret);
 }
 
 static enum scsi_timeout_action ufshcd_eh_timed_out(struct scsi_cmnd *scmd)
Signature · 1 line
மணிவண்ணன் சதாசிவம்
author reviewer
#9 lore raw

Re: [PATCH 2/2] scsi: ufs: Remove the ufshcd_hba_exit() call from ufshcd_async_scan()

Quoted 7 lines · Manivannan Sadhasivam
Quoted 3 lines · Bart Van Assche

Calling ufshcd_hba_exit() from a function that is called asynchronously from ufshcd_init() is wrong because this triggers multiple race conditions. Instead of calling ufshcd_hba_exit(), log an error message.

This also means that during failure, resources will not be powered OFF. IMO, a justification is needed why it is OK to left them powered ON.

I have never seen ufshcd_async_scan() fail other than during hardware bringup. Has anyone else ever observed a ufshcd_async_scan() failure?

Quoted 4 lines
Quoted 2 lines
Fixes 1d337ec2f35e ("ufs: improve init sequence")

No need to backport this patch?

Isn't the "Fixes:" tag sufficient? I don't think that it it necessary to add a "Cc: stable" tag if a "Fixes:" tag is present.

Thanks,

Bart.

#10 lore raw

Re: [PATCH 2/2] scsi: ufs: Remove the ufshcd_hba_exit() call from ufshcd_async_scan()

Quoted 12 lines · Bart Van Assche
Quoted 7 lines · Manivannan Sadhasivam
Quoted 3 lines · Bart Van Assche

Calling ufshcd_hba_exit() from a function that is called asynchronously from ufshcd_init() is wrong because this triggers multiple race conditions. Instead of calling ufshcd_hba_exit(), log an error message.

This also means that during failure, resources will not be powered OFF. IMO, a justification is needed why it is OK to left them powered ON.

I have never seen ufshcd_async_scan() fail other than during hardware bringup. Has anyone else ever observed a ufshcd_async_scan() failure?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Fixes 1d337ec2f35e ("ufs: improve init sequence")

No need to backport this patch?

Isn't the "Fixes:" tag sufficient? I don't think that it it necessary to add a "Cc: stable" tag if a "Fixes:" tag is present.

No. You need to explicitly CC stable list, if you want the commit to be backported to stable releases. Even though the stable maintainers backport the commits with Fixes tag, it is always strongly advised to explictly CC stable list.

Here is an excerpt from Documentation/process/stable-kernel-rules.rst:

"There are three options to submit a change to -stable trees:

1. Add a 'stable tag' to the description of a patch you then submit for mainline inclusion.
2. Ask the stable team to pick up a patch already mainlined.
3. Submit a patch to the stable team that is equivalent to a change already mainlined.

The sections below describe each of the options in more detail.

:ref:option_1 is **strongly** preferred, it is the easiest and most common."

- Mani

Quoted 3 lines

Thanks,

Bart.

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#11 lore raw
In reply to Bart Van Assche

Bart,

Quoted 3 lines

This patch series fixes a kernel crash triggered by the error path of ufshcd_async_scan(). Please consider this patch series for the next merge window.

Applied to 6.8/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering