Skip to contentSkip to conversation

scsi: ufs: Correct the lun used in eh_device_reset_handler() callback

PATCH Applied Can Guo 4 participants 5 messages Dec 28, 2020 – Jan 8, 2021 SCSI

lore
Share & tools
lore

Can Guo

author
#0 lore raw

PATCH 1/1 scsi: ufs: Correct the lun used in eh_device_reset_handler() callback

Users can initiate resets to specific SCSI device/target/host through IOCTL. When this happens, the SCSI cmd passed to eh_device/target/host _reset_handler() callbacks is initialized with a request whose tag is -1. So, in this case, it is not right for eh_device_reset_handler() callback to count on the lun get from hba->lrb[-1]. Fix it by getting lun from the SCSI device associated with the SCSI cmd.

drivers/scsi/ufs/ufshcd.c +4 -7
index 98093a5..d577cda 100644
@@ -6604,19 +6604,16 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd)
 {
 	struct Scsi_Host *host;
 	struct ufs_hba *hba;
-	unsigned int tag;
 	u32 pos;
 	int err;
-	u8 resp = 0xF;
-	struct ufshcd_lrb *lrbp;
+	u8 resp = 0xF, lun;
 	unsigned long flags;
 
 	host = cmd->device->host;
 	hba = shost_priv(host);
-	tag = cmd->request->tag;
 
-	lrbp = &hba->lrb[tag];
-	err = ufshcd_issue_tm_cmd(hba, lrbp->lun, 0, UFS_LOGICAL_RESET, &resp);
+	lun = ufshcd_scsi_to_upiu_lun(cmd->device->lun);
+	err = ufshcd_issue_tm_cmd(hba, lun, 0, UFS_LOGICAL_RESET, &resp);
 	if (err || resp != UPIU_TASK_MANAGEMENT_FUNC_COMPL) {
 		if (!err)
 			err = resp;
@@ -6625,7 +6622,7 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd)
 
 	/* clear the commands that were pending for corresponding LUN */
 	for_each_set_bit(pos, &hba->outstanding_reqs, hba->nutrs) {
-		if (hba->lrb[pos].lun == lrbp->lun) {
+		if (hba->lrb[pos].lun == lun) {
 			err = ufshcd_clear_cmd(hba, pos);
 			if (err)
 				break;
Signature · 1 line
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines

Users can initiate resets to specific SCSI device/target/host through IOCTL. When this happens, the SCSI cmd passed to eh_device/target/host _reset_handler() callbacks is initialized with a request whose tag is -1. So, in this case, it is not right for eh_device_reset_handler() callback to count on the lun get from hba->lrb[-1]. Fix it by getting lun from the SCSI device associated with the SCSI cmd.

Btw, am surprised to see that you guys are still using sg_reset instead of ufs-utils?

Thanks,
Avri

author
#2 lore raw
Quoted 8 lines · Avri Altman
Quoted 8 lines

Users can initiate resets to specific SCSI device/target/host through IOCTL. When this happens, the SCSI cmd passed to eh_device/target/host _reset_handler() callbacks is initialized with a request whose tag is -1.
So, in this case, it is not right for eh_device_reset_handler() callback to count on the lun get from hba->lrb[-1]. Fix it by getting lun from the SCSI device associated with the SCSI cmd.

Quoted 5 lines
Quoted 1 line

Btw, am surprised to see that you guys are still using sg_reset instead of ufs-utils?

Hi Avri,

We are not using any user layer tools at all. But I am confronted with many customers and tons of test teams inside and outside. I see all kinds of corner cases everyday, so not surprised at all.

Thanks,
Can Guo

Quoted 3 lines

Thanks,
Avri

Reviewed-by on v1 1/1
#3 lore raw
In reply to Can Guo
Quoted 8 lines · Can Guo

Users can initiate resets to specific SCSI device/target/host through IOCTL. When this happens, the SCSI cmd passed to eh_device/target/host _reset_handler() callbacks is initialized with a request whose tag is -1. So, in this case, it is not right for eh_device_reset_handler() callback to count on the lun get from hba->lrb[-1]. Fix it by getting lun from the SCSI device associated with the SCSI cmd.

#4 lore raw
In reply to Can Guo
Quoted 6 lines · Can Guo

Users can initiate resets to specific SCSI device/target/host through IOCTL. When this happens, the SCSI cmd passed to eh_device/target/host _reset_handler() callbacks is initialized with a request whose tag is -1. So, in this case, it is not right for eh_device_reset_handler() callback to count on the lun get from hba->lrb[-1]. Fix it by getting lun from the SCSI device associated with the SCSI cmd.

Applied to 5.11/scsi-fixes, thanks!

[1/1] scsi: ufs: Correct the lun used in eh_device_reset_handler() callback

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