Re: [PATCH] sd: Consider max_xfer_blocks if opt_xfer_blocks is unusable

From: Laurence Oberman
Date: Mon Mar 27 2017 - 12:07:56 EST




----- Original Message -----
> From: "Fam Zheng" <famz@xxxxxxxxxx>
> To: linux-kernel@xxxxxxxxxxxxxxx
> Cc: "Martin K. Petersen" <martin.petersen@xxxxxxxxxx>, famz@xxxxxxxxxx, linux-scsi@xxxxxxxxxxxxxxx, "James E.J.
> Bottomley" <jejb@xxxxxxxxxxxxxxxxxx>
> Sent: Monday, March 27, 2017 10:18:31 AM
> Subject: [PATCH] sd: Consider max_xfer_blocks if opt_xfer_blocks is unusable
>
> If device reports a small max_xfer_blocks and a zero opt_xfer_blocks, we
> end up using BLK_DEF_MAX_SECTORS, which is wrong and r/w of that size
> may get error.
>
> Fixes: ca369d51b3e ("block/sd: Fix device-imposed transfer length limits")
> Signed-off-by: Fam Zheng <famz@xxxxxxxxxx>
> ---
> drivers/scsi/sd.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index fcfeddc..e2e21ab 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -2957,6 +2957,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
> rw_max = logical_to_sectors(sdp, sdkp->opt_xfer_blocks);
> } else
> rw_max = BLK_DEF_MAX_SECTORS;
> + rw_max = min_not_zero(rw_max, dev_max);
>
> /* Combine with controller limits */
> q->limits.max_sectors = min(rw_max, queue_max_hw_sectors(q));
> --
> 2.9.3
>
>
Looks good to me and addresses the issue we faced.
FInal confirmation this change is OK to come from Martin or James.

Reviewed-by: Laurence Oberman <loberman@xxxxxxxxxx>