Skip to contentSkip to conversation

scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()

PATCH Applied Adrian Hunter 6 participants 9 messages Mar 1, 2021 – Mar 4, 2021 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()

If ufshcd_probe_hba() fails it sets ufshcd_state to UFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop in ufshcd_reset_and_restore(), and succeeds, then it will not set the state back to UFSHCD_STATE_OPERATIONAL unless the state was UFSHCD_STATE_RESET.

That can result in the state being UFSHCD_STATE_ERROR even though ufshcd_reset_and_restore() is successful and returns zero.

Fix by initializing the state to UFSHCD_STATE_RESET in the start of each loop in ufshcd_reset_and_restore(). If there is an error, ufshcd_reset_and_restore() will change the state to UFSHCD_STATE_ERROR, otherwise ufshcd_probe_hba() will have set the state appropriately.

Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler and other error recovery paths")
---
 drivers/scsi/ufs/ufshcd.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/scsi/ufs/ufshcd.c +2 -0
index 77161750c9fb..91a403afe038 100644
@@ -7031,6 +7031,8 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba)
 	spin_unlock_irqrestore(hba->host->host_lock, flags);
 
 	do {
+		hba->ufshcd_state = UFSHCD_STATE_RESET;
+
 		/* Reset the attached device */
 		ufshcd_device_reset(hba);
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Adrian Hunter

If ufshcd_probe_hba() fails it sets ufshcd_state to UFSHCD_STATE_ERROR,
however, if it is called again, as it is within a loop in ufshcd_reset_and_restore(), and succeeds, then it will not set the state
back to UFSHCD_STATE_OPERATIONAL unless the state was UFSHCD_STATE_RESET.

That can result in the state being UFSHCD_STATE_ERROR even though ufshcd_reset_and_restore() is successful and returns zero.

Fix by initializing the state to UFSHCD_STATE_RESET in the start of each
loop in ufshcd_reset_and_restore(). If there is an error, ufshcd_reset_and_restore() will change the state to UFSHCD_STATE_ERROR,
otherwise ufshcd_probe_hba() will have set the state appropriately.

Quoted 3 lines
Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler and

other error recovery paths")

We used to directly set hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL at the beginning of ufshcd_probe_hba(), and didn't have checkup if (hba-

Quoted 1 line

ufshcd_state == UFSHCD_STATE_RESET). Remove this checkup, also works,

but in This loop, it it better that, before going to reset flow, ufshcd_state should be set UFSHCD_STATE_RESET.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Adrian Hunter
Quoted 9 lines · Adrian Hunter

If ufshcd_probe_hba() fails it sets ufshcd_state to UFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop in ufshcd_reset_and_restore(), and succeeds, then it will not set the state back to UFSHCD_STATE_OPERATIONAL unless the state was UFSHCD_STATE_RESET.

That can result in the state being UFSHCD_STATE_ERROR even though ufshcd_reset_and_restore() is successful and returns zero.

Quoted 8 lines

Fix by initializing the state to UFSHCD_STATE_RESET in the start of each loop in ufshcd_reset_and_restore(). If there is an error, ufshcd_reset_and_restore() will change the state to UFSHCD_STATE_ERROR, otherwise ufshcd_probe_hba() will have set the state appropriately.

Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler and other error recovery paths")

---

Quoted 19 lines

drivers/scsi/ufs/ufshcd.c | 2 ++

1 file changed, 2 insertions(+)
drivers/scsi/ufs/ufshcd.c +2 -0
index 77161750c9fb..91a403afe038 100644
@@ -7031,6 +7031,8 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba)
 	spin_unlock_irqrestore(hba->host->host_lock, flags);
 
 	do {
+		hba->ufshcd_state = UFSHCD_STATE_RESET;
+
 		/* Reset the attached device */
 		ufshcd_device_reset(hba);
 
Signature · 1 line
2.17.1
#3 lore raw
In reply to Adrian Hunter
Quoted 10 lines

If ufshcd_probe_hba() fails it sets ufshcd_state to UFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop in ufshcd_reset_and_restore(), and succeeds, then it will not set the state back to UFSHCD_STATE_OPERATIONAL unless the state was UFSHCD_STATE_RESET.

That can result in the state being UFSHCD_STATE_ERROR even though ufshcd_reset_and_restore() is successful and returns zero.

Quoted 8 lines

Fix by initializing the state to UFSHCD_STATE_RESET in the start of each loop in ufshcd_reset_and_restore(). If there is an error, ufshcd_reset_and_restore() will change the state to UFSHCD_STATE_ERROR, otherwise ufshcd_probe_hba() will have set the state appropriately.

Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler and other

error recovery paths")

I think that CanG recent series addressed that issue as well, can you take a look?
https://lore.kernel.org/lkml/[email protected]/

Quoted 20 lines
---
 drivers/scsi/ufs/ufshcd.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/scsi/ufs/ufshcd.c +2 -1
index 77161750c9fb..91a403afe038 100644
@@ -7031,6 +7031,8 @@ static int ufshcd_reset_and_restore(struct ufs_hba
 *hba)
        spin_unlock_irqrestore(hba->host->host_lock, flags);
 
        do {
+               hba->ufshcd_state = UFSHCD_STATE_RESET;
+
                /* Reset the attached device */
                ufshcd_device_reset(hba);
 
--

2.17.1

#4 lore raw
Quoted 15 lines · Avri Altman
Quoted 15 lines

If ufshcd_probe_hba() fails it sets ufshcd_state to UFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop in ufshcd_reset_and_restore(), and succeeds, then it will not set the state back to UFSHCD_STATE_OPERATIONAL unless the state was UFSHCD_STATE_RESET.

That can result in the state being UFSHCD_STATE_ERROR even though ufshcd_reset_and_restore() is successful and returns zero.

Fix by initializing the state to UFSHCD_STATE_RESET in the start of each loop in ufshcd_reset_and_restore(). If there is an error, ufshcd_reset_and_restore() will change the state to UFSHCD_STATE_ERROR, otherwise ufshcd_probe_hba() will have set the state appropriately.

Quoted 5 lines
Quoted 3 lines
Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler and other

error recovery paths")

I think that CanG recent series addressed that issue as well, can you take a look?
https://lore.kernel.org/lkml/[email protected]/

Yes, there it is mixed in with other changes. However it is probably better as a separate patch. Can Guo, what do you think?

Quoted 23 lines
Quoted 22 lines

---
 drivers/scsi/ufs/ufshcd.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/scsi/ufs/ufshcd.c +2 -1
index 77161750c9fb..91a403afe038 100644
@@ -7031,6 +7031,8 @@ static int ufshcd_reset_and_restore(struct ufs_hba
 *hba)
        spin_unlock_irqrestore(hba->host->host_lock, flags);
 
        do {
+               hba->ufshcd_state = UFSHCD_STATE_RESET;
+
                /* Reset the attached device */
                ufshcd_device_reset(hba);
 
--

2.17.1

#5 lore raw
Quoted 11 lines · Adrian Hunter
Quoted 11 lines
Quoted 11 lines

That can result in the state being UFSHCD_STATE_ERROR even though ufshcd_reset_and_restore() is successful and returns zero.

Fix by initializing the state to UFSHCD_STATE_RESET in the start of each
loop in ufshcd_reset_and_restore(). If there is an error, ufshcd_reset_and_restore() will change the state to UFSHCD_STATE_ERROR,
otherwise ufshcd_probe_hba() will have set the state appropriately.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler

and other
error recovery paths")

I think that CanG recent series addressed that issue as well, can you take a look?

https://lore.kernel.org/lkml/[email protected]/

Quoted 4 lines

Yes, there it is mixed in with other changes. However it is probably better
as a separate patch. Can Guo, what do you think?

we can firstly take this fixup patch.

#6 lore raw
In reply to Adrian Hunter
Quoted 16 lines · Adrian Hunter
Quoted 15 lines · Avri Altman
Quoted 15 lines

If ufshcd_probe_hba() fails it sets ufshcd_state to UFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop in ufshcd_reset_and_restore(), and succeeds, then it will not set the state back to UFSHCD_STATE_OPERATIONAL unless the state was UFSHCD_STATE_RESET.

That can result in the state being UFSHCD_STATE_ERROR even though ufshcd_reset_and_restore() is successful and returns zero.

Fix by initializing the state to UFSHCD_STATE_RESET in the start of each loop in ufshcd_reset_and_restore(). If there is an error, ufshcd_reset_and_restore() will change the state to UFSHCD_STATE_ERROR, otherwise ufshcd_probe_hba() will have set the state appropriately.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler and other

error recovery paths")

I think that CanG recent series addressed that issue as well, can you take a look?
https://lore.kernel.org/lkml/[email protected]/

Yes, there it is mixed in with other changes. However it is probably better as a separate patch. Can Guo, what do you think?

Oh, I missed this one...
Sure, I will split it out as a seperate change in next version.

Thanks,
Can Guo.

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines


---
 drivers/scsi/ufs/ufshcd.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/scsi/ufs/ufshcd.c +0 -0
index 77161750c9fb..91a403afe038 100644
@@ -7031,6 +7031,8 @@ static int ufshcd_reset_and_restore(struct 

ufs_hba
*hba)

        spin_unlock_irqrestore(hba->host->host_lock, flags);

        do {
drivers/scsi/ufs/ufshcd.c +2 -1
+               hba->ufshcd_state = UFSHCD_STATE_RESET;
+
                /* Reset the attached device */
                ufshcd_device_reset(hba);
 
--

2.17.1

#7 lore raw
In reply to Adrian Hunter
Quoted 26 lines · Adrian Hunter

If ufshcd_probe_hba() fails it sets ufshcd_state to UFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop in ufshcd_reset_and_restore(), and succeeds, then it will not set the state back to UFSHCD_STATE_OPERATIONAL unless the state was UFSHCD_STATE_RESET.

That can result in the state being UFSHCD_STATE_ERROR even though ufshcd_reset_and_restore() is successful and returns zero.

Fix by initializing the state to UFSHCD_STATE_RESET in the start of each loop in ufshcd_reset_and_restore(). If there is an error, ufshcd_reset_and_restore() will change the state to UFSHCD_STATE_ERROR, otherwise ufshcd_probe_hba() will have set the state appropriately.

Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler and

other error recovery paths")

---
 drivers/scsi/ufs/ufshcd.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/scsi/ufs/ufshcd.c +0 -0
index 77161750c9fb..91a403afe038 100644

drivers/scsi/ufs/ufshcd.c static int ufshcd_reset_and_restore(struct · line 7038

Quoted 8 lines
drivers/scsi/ufs/ufshcd.c +2 -0
@@ -7031,6 +7031,8 @@ static int ufshcd_reset_and_restore(struct 
 ufs_hba *hba)
 	spin_unlock_irqrestore(hba->host->host_lock, flags);
 
 	do {
+		hba->ufshcd_state = UFSHCD_STATE_RESET;
+
 		/* Reset the attached device */
 		ufshcd_device_reset(hba);

Hi Adrian,

I've proposed a fix to get it addressed - https://lore.kernel.org/patchwork/patch/1383817/

Thanks,

Can Guo.

#8 lore raw
In reply to Adrian Hunter
Quoted 10 lines · Adrian Hunter

If ufshcd_probe_hba() fails it sets ufshcd_state to UFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop in ufshcd_reset_and_restore(), and succeeds, then it will not set the state back to UFSHCD_STATE_OPERATIONAL unless the state was UFSHCD_STATE_RESET.

That can result in the state being UFSHCD_STATE_ERROR even though ufshcd_reset_and_restore() is successful and returns zero.

[...]

Applied to 5.12/scsi-fixes, thanks!

[1/1] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()

      https://git.kernel.org/mkp/scsi/c/02c2fc6acc43
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering