Skip to content

Commit 9c1d9c2

Browse files
sd: Reject optimal transfer length smaller than page size
Eryu Guan reported that loading scsi_debug would fail. This turned out to be caused by scsi_debug reporting an optimal I/O size of 32KB which is smaller than the 64KB page size on the PowerPC system in question. Add a check to ensure that we only use the device-reported OPTIMAL TRANSFER LENGTH if it is bigger than or equal to the page cache size. Reported-by: Eryu Guan <guaneryu@gmail.com> Reported-by: Ming Lei <tom.leiming@gmail.com> Reviewed-by: Douglas Gilbert <dgilbert@interlog.com> Reviewed-by: Ewan Milne <emilne@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 1c69d3b commit 9c1d9c2

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

drivers/scsi/sd.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,10 +2885,13 @@ static int sd_revalidate_disk(struct gendisk *disk)
28852885

28862886
/*
28872887
* Use the device's preferred I/O size for reads and writes
2888-
* unless the reported value is unreasonably large (or garbage).
2888+
* unless the reported value is unreasonably small, large, or
2889+
* garbage.
28892890
*/
2890-
if (sdkp->opt_xfer_blocks && sdkp->opt_xfer_blocks <= dev_max &&
2891-
sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS)
2891+
if (sdkp->opt_xfer_blocks &&
2892+
sdkp->opt_xfer_blocks <= dev_max &&
2893+
sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS &&
2894+
sdkp->opt_xfer_blocks * sdp->sector_size >= PAGE_CACHE_SIZE)
28922895
rw_max = q->limits.io_opt =
28932896
logical_to_sectors(sdp, sdkp->opt_xfer_blocks);
28942897
else

0 commit comments

Comments
 (0)