diff mbox series

scsi: sd: Clear sdkp->protection_type when the disk isn't DIF in sd_read_protection_type()

Message ID 1578532344-101668-1-git-send-email-chenxiang66@hisilicon.com (mailing list archive)
State Mainlined
Commit 465f4edaecc6c37f81349233e84d46246bcac11a
Headers show
Series scsi: sd: Clear sdkp->protection_type when the disk isn't DIF in sd_read_protection_type() | expand

Commit Message

chenxiang Jan. 9, 2020, 1:12 a.m. UTC
From: Xiang Chen <chenxiang66@hisilicon.com>

For a SAS disk, format it as a SAS DIF disk, then if re-format SAS DIF disk to normal
SAS disk,it will report errors as follows:
...
[root@localhost ~]# [77380.678276] sd 4:0:0:0: [sda] tag#67 UNKNOWN(0x2003) Result:
hostbyte=0x07 driverbyte=0x00
[77380.686511] sd 4:0:0:0: [sda] tag#67 CDB: opcode=0x28 28 20 00 00 00 00 00 00 08 00
[77380.694139] blk_update_request: I/O error, dev sda, sector 0 op 0x0:(READ) flags 0x0
phys_seg 1 prio class 0
[77380.703929] Buffer I/O error on dev sda, logical block 0, async page read
[77380.790267] sd 4:0:0:0: [sda] tag#72 UNKNOWN(0x2003) Result: hostbyte=0x07
driverbyte=0x00
[77380.798496] sd 4:0:0:0: [sda] tag#72 CDB: opcode=0x28 28 20 00 00 00 00 00 00 08 00
[77380.806123] blk_update_request: I/O error, dev sda, sector 0 op 0x0:(READ) flags 0x0
phys_seg 1 prio class 0
[77380.815907] Buffer I/O error on dev sda, logical block 0, async page read
[77380.822676]  sda: unable to read partition table
...

When re-format SAS disk to normal SAS disk, it will send command READ_CAPACITY to get
protection info. In function sd_read_protection_type(), it checks whether the disk is
DIF from protection info, if not directly return. But if the disk was DIF disk, so
sdkp->protection_type of the disk is still be set. So the system will mistake the normal
disk as DIF disk(from CDB log 0x20 indicates there is DIF info with data).)
To avoid the issue, clear sdkp->protection_type when the disk is not DIF disk in
function sd_read_protection_type().

Fixes: fe542396da73 ("[SCSI] sd: Ensure we correctly disable devices with unknown protection type")
Signed-off-by: Xiang Chen <chenxiang66@hisilicon.com>
---
 drivers/scsi/sd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Martin K. Petersen Jan. 10, 2020, 6:36 a.m. UTC | #1
> For a SAS disk, format it as a SAS DIF disk, then if re-format SAS DIF
> disk to normal SAS disk,it will report errors as follows:

Clarified commit description. Applied to 5.5/scsi-fixes, thanks!
diff mbox series

Patch

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index cea6259..65ce10c 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2211,8 +2211,10 @@  static int sd_read_protection_type(struct scsi_disk *sdkp, unsigned char *buffer
 	u8 type;
 	int ret = 0;
 
-	if (scsi_device_protection(sdp) == 0 || (buffer[12] & 1) == 0)
+	if (scsi_device_protection(sdp) == 0 || (buffer[12] & 1) == 0) {
+		sdkp->protection_type = 0;
 		return ret;
+	}
 
 	type = ((buffer[12] >> 1) & 7) + 1; /* P_TYPE 0 = Type 1 */