RE: [PATCH] UAS: fix alignment of scatter/gather segments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Oliver Neukum
> Sent: 29 April 2019 13:20
> This is the UAS version of
> 
> 747668dbc061b3e62bc1982767a3a1f9815fcf0e
> usb-storage: Set virt_boundary_mask to avoid SG overflows
> 
> We are not as likely to be vulnerable as storage, as it is unlikelier
> that UAS is run over a controller without native support for SG,
> but the issue exists.
> 
> Signed-off-by: Oliver Neukum <oneukum@xxxxxxxx>
> ---
>  drivers/usb/storage/uas.c | 26 ++++++++++++--------------
>  1 file changed, 12 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
> index 6d71b8fff9df..ec9c1c7bb156 100644
> --- a/drivers/usb/storage/uas.c
> +++ b/drivers/usb/storage/uas.c
> @@ -789,24 +789,22 @@ static int uas_slave_alloc(struct scsi_device *sdev)
>  {
>  	struct uas_dev_info *devinfo =
>  		(struct uas_dev_info *)sdev->host->hostdata;
> +	int maxp;
> 
>  	sdev->hostdata = devinfo;
> 
>  	/*
> -	 * USB has unusual DMA-alignment requirements: Although the
> -	 * starting address of each scatter-gather element doesn't matter,
> -	 * the length of each element except the last must be divisible
> -	 * by the Bulk maxpacket value.  There's currently no way to
> -	 * express this by block-layer constraints, so we'll cop out
> -	 * and simply require addresses to be aligned at 512-byte
> -	 * boundaries.  This is okay since most block I/O involves
> -	 * hardware sectors that are multiples of 512 bytes in length,
> -	 * and since host controllers up through USB 2.0 have maxpacket
> -	 * values no larger than 512.
> -	 *
> -	 * But it doesn't suffice for Wireless USB, where Bulk maxpacket
> -	 * values can be as large as 2048.  To make that work properly
> -	 * will require changes to the block layer.
> +	 * USB has unusual scatter-gather requirements: the length of each
> +	 * scatterlist element except the last must be divisible by the
> +	 * Bulk maxpacket value.  Fortunately this value is always a
> +	 * power of 2.  Inform the block layer about this requirement.
> +	 */

That isn't the correct restriction for XHCI.
It has its own perverse restrictions.
I think they are all handled within the xhci driver.

	David


> +
> +	maxp = usb_maxpacket(devinfo->udev, devinfo->data_in_pipe, 0);
> +	blk_queue_virt_boundary(sdev->request_queue, maxp - 1);
> +
> +	/*
> +	 * This one is for the controllers. We assume 512 is always good.
>  	 */
>  	blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
> 
> --
> 2.16.4

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux