Linux USB
 help / color / mirror / Atom feed
* UAS: fix alignment of scatter/gather segments
@ 2019-04-29 12:20 Oliver Neukum
  2019-04-29 12:20 ` [PATCH] " Oliver Neukum
  2019-04-29 13:31 ` David Laight
  0 siblings, 2 replies; 28+ messages in thread
From: Oliver Neukum @ 2019-04-29 12:20 UTC (permalink / raw)
  To: gregKH, linux-usb; +Cc: Oliver Neukum

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.
+	 */
+
+	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));
 

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

end of thread, other threads:[~2019-04-30 14:39 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-29 12:20 UAS: fix alignment of scatter/gather segments Oliver Neukum
2019-04-29 12:20 ` [PATCH] " Oliver Neukum
2019-04-29 13:31 ` David Laight
2019-04-29 13:31   ` [PATCH] " David Laight
2019-04-29 13:38   ` Oliver Neukum
2019-04-29 13:38     ` [PATCH] " Oliver Neukum
2019-04-29 14:19     ` David Laight
2019-04-29 14:19       ` [PATCH] " David Laight
2019-04-29 14:32       ` Oliver Neukum
2019-04-29 14:32         ` [PATCH] " Oliver Neukum
2019-04-29 15:06         ` David Laight
2019-04-29 15:06           ` [PATCH] " David Laight
2019-04-29 15:57           ` Oliver Neukum
2019-04-29 15:57             ` [PATCH] " Oliver Neukum
2019-04-29 16:08             ` Alan Stern
2019-04-29 16:08               ` [PATCH] " Alan Stern
2019-04-29 16:58               ` Oliver Neukum
2019-04-29 16:58                 ` [PATCH] " Oliver Neukum
2019-04-29 17:55                 ` Alan Stern
2019-04-29 17:55                   ` [PATCH] " Alan Stern
2019-04-29 18:42                   ` Oliver Neukum
2019-04-29 18:42                     ` [PATCH] " Oliver Neukum
2019-04-29 19:42                     ` Alan Stern
2019-04-29 19:42                       ` [PATCH] " Alan Stern
2019-04-30  9:16                   ` David Laight
2019-04-30  9:16                     ` [PATCH] " David Laight
2019-04-30 14:39                     ` Alan Stern
2019-04-30 14:39                       ` [PATCH] " Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox