scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()
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.
--- drivers/scsi/ufs/ufshcd.c | 2 ++ 1 file changed, 2 insertions(+)
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);
Signature · 1 line
2.17.1
Quoted 18 lines · Adrian Hunter
If
ufshcd_probe_hba()fails it setsufshcd_statetoUFSHCD_STATE_ERROR,
however, if it is called again, as it is within a loop inufshcd_reset_and_restore(), and succeeds, then it will not set the state
back toUFSHCD_STATE_OPERATIONALunless the state wasUFSHCD_STATE_RESET.That can result in the state being
UFSHCD_STATE_ERROReven thoughufshcd_reset_and_restore()is successful and returns zero.Fix by initializing the state to
UFSHCD_STATE_RESETin the start of each
loop inufshcd_reset_and_restore(). If there is an error,ufshcd_reset_and_restore()will change the state toUFSHCD_STATE_ERROR,
otherwiseufshcd_probe_hba()will have set the state appropriately.
Quoted 3 lines
Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler andother error recovery paths")
Signed-off-by Adrian Hunter <[email protected]>
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.
Quoted 9 lines · Adrian Hunter
If
ufshcd_probe_hba()fails it setsufshcd_statetoUFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop inufshcd_reset_and_restore(), and succeeds, then it will not set the state back toUFSHCD_STATE_OPERATIONALunless the state wasUFSHCD_STATE_RESET.That can result in the state being
UFSHCD_STATE_ERROReven thoughufshcd_reset_and_restore()is successful and returns zero.
Quoted 8 lines
Fix by initializing the state to
UFSHCD_STATE_RESETin the start of each loop inufshcd_reset_and_restore(). If there is an error,ufshcd_reset_and_restore()will change the state toUFSHCD_STATE_ERROR, otherwiseufshcd_probe_hba()will have set the state appropriately.Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler and other error recovery paths")Signed-off-by Adrian Hunter <[email protected]>---
Quoted 19 lines
drivers/scsi/ufs/ufshcd.c| 2 ++1 file changed, 2 insertions(+)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);Signature · 1 line
2.17.1
Quoted 10 lines
If
ufshcd_probe_hba()fails it setsufshcd_statetoUFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop inufshcd_reset_and_restore(), and succeeds, then it will not set the state back toUFSHCD_STATE_OPERATIONALunless the state wasUFSHCD_STATE_RESET.That can result in the state being
UFSHCD_STATE_ERROReven thoughufshcd_reset_and_restore()is successful and returns zero.
Quoted 8 lines
Fix by initializing the state to
UFSHCD_STATE_RESETin the start of each loop inufshcd_reset_and_restore(). If there is an error,ufshcd_reset_and_restore()will change the state toUFSHCD_STATE_ERROR, otherwiseufshcd_probe_hba()will have set the state appropriately.Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler and othererror recovery paths")
Signed-off-by Adrian Hunter <[email protected]>
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@@ -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
Quoted 15 lines · Avri Altman
Quoted 15 lines
If
ufshcd_probe_hba()fails it setsufshcd_statetoUFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop inufshcd_reset_and_restore(), and succeeds, then it will not set the state back toUFSHCD_STATE_OPERATIONALunless the state wasUFSHCD_STATE_RESET.That can result in the state being
UFSHCD_STATE_ERROReven thoughufshcd_reset_and_restore()is successful and returns zero.Fix by initializing the state to
UFSHCD_STATE_RESETin the start of each loop inufshcd_reset_and_restore(). If there is an error,ufshcd_reset_and_restore()will change the state toUFSHCD_STATE_ERROR, otherwiseufshcd_probe_hba()will have set the state appropriately.
Quoted 5 lines
Quoted 3 lines
Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler and othererror recovery paths")
Signed-off-by Adrian Hunter <[email protected]>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@@ -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
Quoted 11 lines · Adrian Hunter
Quoted 11 lines
Quoted 11 lines
That can result in the state being
UFSHCD_STATE_ERROReven thoughufshcd_reset_and_restore()is successful and returns zero.Fix by initializing the state to
UFSHCD_STATE_RESETin the start of each
loop inufshcd_reset_and_restore(). If there is an error,ufshcd_reset_and_restore()will change the state toUFSHCD_STATE_ERROR,
otherwiseufshcd_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 handlerand other
error recovery paths")Signed-off-by Adrian Hunter <[email protected]>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.
Quoted 16 lines · Adrian Hunter
Quoted 15 lines · Avri Altman
Quoted 15 lines
If
ufshcd_probe_hba()fails it setsufshcd_statetoUFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop inufshcd_reset_and_restore(), and succeeds, then it will not set the state back toUFSHCD_STATE_OPERATIONALunless the state wasUFSHCD_STATE_RESET.That can result in the state being
UFSHCD_STATE_ERROReven thoughufshcd_reset_and_restore()is successful and returns zero.Fix by initializing the state to
UFSHCD_STATE_RESETin the start of each loop inufshcd_reset_and_restore(). If there is an error,ufshcd_reset_and_restore()will change the state toUFSHCD_STATE_ERROR, otherwiseufshcd_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 othererror recovery paths")
Signed-off-by Adrian Hunter <[email protected]>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@@ -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
Quoted 26 lines · Adrian Hunter
If
ufshcd_probe_hba()fails it setsufshcd_statetoUFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop inufshcd_reset_and_restore(), and succeeds, then it will not set the state back toUFSHCD_STATE_OPERATIONALunless the state wasUFSHCD_STATE_RESET.That can result in the state being
UFSHCD_STATE_ERROReven thoughufshcd_reset_and_restore()is successful and returns zero.Fix by initializing the state to
UFSHCD_STATE_RESETin the start of each loop inufshcd_reset_and_restore(). If there is an error,ufshcd_reset_and_restore()will change the state toUFSHCD_STATE_ERROR, otherwiseufshcd_probe_hba()will have set the state appropriately.Fixes 4db7a2360597 ("scsi: ufs: Fix concurrency of error handler andother error recovery paths")
Signed-off-by Adrian Hunter <[email protected]>--- drivers/scsi/ufs/ufshcd.c | 2 ++ 1 file changed, 2 insertions(+)drivers/scsi/ufs/ufshcd.c +0
-0
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.
Martin K. Petersen
AppliedQuoted 10 lines · Adrian Hunter
If
ufshcd_probe_hba()fails it setsufshcd_statetoUFSHCD_STATE_ERROR, however, if it is called again, as it is within a loop inufshcd_reset_and_restore(), and succeeds, then it will not set the state back toUFSHCD_STATE_OPERATIONALunless the state wasUFSHCD_STATE_RESET.That can result in the state being
UFSHCD_STATE_ERROReven thoughufshcd_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