linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: sd: Clear sdkp->protection_type when the disk isn't DIF in sd_read_protection_type()
@ 2020-01-09  1:12 chenxiang
  2020-01-10  6:36 ` Martin K. Petersen
  0 siblings, 1 reply; 2+ messages in thread
From: chenxiang @ 2020-01-09  1:12 UTC (permalink / raw)
  To: jejb, martin.petersen; +Cc: linuxarm, linux-scsi, john.garry, Xiang Chen

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(-)

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 */
 
-- 
2.8.1


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

* Re: [PATCH] scsi: sd: Clear sdkp->protection_type when the disk isn't DIF in sd_read_protection_type()
  2020-01-09  1:12 [PATCH] scsi: sd: Clear sdkp->protection_type when the disk isn't DIF in sd_read_protection_type() chenxiang
@ 2020-01-10  6:36 ` Martin K. Petersen
  0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2020-01-10  6:36 UTC (permalink / raw)
  To: chenxiang; +Cc: jejb, martin.petersen, linuxarm, linux-scsi, john.garry


> 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!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2020-01-10  6:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-09  1:12 [PATCH] scsi: sd: Clear sdkp->protection_type when the disk isn't DIF in sd_read_protection_type() chenxiang
2020-01-10  6:36 ` 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).