Skip to contentSkip to conversation

scsi: ufs: Improve SCSI abort handling

PATCH Applied Bart Van Assche 6 participants 14 messages Nov 4, 2021 – Dec 14, 2021 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: ufs: Improve SCSI abort handling

The following has been observed on a test setup:

WARNING: CPU: 4 PID: 250 at drivers/scsi/ufs/ufshcd.c:2737 ufshcd_queuecommand+0x468/0x65c
Call trace:
 ufshcd_queuecommand+0x468/0x65c
 scsi_send_eh_cmnd+0x224/0x6a0
 scsi_eh_test_devices+0x248/0x418
 scsi_eh_ready_devs+0xc34/0xe58
 scsi_error_handler+0x204/0x80c
 kthread+0x150/0x1b4
 ret_from_fork+0x10/0x30

That warning is triggered by the following statement:

	WARN_ON(lrbp->cmd);

Fix this warning by clearing lrbp->cmd from the abort handler.

Fixes 7a3e97b0dc4b ("[SCSI] ufshcd: UFS Host controller driver")
---
 drivers/scsi/ufs/ufshcd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/ufs/ufshcd.c +1 -0
index 3b4a714e2f68..d8a59258b1dc 100644
@@ -7069,6 +7069,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)
 		goto release;
 	}
 
+	lrbp->cmd = NULL;
 	err = SUCCESS;
 
 release:
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Bart Van Assche

The following has been observed on a test setup:

WARNING: CPU: 4 PID: 250 at drivers/scsi/ufs/ufshcd.c:2737
ufshcd_queuecommand+0x468/0x65c
Call trace:
 ufshcd_queuecommand+0x468/0x65c
 scsi_send_eh_cmnd+0x224/0x6a0
 scsi_eh_test_devices+0x248/0x418
 scsi_eh_ready_devs+0xc34/0xe58
 scsi_error_handler+0x204/0x80c
 kthread+0x150/0x1b4
 ret_from_fork+0x10/0x30
Quoted 8 lines

That warning is triggered by the following statement:

	WARN_ON(lrbp->cmd);

Fix this warning by clearing lrbp->cmd from the abort handler.

Fixes 7a3e97b0dc4b ("[SCSI] ufshcd: UFS Host controller driver")
Quoted 16 lines
---
 drivers/scsi/ufs/ufshcd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/ufs/ufshcd.c +1 -0
index 3b4a714e2f68..d8a59258b1dc 100644
@@ -7069,6 +7069,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)
 		goto release;
 	}
 
+	lrbp->cmd = NULL;
 	err = SUCCESS;
 
 release:
#2 lore raw

PATCH 1/1 scsi: ufs: Improve SCSI abort handling

In reply to Bart Van Assche

Hi Bart,

Quoted 11 lines
drivers/scsi/ufs/ufshcd.c +1 -0
index 3b4a714e2f68..d8a59258b1dc 100644
@@ -7069,6 +7069,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)
                goto release;
        }
 
+        lrbp->cmd = NULL;
        err = SUCCESS;
 
Quoted 1 line

release:

I found similar code in the ufshcd_err_handler(). I think the following patch will required to fix another warning.

drivers/scsi/ufs/ufshcd.c +1 -0
index f5ba8f953b87..cce9abc6b879 100644
@@ -6190,6 +6190,7 @@ static void ufshcd_err_handler(struct work_struct *work)
                }
                dev_err(hba->dev, "Aborted tag %d / CDB %#02x\n", tag,
                        hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1);
+               hba->lrb[tag].cmd = NULL;
        }
 
        /* Clear pending task management requests */

Thanks,
Daejun

#3 lore raw
Quoted 8 lines · Daejun Park

I found similar code in the ufshcd_err_handler(). I think the following patch will required to fix another warning.

drivers/scsi/ufs/ufshcd.c +0 -0
index f5ba8f953b87..cce9abc6b879 100644

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

Quoted 7 lines
drivers/scsi/ufs/ufshcd.c +1 -0
@@ -6190,6 +6190,7 @@ static void ufshcd_err_handler(struct work_struct *work)
                 }
                 dev_err(hba->dev, "Aborted tag %d / CDB %#02x\n", tag,
                         hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1);
+               hba->lrb[tag].cmd = NULL;
         }
 
         /* Clear pending task management requests */

Hmm ... since the error handler calls ufshcd_complete_requests(), shouldn't the completion function clear the 'cmd' member? I'm concerned that the above change would break the completion handler.

Thanks,

Bart.

Reviewed-by
#4 lore raw
Quoted 15 lines · Daejun Park
Quoted 14 lines

I found similar code in the ufshcd_err_handler(). I think the following patch will required to fix another warning.

drivers/scsi/ufs/ufshcd.c +1 -0
index f5ba8f953b87..cce9abc6b879 100644
@@ -6190,6 +6190,7 @@ static void ufshcd_err_handler(struct work_struct *work)
                 }
                 dev_err(hba->dev, "Aborted tag %d / CDB %#02x\n", tag,
                         hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1);
+               hba->lrb[tag].cmd = NULL;
         }
 
Quoted 5 lines

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

Quoted 1 line
drivers/scsi/ufs/ufshcd.c +0 -0
         /* Clear pending task management requests */

Hmm ... since the error handler calls ufshcd_complete_requests(), shouldn't the completion function clear the 'cmd' member? I'm concerned that the above change would break the completion handler.

I missed that the error handler calls ufshcd_complete_requests(). Please ignore my suggestion.

By the way, I give my reviewed-by tag.

Thanks,
Daejun

#5 lore raw
Quoted 21 lines · Daejun Park
Quoted 15 lines · Daejun Park
Quoted 14 lines

I found similar code in the ufshcd_err_handler(). I think the following patch will required to fix another warning.

drivers/scsi/ufs/ufshcd.c +1 -0
index f5ba8f953b87..cce9abc6b879 100644
@@ -6190,6 +6190,7 @@ static void ufshcd_err_handler(struct work_struct *work)
                  }
                  dev_err(hba->dev, "Aborted tag %d / CDB %#02x\n", tag,
                          hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1);
+               hba->lrb[tag].cmd = NULL;
          }
 
Quoted 5 lines

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

Quoted 1 line
drivers/scsi/ufs/ufshcd.c +0 -0
          /* Clear pending task management requests */

Hmm ... since the error handler calls ufshcd_complete_requests(), shouldn't the completion function clear the 'cmd' member? I'm concerned that the above change would break the completion handler.

Quoted 6 lines

I missed that the error handler calls ufshcd_complete_requests(). Please ignore my suggestion.

By the way, I give my reviewed-by tag.

Thanks Daejun! However, your question made me wonder whether ufshcd_abort() should clear the 'tag' bit from hba->outstanding_reqs. Although the SCSI standard requires that a command that is aborted is not completed, the UFSHCI specification requires that writing into the UTRLCLR register clears the corresponding bit(s) in the UTRLDBR register. I think bit 'tag' will have to be cleared from hba->outstanding_reqs to prevent that the aborted request is completed while the SCSI core is resubmitting it.

Thanks,

Bart.

#6 lore raw
Quoted 29 lines · Daejun Park
Quoted 21 lines
Quoted 15 lines · Daejun Park
Quoted 14 lines

I found similar code in the ufshcd_err_handler(). I think the following patch will required to fix another warning.

drivers/scsi/ufs/ufshcd.c +1 -0
index f5ba8f953b87..cce9abc6b879 100644
@@ -6190,6 +6190,7 @@ static void ufshcd_err_handler(struct work_struct *work)
                  }
                  dev_err(hba->dev, "Aborted tag %d / CDB %#02x\n", tag,
                          hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1);
+               hba->lrb[tag].cmd = NULL;
          }
 
Quoted 5 lines

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

Quoted 1 line
drivers/scsi/ufs/ufshcd.c +0 -0
          /* Clear pending task management requests */

Hmm ... since the error handler calls ufshcd_complete_requests(), shouldn't the completion function clear the 'cmd' member? I'm concerned that the above change would break the completion handler.

Quoted 6 lines

I missed that the error handler calls ufshcd_complete_requests(). Please ignore my suggestion.

By the way, I give my reviewed-by tag.

Quoted 7 lines

Thanks Daejun! However, your question made me wonder whether ufshcd_abort() should clear the 'tag' bit from hba->outstanding_reqs. Although the SCSI standard requires that a command that is aborted is not completed, the UFSHCI specification requires that writing into the UTRLCLR register clears the corresponding bit(s) in the UTRLDBR register. I think bit 'tag' will have to be cleared from hba->outstanding_reqs to prevent that the aborted request is completed while the SCSI core is resubmitting it.

My understanding is the completion of aborted request can be duplicated because SCSI core will resubmit the request. Therefore the clearing of the bit can avoid duplicated completion of the request.

Thanks,
Daejun

Reviewed-by on v1 1/1
#7 lore raw
In reply to Bart Van Assche

Hi Bart,

Quoted 30 lines · Bart Van Assche

The following has been observed on a test setup:

WARNING: CPU: 4 PID: 250 at drivers/scsi/ufs/ufshcd.c:2737
ufshcd_queuecommand+0x468/0x65c
Call trace:
 ufshcd_queuecommand+0x468/0x65c
 scsi_send_eh_cmnd+0x224/0x6a0
 scsi_eh_test_devices+0x248/0x418
 scsi_eh_ready_devs+0xc34/0xe58
 scsi_error_handler+0x204/0x80c
 kthread+0x150/0x1b4
 ret_from_fork+0x10/0x30

That warning is triggered by the following statement:

	WARN_ON(lrbp->cmd);

Fix this warning by clearing lrbp->cmd from the abort handler.

Fixes 7a3e97b0dc4b ("[SCSI] ufshcd: UFS Host controller driver")
---
 drivers/scsi/ufs/ufshcd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/ufs/ufshcd.c +0 -0
index 3b4a714e2f68..d8a59258b1dc 100644

drivers/scsi/ufs/ufshcd.c static int ufshcd_abort(struct scsi_cmnd *cmd) · line 7075

Quoted 7 lines
drivers/scsi/ufs/ufshcd.c +1 -0
@@ -7069,6 +7069,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)
 		goto release;
 	}
 
+	lrbp->cmd = NULL;
 	err = SUCCESS;
 
 release:

Thanks for this patch! We are looking at the same issue as well recently.

#8 lore raw
In reply to Bart Van Assche

Bart,

Quoted 5 lines

That warning is triggered by the following statement:

	WARN_ON(lrbp->cmd);

Fix this warning by clearing lrbp->cmd from the abort handler.

Applied to 5.16/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#9 lore raw
In reply to Bart Van Assche
Quoted 12 lines · Bart Van Assche

The following has been observed on a test setup:

WARNING: CPU: 4 PID: 250 at drivers/scsi/ufs/ufshcd.c:2737 ufshcd_queuecommand+0x468/0x65c
Call trace:
 ufshcd_queuecommand+0x468/0x65c
 scsi_send_eh_cmnd+0x224/0x6a0
 scsi_eh_test_devices+0x248/0x418
 scsi_eh_ready_devs+0xc34/0xe58
 scsi_error_handler+0x204/0x80c
 kthread+0x150/0x1b4
 ret_from_fork+0x10/0x30
Quoted 1 line

[...]

Applied to 5.16/scsi-fixes, thanks!

[1/1] scsi: ufs: Improve SCSI abort handling

      https://git.kernel.org/mkp/scsi/c/3ff1f6b6ba6f
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
maintainer
#10 lore raw
Quoted 15 lines · Martin K. Petersen
Quoted 13 lines · Bart Van Assche

The following has been observed on a test setup:

WARNING: CPU: 4 PID: 250 at drivers/scsi/ufs/ufshcd.c:2737
ufshcd_queuecommand+0x468/0x65c
Call trace:
 ufshcd_queuecommand+0x468/0x65c
 scsi_send_eh_cmnd+0x224/0x6a0
 scsi_eh_test_devices+0x248/0x418
 scsi_eh_ready_devs+0xc34/0xe58
 scsi_error_handler+0x204/0x80c
 kthread+0x150/0x1b4
 ret_from_fork+0x10/0x30
Quoted 6 lines
Quoted 1 line

[...]

Applied to 5.16/scsi-fixes, thanks!

[1/1] scsi: ufs: Improve SCSI abort handling

      https://git.kernel.org/mkp/scsi/c/3ff1f6b6ba6f

OK, so now we have a conflict between fixes and queue. My impression is that the patch causing the conflict:

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

Actually supersedes this one, so I can simply drop the entirety of this patch in fixes, is that correct?

James

#11 lore raw
Quoted 6 lines · James Bottomley
Quoted 4 lines · Martin K. Petersen

Applied to 5.16/scsi-fixes, thanks!

[1/1] scsi: ufs: Improve SCSI abort handling

       https://git.kernel.org/mkp/scsi/c/3ff1f6b6ba6f
Quoted 7 lines

OK, so now we have a conflict between fixes and queue. My impression is that the patch causing the conflict:

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

Actually supersedes this one, so I can simply drop the entirety of this patch in fixes, is that correct?

Hi James,

Commit 1fbaa02dfd05 ("scsi: ufs: Improve SCSI abort handling further") is intended as an improvement for commit 3ff1f6b6ba6f ("scsi: ufs: core:
Improve SCSI abort handling"). Since commit 3ff1f6b6ba6f is already in Linus' tree I don't think that it can be dropped? A possible approach is to revert commit 3ff1f6b6ba6f before merging the mkp-scsi/for-next branch.

Thanks,

Bart.

maintainer
#12 lore raw
Quoted 16 lines · Bart Van Assche
Quoted 6 lines · James Bottomley
Quoted 4 lines · Martin K. Petersen

Applied to 5.16/scsi-fixes, thanks!

[1/1] scsi: ufs: Improve SCSI abort handling

       https://git.kernel.org/mkp/scsi/c/3ff1f6b6ba6f
Quoted 8 lines

OK, so now we have a conflict between fixes and queue. My impression
is that the patch causing the conflict:

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

Actually supersedes this one, so I can simply drop the entirety of this patch in fixes, is that correct?

Quoted 8 lines

Hi James,

Commit 1fbaa02dfd05 ("scsi: ufs: Improve SCSI abort handling further") is intended as an improvement for commit 3ff1f6b6ba6f ("scsi: ufs: core: Improve SCSI abort handling"). Since commit 3ff1f6b6ba6f is already in Linus' tree I don't think that it can be dropped? A possible approach is to revert commit 3ff1f6b6ba6f before merging the mkp-scsi/for-next branch.

I meant the effect of the fixes patch can be dropped in the merge commit. So the sole surviving code is from the misc tree. Like what I did at the top of the for-next branch:

https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git/commit/?h=for-next&id=014adbc9a838772b265834a55cd7b13eb2665d7e

James