From: David Laight <David.Laight@ACULAB.COM> To: 'Oliver Neukum' <oneukum@suse.com>, "gregKH@linuxfoundation.org" <gregKH@linuxfoundation.org>, "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org> Subject: UAS: fix alignment of scatter/gather segments Date: Mon, 29 Apr 2019 13:31:58 +0000 [thread overview] Message-ID: <f378babbf2f349e59d98a5ab99958d78@AcuMS.aculab.com> (raw) 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@suse.com> > --- > 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)
WARNING: multiple messages have this Message-ID (diff)
From: David Laight <David.Laight@ACULAB.COM> To: 'Oliver Neukum' <oneukum@suse.com>, "gregKH@linuxfoundation.org" <gregKH@linuxfoundation.org>, "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org> Subject: RE: [PATCH] UAS: fix alignment of scatter/gather segments Date: Mon, 29 Apr 2019 13:31:58 +0000 [thread overview] Message-ID: <f378babbf2f349e59d98a5ab99958d78@AcuMS.aculab.com> (raw) Message-ID: <20190429133158.WcLispNydQ0N-R-NceJCiOJA3YdnfWDXQ9jOwF-zWx4@z> (raw) In-Reply-To: <20190429122026.4249-1-oneukum@suse.com> 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@suse.com> > --- > 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)
next reply other threads:[~2019-04-29 13:31 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-04-29 13:31 David Laight [this message] 2019-04-29 13:31 ` [PATCH] UAS: fix alignment of scatter/gather segments David Laight -- strict thread matches above, loose matches on Subject: below -- 2019-04-30 14:39 Alan Stern 2019-04-30 14:39 ` [PATCH] " Alan Stern 2019-04-30 9:16 David Laight 2019-04-30 9:16 ` [PATCH] " David Laight 2019-04-29 19:42 Alan Stern 2019-04-29 19:42 ` [PATCH] " Alan Stern 2019-04-29 18:42 Oliver Neukum 2019-04-29 18:42 ` [PATCH] " Oliver Neukum 2019-04-29 17:55 Alan Stern 2019-04-29 17:55 ` [PATCH] " Alan Stern 2019-04-29 16:58 Oliver Neukum 2019-04-29 16:58 ` [PATCH] " Oliver Neukum 2019-04-29 16:08 Alan Stern 2019-04-29 16:08 ` [PATCH] " Alan Stern 2019-04-29 15:57 Oliver Neukum 2019-04-29 15:57 ` [PATCH] " Oliver Neukum 2019-04-29 15:06 David Laight 2019-04-29 15:06 ` [PATCH] " David Laight 2019-04-29 14:32 Oliver Neukum 2019-04-29 14:32 ` [PATCH] " Oliver Neukum 2019-04-29 14:19 David Laight 2019-04-29 14:19 ` [PATCH] " David Laight 2019-04-29 13:38 Oliver Neukum 2019-04-29 13:38 ` [PATCH] " Oliver Neukum 2019-04-29 12:20 Oliver Neukum 2019-04-29 12:20 ` [PATCH] " Oliver Neukum
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=f378babbf2f349e59d98a5ab99958d78@AcuMS.aculab.com \ --to=david.laight@aculab.com \ --cc=gregKH@linuxfoundation.org \ --cc=linux-usb@vger.kernel.org \ --cc=oneukum@suse.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.