Skip to content

Commit 5ddfe08

Browse files
hreineckeJames Bottomley
authored andcommitted
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: 09e2b0b ("scsi: rescan VPD attributes") Cc: <stable@vger.kernel.org> #v4.5+ Suggested-by: Alexander Duyck <aduyck@mirantis.com> Signed-off-by: Hannes Reinecke <hare@suse.com> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent f08bb1e commit 5ddfe08

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

drivers/scsi/scsi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,9 @@ void scsi_attach_vpd(struct scsi_device *sdev)
784784
int pg83_supported = 0;
785785
unsigned char __rcu *vpd_buf, *orig_vpd_buf = NULL;
786786

787-
if (sdev->skip_vpd_pages)
787+
if (!scsi_device_supports_vpd(sdev))
788788
return;
789+
789790
retry_pg0:
790791
vpd_buf = kmalloc(vpd_len, GFP_KERNEL);
791792
if (!vpd_buf)

drivers/scsi/sd.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,23 +2788,6 @@ static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer)
27882788
sdkp->ws10 = 1;
27892789
}
27902790

2791-
static int sd_try_extended_inquiry(struct scsi_device *sdp)
2792-
{
2793-
/* Attempt VPD inquiry if the device blacklist explicitly calls
2794-
* for it.
2795-
*/
2796-
if (sdp->try_vpd_pages)
2797-
return 1;
2798-
/*
2799-
* Although VPD inquiries can go to SCSI-2 type devices,
2800-
* some USB ones crash on receiving them, and the pages
2801-
* we currently ask for are for SPC-3 and beyond
2802-
*/
2803-
if (sdp->scsi_level > SCSI_SPC_2 && !sdp->skip_vpd_pages)
2804-
return 1;
2805-
return 0;
2806-
}
2807-
28082791
/**
28092792
* sd_revalidate_disk - called the first time a new disk is seen,
28102793
* performs disk spin up, read_capacity, etc.
@@ -2844,7 +2827,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
28442827
if (sdkp->media_present) {
28452828
sd_read_capacity(sdkp, buffer);
28462829

2847-
if (sd_try_extended_inquiry(sdp)) {
2830+
if (scsi_device_supports_vpd(sdp)) {
28482831
sd_read_block_provisioning(sdkp);
28492832
sd_read_block_limits(sdkp);
28502833
sd_read_block_characteristics(sdkp);

include/scsi/scsi_device.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,31 @@ static inline int scsi_device_tpgs(struct scsi_device *sdev)
516516
return sdev->inquiry ? (sdev->inquiry[5] >> 4) & 0x3 : 0;
517517
}
518518

519+
/**
520+
* scsi_device_supports_vpd - test if a device supports VPD pages
521+
* @sdev: the &struct scsi_device to test
522+
*
523+
* If the 'try_vpd_pages' flag is set it takes precedence.
524+
* Otherwise we will assume VPD pages are supported if the
525+
* SCSI level is at least SPC-3 and 'skip_vpd_pages' is not set.
526+
*/
527+
static inline int scsi_device_supports_vpd(struct scsi_device *sdev)
528+
{
529+
/* Attempt VPD inquiry if the device blacklist explicitly calls
530+
* for it.
531+
*/
532+
if (sdev->try_vpd_pages)
533+
return 1;
534+
/*
535+
* Although VPD inquiries can go to SCSI-2 type devices,
536+
* some USB ones crash on receiving them, and the pages
537+
* we currently ask for are for SPC-3 and beyond
538+
*/
539+
if (sdev->scsi_level > SCSI_SPC_2 && !sdev->skip_vpd_pages)
540+
return 1;
541+
return 0;
542+
}
543+
519544
#define MODULE_ALIAS_SCSI_DEVICE(type) \
520545
MODULE_ALIAS("scsi:t-" __stringify(type) "*")
521546
#define SCSI_DEVICE_MODALIAS_FMT "scsi:t-0x%02x"

0 commit comments

Comments
 (0)