[2/3] sd: Reject optimal transfer length smaller than page size
diff mbox

Message ID 1450306433-20166-2-git-send-email-martin.petersen@oracle.com
State New
Headers show

Commit Message

Martin K. Petersen Dec. 16, 2015, 10:53 p.m. UTC
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>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
---
 drivers/scsi/sd.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Douglas Gilbert Dec. 17, 2015, 12:55 a.m. UTC | #1
On 15-12-16 05:53 PM, Martin K. Petersen wrote:
> 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>
> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
> ---
>   drivers/scsi/sd.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 3d22fc3e3c1a..4e08d1cd704d 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -2885,10 +2885,13 @@ static int sd_revalidate_disk(struct gendisk *disk)
>
>   	/*
>   	 * Use the device's preferred I/O size for reads and writes
> -	 * unless the reported value is unreasonably large (or garbage).
> +	 * unless the reported value is unreasonably small, large, or
> +	 * garbage.
>   	 */
> -	if (sdkp->opt_xfer_blocks && sdkp->opt_xfer_blocks <= dev_max &&
> -	    sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS)
> +	if (sdkp->opt_xfer_blocks &&
> +	    sdkp->opt_xfer_blocks <= dev_max &&
> +	    sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS &&
> +	    sdkp->opt_xfer_blocks * sdp->sector_size >= PAGE_CACHE_SIZE)
>   		rw_max = q->limits.io_opt =
>   			logical_to_sectors(sdp, sdkp->opt_xfer_blocks);
>   	else
>
and following that 'else' is:
                 rw_max = BLK_DEF_MAX_SECTORS;

and blkdev.h says:

enum blk_default_limits {
         BLK_MAX_SEGMENTS        = 128,
         BLK_SAFE_MAX_SECTORS    = 255,
         BLK_DEF_MAX_SECTORS     = 2560,
         BLK_MAX_SEGMENT_SIZE    = 65536,
         BLK_SEG_BOUNDARY_MASK   = 0xFFFFFFFFUL,
};


Reviewed-by: Douglas Gilbert <dgilbert@interlog.com>

--
To unsubscribe from this list: send the line "unsubscribe linux-block" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ewan D. Milne Dec. 17, 2015, 1:19 p.m. UTC | #2
On Wed, 2015-12-16 at 17:53 -0500, Martin K. Petersen wrote:
> 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>
> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
> ---
>  drivers/scsi/sd.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 3d22fc3e3c1a..4e08d1cd704d 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -2885,10 +2885,13 @@ static int sd_revalidate_disk(struct gendisk *disk)
>  
>  	/*
>  	 * Use the device's preferred I/O size for reads and writes
> -	 * unless the reported value is unreasonably large (or garbage).
> +	 * unless the reported value is unreasonably small, large, or
> +	 * garbage.
>  	 */
> -	if (sdkp->opt_xfer_blocks && sdkp->opt_xfer_blocks <= dev_max &&
> -	    sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS)
> +	if (sdkp->opt_xfer_blocks &&
> +	    sdkp->opt_xfer_blocks <= dev_max &&
> +	    sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS &&
> +	    sdkp->opt_xfer_blocks * sdp->sector_size >= PAGE_CACHE_SIZE)
>  		rw_max = q->limits.io_opt =
>  			logical_to_sectors(sdp, sdkp->opt_xfer_blocks);
>  	else

Reviewed-by: Ewan D. Milne <emilne@redhat.com>


--
To unsubscribe from this list: send the line "unsubscribe linux-block" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 3d22fc3e3c1a..4e08d1cd704d 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2885,10 +2885,13 @@  static int sd_revalidate_disk(struct gendisk *disk)
 
 	/*
 	 * Use the device's preferred I/O size for reads and writes
-	 * unless the reported value is unreasonably large (or garbage).
+	 * unless the reported value is unreasonably small, large, or
+	 * garbage.
 	 */
-	if (sdkp->opt_xfer_blocks && sdkp->opt_xfer_blocks <= dev_max &&
-	    sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS)
+	if (sdkp->opt_xfer_blocks &&
+	    sdkp->opt_xfer_blocks <= dev_max &&
+	    sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS &&
+	    sdkp->opt_xfer_blocks * sdp->sector_size >= PAGE_CACHE_SIZE)
 		rw_max = q->limits.io_opt =
 			logical_to_sectors(sdp, sdkp->opt_xfer_blocks);
 	else