Commit 5ddfe085 authored by Hannes Reinecke's avatar Hannes Reinecke Committed by James Bottomley

scsi: Do not attach VPD to devices that don't support it

The patch "scsi: rescan VPD attributes" introduced a regression in which
devices that don't support VPD were being scanned for VPD attributes
anyway.  This could cause issues for some devices and should be avoided
so the check for scsi_level has been moved out of scsi_add_lun and into
scsi_attach_vpd so that all callers will not scan VPD for devices that
don't support it.

[mkp: Merge fix]

Fixes: 09e2b0b1 ("scsi: rescan VPD attributes")
Cc: <stable@vger.kernel.org> #v4.5+
Suggested-by: default avatarAlexander Duyck <aduyck@mirantis.com>
Signed-off-by: default avatarHannes Reinecke <hare@suse.com>
Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent f08bb1e0
...@@ -784,8 +784,9 @@ void scsi_attach_vpd(struct scsi_device *sdev) ...@@ -784,8 +784,9 @@ void scsi_attach_vpd(struct scsi_device *sdev)
int pg83_supported = 0; int pg83_supported = 0;
unsigned char __rcu *vpd_buf, *orig_vpd_buf = NULL; unsigned char __rcu *vpd_buf, *orig_vpd_buf = NULL;
if (sdev->skip_vpd_pages) if (!scsi_device_supports_vpd(sdev))
return; return;
retry_pg0: retry_pg0:
vpd_buf = kmalloc(vpd_len, GFP_KERNEL); vpd_buf = kmalloc(vpd_len, GFP_KERNEL);
if (!vpd_buf) if (!vpd_buf)
......
...@@ -2788,23 +2788,6 @@ static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer) ...@@ -2788,23 +2788,6 @@ static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer)
sdkp->ws10 = 1; sdkp->ws10 = 1;
} }
static int sd_try_extended_inquiry(struct scsi_device *sdp)
{
/* Attempt VPD inquiry if the device blacklist explicitly calls
* for it.
*/
if (sdp->try_vpd_pages)
return 1;
/*
* Although VPD inquiries can go to SCSI-2 type devices,
* some USB ones crash on receiving them, and the pages
* we currently ask for are for SPC-3 and beyond
*/
if (sdp->scsi_level > SCSI_SPC_2 && !sdp->skip_vpd_pages)
return 1;
return 0;
}
/** /**
* sd_revalidate_disk - called the first time a new disk is seen, * sd_revalidate_disk - called the first time a new disk is seen,
* performs disk spin up, read_capacity, etc. * performs disk spin up, read_capacity, etc.
...@@ -2844,7 +2827,7 @@ static int sd_revalidate_disk(struct gendisk *disk) ...@@ -2844,7 +2827,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
if (sdkp->media_present) { if (sdkp->media_present) {
sd_read_capacity(sdkp, buffer); sd_read_capacity(sdkp, buffer);
if (sd_try_extended_inquiry(sdp)) { if (scsi_device_supports_vpd(sdp)) {
sd_read_block_provisioning(sdkp); sd_read_block_provisioning(sdkp);
sd_read_block_limits(sdkp); sd_read_block_limits(sdkp);
sd_read_block_characteristics(sdkp); sd_read_block_characteristics(sdkp);
......
...@@ -516,6 +516,31 @@ static inline int scsi_device_tpgs(struct scsi_device *sdev) ...@@ -516,6 +516,31 @@ static inline int scsi_device_tpgs(struct scsi_device *sdev)
return sdev->inquiry ? (sdev->inquiry[5] >> 4) & 0x3 : 0; return sdev->inquiry ? (sdev->inquiry[5] >> 4) & 0x3 : 0;
} }
/**
* scsi_device_supports_vpd - test if a device supports VPD pages
* @sdev: the &struct scsi_device to test
*
* If the 'try_vpd_pages' flag is set it takes precedence.
* Otherwise we will assume VPD pages are supported if the
* SCSI level is at least SPC-3 and 'skip_vpd_pages' is not set.
*/
static inline int scsi_device_supports_vpd(struct scsi_device *sdev)
{
/* Attempt VPD inquiry if the device blacklist explicitly calls
* for it.
*/
if (sdev->try_vpd_pages)
return 1;
/*
* Although VPD inquiries can go to SCSI-2 type devices,
* some USB ones crash on receiving them, and the pages
* we currently ask for are for SPC-3 and beyond
*/
if (sdev->scsi_level > SCSI_SPC_2 && !sdev->skip_vpd_pages)
return 1;
return 0;
}
#define MODULE_ALIAS_SCSI_DEVICE(type) \ #define MODULE_ALIAS_SCSI_DEVICE(type) \
MODULE_ALIAS("scsi:t-" __stringify(type) "*") MODULE_ALIAS("scsi:t-" __stringify(type) "*")
#define SCSI_DEVICE_MODALIAS_FMT "scsi:t-0x%02x" #define SCSI_DEVICE_MODALIAS_FMT "scsi:t-0x%02x"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment