Skip to content

Commit b5fc07a

Browse files
scsi: core: Consult supported VPD page list prior to fetching page
Commit c92a6b5 ("scsi: core: Query VPD size before getting full page") removed the logic which checks whether a VPD page is present on the supported pages list before asking for the page itself. That was done because SPC helpfully states "The Supported VPD Pages VPD page list may or may not include all the VPD pages that are able to be returned by the device server". Testing had revealed a few devices that supported some of the 0xBn pages but didn't actually list them in page 0. Julian Sikorski bisected a problem with his drive resetting during discovery to the commit above. As it turns out, this particular drive firmware will crash if we attempt to fetch page 0xB9. Various approaches were attempted to work around this. In the end, reinstating the logic that consults VPD page 0 before fetching any other page was the path of least resistance. A firmware update for the devices which originally compelled us to remove the check has since been released. Link: https://lore.kernel.org/r/[email protected] Fixes: c92a6b5 ("scsi: core: Query VPD size before getting full page") Cc: [email protected] Cc: Bart Van Assche <[email protected]> Reported-by: Julian Sikorski <[email protected]> Tested-by: Julian Sikorski <[email protected]> Reviewed-by: Lee Duncan <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 321da3d commit b5fc07a

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

drivers/scsi/scsi.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,39 @@ static int scsi_vpd_inquiry(struct scsi_device *sdev, unsigned char *buffer,
328328
return result + 4;
329329
}
330330

331+
enum scsi_vpd_parameters {
332+
SCSI_VPD_HEADER_SIZE = 4,
333+
SCSI_VPD_LIST_SIZE = 36,
334+
};
335+
331336
static int scsi_get_vpd_size(struct scsi_device *sdev, u8 page)
332337
{
333-
unsigned char vpd_header[SCSI_VPD_HEADER_SIZE] __aligned(4);
338+
unsigned char vpd[SCSI_VPD_LIST_SIZE] __aligned(4);
334339
int result;
335340

336341
if (sdev->no_vpd_size)
337342
return SCSI_DEFAULT_VPD_LEN;
338343

344+
/*
345+
* Fetch the supported pages VPD and validate that the requested page
346+
* number is present.
347+
*/
348+
if (page != 0) {
349+
result = scsi_vpd_inquiry(sdev, vpd, 0, sizeof(vpd));
350+
if (result < SCSI_VPD_HEADER_SIZE)
351+
return 0;
352+
353+
result -= SCSI_VPD_HEADER_SIZE;
354+
if (!memchr(&vpd[SCSI_VPD_HEADER_SIZE], page, result))
355+
return 0;
356+
}
339357
/*
340358
* Fetch the VPD page header to find out how big the page
341359
* is. This is done to prevent problems on legacy devices
342360
* which can not handle allocation lengths as large as
343361
* potentially requested by the caller.
344362
*/
345-
result = scsi_vpd_inquiry(sdev, vpd_header, page, sizeof(vpd_header));
363+
result = scsi_vpd_inquiry(sdev, vpd, page, SCSI_VPD_HEADER_SIZE);
346364
if (result < 0)
347365
return 0;
348366

include/scsi/scsi_device.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ struct scsi_vpd {
100100
unsigned char data[];
101101
};
102102

103-
enum scsi_vpd_parameters {
104-
SCSI_VPD_HEADER_SIZE = 4,
105-
};
106-
107103
struct scsi_device {
108104
struct Scsi_Host *host;
109105
struct request_queue *request_queue;

0 commit comments

Comments
 (0)