All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sd: Consider max_xfer_blocks if opt_xfer_blocks is unusable
@ 2017-03-27 14:18 Fam Zheng
  2017-03-27 16:06 ` Laurence Oberman
  2017-03-28  2:11 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Fam Zheng @ 2017-03-27 14:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: Martin K. Petersen, famz, linux-scsi, James E.J. Bottomley

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@redhat.com>
---
 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] sd: Consider max_xfer_blocks if opt_xfer_blocks is unusable
  2017-03-27 14:18 [PATCH] sd: Consider max_xfer_blocks if opt_xfer_blocks is unusable Fam Zheng
@ 2017-03-27 16:06 ` Laurence Oberman
  2017-03-28  2:11 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Laurence Oberman @ 2017-03-27 16:06 UTC (permalink / raw)
  To: Fam Zheng
  Cc: linux-kernel, Martin K. Petersen, linux-scsi, James E.J. Bottomley



----- Original Message -----
> From: "Fam Zheng" <famz@redhat.com>
> To: linux-kernel@vger.kernel.org
> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>, famz@redhat.com, linux-scsi@vger.kernel.org, "James E.J.
> Bottomley" <jejb@linux.vnet.ibm.com>
> 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@redhat.com>
> ---
>  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@redhat.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] sd: Consider max_xfer_blocks if opt_xfer_blocks is unusable
  2017-03-27 14:18 [PATCH] sd: Consider max_xfer_blocks if opt_xfer_blocks is unusable Fam Zheng
  2017-03-27 16:06 ` Laurence Oberman
@ 2017-03-28  2:11 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2017-03-28  2:11 UTC (permalink / raw)
  To: Fam Zheng
  Cc: linux-kernel, Martin K. Petersen, linux-scsi, James E.J. Bottomley

Fam Zheng <famz@redhat.com> writes:

Hi Fam,

> --- 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);

rw_max is in sectors, dev_max is in logical blocks.

>  
>  	/* Combine with controller limits */
>  	q->limits.max_sectors = min(rw_max, queue_max_hw_sectors(q));

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-28  2:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-27 14:18 [PATCH] sd: Consider max_xfer_blocks if opt_xfer_blocks is unusable Fam Zheng
2017-03-27 16:06 ` Laurence Oberman
2017-03-28  2:11 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.