linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()
@ 2021-03-01 19:19 Adrian Hunter
  2021-03-01 20:46 ` Bean Huo
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Adrian Hunter @ 2021-03-01 19:19 UTC (permalink / raw)
  To: Martin K . Petersen, James E . J . Bottomley
  Cc: linux-scsi, linux-kernel, Alim Akhtar, Avri Altman, Bean Huo,
	Can Guo, Asutosh Das, Stanley Chu

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")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/scsi/ufs/ufshcd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 77161750c9fb..91a403afe038 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()
  2021-03-01 19:19 [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore() Adrian Hunter
@ 2021-03-01 20:46 ` Bean Huo
  2021-03-01 23:54 ` Asutosh Das
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Bean Huo @ 2021-03-01 20:46 UTC (permalink / raw)
  To: Adrian Hunter, Martin K . Petersen, James E . J . Bottomley
  Cc: linux-scsi, linux-kernel, Alim Akhtar, Avri Altman, Can Guo,
	Asutosh Das, Stanley Chu

On Mon, 2021-03-01 at 21:19 +0200, Adrian Hunter wrote:
> 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")
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>

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-
>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: Bean Huo <beanhuo@micron.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()
  2021-03-01 19:19 [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore() Adrian Hunter
  2021-03-01 20:46 ` Bean Huo
@ 2021-03-01 23:54 ` Asutosh Das
  2021-03-02  7:01 ` Avri Altman
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Asutosh Das @ 2021-03-01 23:54 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Martin K . Petersen, James E . J . Bottomley, linux-scsi,
	linux-kernel, Alim Akhtar, Avri Altman, Bean Huo, Can Guo,
	Stanley Chu

On Mon, Mar 01 2021 at 11:19 -0800, Adrian Hunter wrote:
>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")
>Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
>---

Reviewed-by: Asutosh Das <asutoshd@codeaurora.org>

> drivers/scsi/ufs/ufshcd.c | 2 ++
> 1 file changed, 2 insertions(+)
>
>diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
>index 77161750c9fb..91a403afe038 100644
>--- a/drivers/scsi/ufs/ufshcd.c
>+++ b/drivers/scsi/ufs/ufshcd.c
>@@ -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
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()
  2021-03-01 19:19 [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore() Adrian Hunter
  2021-03-01 20:46 ` Bean Huo
  2021-03-01 23:54 ` Asutosh Das
@ 2021-03-02  7:01 ` Avri Altman
  2021-03-02  8:14   ` Adrian Hunter
  2021-03-03 10:05 ` Can Guo
  2021-03-04  4:16 ` Martin K. Petersen
  4 siblings, 1 reply; 9+ messages in thread
From: Avri Altman @ 2021-03-02  7:01 UTC (permalink / raw)
  To: Adrian Hunter, Martin K . Petersen, James E . J . Bottomley
  Cc: linux-scsi, linux-kernel, Alim Akhtar, Bean Huo, Can Guo,
	Asutosh Das, Stanley Chu

 
> 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")
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
I think that CanG recent series addressed that issue as well, can you take a look?
https://lore.kernel.org/lkml/1614145010-36079-2-git-send-email-cang@codeaurora.org/


> ---
>  drivers/scsi/ufs/ufshcd.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 77161750c9fb..91a403afe038 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()
  2021-03-02  7:01 ` Avri Altman
@ 2021-03-02  8:14   ` Adrian Hunter
  2021-03-02 13:04     ` Bean Huo
  2021-03-03 10:19     ` Can Guo
  0 siblings, 2 replies; 9+ messages in thread
From: Adrian Hunter @ 2021-03-02  8:14 UTC (permalink / raw)
  To: Avri Altman, Martin K . Petersen, James E . J . Bottomley
  Cc: linux-scsi, linux-kernel, Alim Akhtar, Bean Huo, Can Guo,
	Asutosh Das, Stanley Chu

On 2/03/21 9:01 am, Avri Altman wrote:
>  
>> 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")
>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> I think that CanG recent series addressed that issue as well, can you take a look?
> https://lore.kernel.org/lkml/1614145010-36079-2-git-send-email-cang@codeaurora.org/

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

> 
> 
>> ---
>>  drivers/scsi/ufs/ufshcd.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
>> index 77161750c9fb..91a403afe038 100644
>> --- a/drivers/scsi/ufs/ufshcd.c
>> +++ b/drivers/scsi/ufs/ufshcd.c
>> @@ -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
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()
  2021-03-02  8:14   ` Adrian Hunter
@ 2021-03-02 13:04     ` Bean Huo
  2021-03-03 10:19     ` Can Guo
  1 sibling, 0 replies; 9+ messages in thread
From: Bean Huo @ 2021-03-02 13:04 UTC (permalink / raw)
  To: Adrian Hunter, Avri Altman, Martin K . Petersen, James E . J . Bottomley
  Cc: linux-scsi, linux-kernel, Alim Akhtar, Can Guo, Asutosh Das, Stanley Chu

On Tue, 2021-03-02 at 10:14 +0200, Adrian Hunter wrote:
> > > 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")
> > > Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> > 
> > I think that CanG recent series addressed that issue as well, can
> > you take a look?
> > 
https://lore.kernel.org/lkml/1614145010-36079-2-git-send-email-cang@codeaurora.org/
> 
> 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.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()
  2021-03-01 19:19 [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore() Adrian Hunter
                   ` (2 preceding siblings ...)
  2021-03-02  7:01 ` Avri Altman
@ 2021-03-03 10:05 ` Can Guo
  2021-03-04  4:16 ` Martin K. Petersen
  4 siblings, 0 replies; 9+ messages in thread
From: Can Guo @ 2021-03-03 10:05 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Martin K . Petersen, James E . J . Bottomley, linux-scsi,
	linux-kernel, Alim Akhtar, Avri Altman, Bean Huo, Asutosh Das,
	Stanley Chu

On 2021-03-02 03:19, Adrian Hunter wrote:
> 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")
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  drivers/scsi/ufs/ufshcd.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 77161750c9fb..91a403afe038 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()
  2021-03-02  8:14   ` Adrian Hunter
  2021-03-02 13:04     ` Bean Huo
@ 2021-03-03 10:19     ` Can Guo
  1 sibling, 0 replies; 9+ messages in thread
From: Can Guo @ 2021-03-03 10:19 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Avri Altman, Martin K . Petersen, James E . J . Bottomley,
	linux-scsi, linux-kernel, Alim Akhtar, Bean Huo, Asutosh Das,
	Stanley Chu

On 2021-03-02 16:14, Adrian Hunter wrote:
> On 2/03/21 9:01 am, Avri Altman wrote:
>> 
>>> 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")
>>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
>> I think that CanG recent series addressed that issue as well, can you 
>> take a look?
>> https://lore.kernel.org/lkml/1614145010-36079-2-git-send-email-cang@codeaurora.org/
> 
> 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.

> 
>> 
>> 
>>> ---
>>>  drivers/scsi/ufs/ufshcd.c | 2 ++
>>>  1 file changed, 2 insertions(+)
>>> 
>>> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
>>> index 77161750c9fb..91a403afe038 100644
>>> --- a/drivers/scsi/ufs/ufshcd.c
>>> +++ b/drivers/scsi/ufs/ufshcd.c
>>> @@ -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
>> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore()
  2021-03-01 19:19 [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore() Adrian Hunter
                   ` (3 preceding siblings ...)
  2021-03-03 10:05 ` Can Guo
@ 2021-03-04  4:16 ` Martin K. Petersen
  4 siblings, 0 replies; 9+ messages in thread
From: Martin K. Petersen @ 2021-03-04  4:16 UTC (permalink / raw)
  To: Adrian Hunter, James E . J . Bottomley
  Cc: Martin K . Petersen, Alim Akhtar, Can Guo, Bean Huo,
	linux-kernel, Asutosh Das, Avri Altman, Stanley Chu, linux-scsi

On Mon, 1 Mar 2021 21:19:40 +0200, Adrian Hunter wrote:

> 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

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-03-04  4:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01 19:19 [PATCH] scsi: ufs: Fix incorrect ufshcd_state after ufshcd_reset_and_restore() Adrian Hunter
2021-03-01 20:46 ` Bean Huo
2021-03-01 23:54 ` Asutosh Das
2021-03-02  7:01 ` Avri Altman
2021-03-02  8:14   ` Adrian Hunter
2021-03-02 13:04     ` Bean Huo
2021-03-03 10:19     ` Can Guo
2021-03-03 10:05 ` Can Guo
2021-03-04  4:16 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).