* [PATCHv2] UAS: fix alignment of scatter/gather segments
@ 2019-04-30 10:21 ` Oliver Neukum
0 siblings, 0 replies; 6+ messages in thread
From: Oliver Neukum @ 2019-04-30 10:21 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.
The issue has been existing since the inception of the driver.
Fixes: 115bb1ffa54ac ("USB: Add UAS driver")
Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
drivers/usb/storage/uas.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 6d71b8fff9df..3856f34b89b8 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -789,24 +789,33 @@ 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.
+ * We have two requirements here. We must satisfy the requirements
+ * of the physical HC and the demands of the protocol, as we
+ * definitely want no additional memory allocation in this path
+ * ruling out using bounce buffers.
*
- * 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.
+ * For a transmission on USB to continue we must never send
+ * a package that is smaller than maxpacket. Hence the length of each
+ * scatterlist element except the last must be divisible by the
+ * Bulk maxpacket value.
+ * If the HC does not ensure that through SG,
+ * the upper layer must do that. We must assume nothing
+ * about the capabilities off the HC, so we use the most
+ * pessimistic requirement.
+ */
+
+ maxp = usb_maxpacket(devinfo->udev, devinfo->data_in_pipe, 0);
+ blk_queue_virt_boundary(sdev->request_queue, maxp - 1);
+
+ /*
+ * The protocol has no requirements on alignment in the strict sense.
+ * Controllers may or may not have alignment restrictions.
+ * As this is not exported, we use an extremely conservative guess.
*/
blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCHv2] UAS: fix alignment of scatter/gather segments
@ 2019-04-30 10:21 ` Oliver Neukum
0 siblings, 0 replies; 6+ messages in thread
From: Oliver Neukum @ 2019-04-30 10:21 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.
The issue has been existing since the inception of the driver.
Fixes: 115bb1ffa54ac ("USB: Add UAS driver")
Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
drivers/usb/storage/uas.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 6d71b8fff9df..3856f34b89b8 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -789,24 +789,33 @@ 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.
+ * We have two requirements here. We must satisfy the requirements
+ * of the physical HC and the demands of the protocol, as we
+ * definitely want no additional memory allocation in this path
+ * ruling out using bounce buffers.
*
- * 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.
+ * For a transmission on USB to continue we must never send
+ * a package that is smaller than maxpacket. Hence the length of each
+ * scatterlist element except the last must be divisible by the
+ * Bulk maxpacket value.
+ * If the HC does not ensure that through SG,
+ * the upper layer must do that. We must assume nothing
+ * about the capabilities off the HC, so we use the most
+ * pessimistic requirement.
+ */
+
+ maxp = usb_maxpacket(devinfo->udev, devinfo->data_in_pipe, 0);
+ blk_queue_virt_boundary(sdev->request_queue, maxp - 1);
+
+ /*
+ * The protocol has no requirements on alignment in the strict sense.
+ * Controllers may or may not have alignment restrictions.
+ * As this is not exported, we use an extremely conservative guess.
*/
blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
--
2.16.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCHv2] UAS: fix alignment of scatter/gather segments
@ 2019-04-30 10:32 ` Greg KH
0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2019-04-30 10:32 UTC (permalink / raw)
To: Oliver Neukum; +Cc: linux-usb
On Tue, Apr 30, 2019 at 12:21:45PM +0200, Oliver Neukum wrote:
> 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.
> The issue has been existing since the inception of the driver.
>
> Fixes: 115bb1ffa54ac ("USB: Add UAS driver")
Shouldn't this be:
Fixes: 115bb1ffa54c ("USB: Add UAS driver")
The sha1 you put here isn't valid :(
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCHv2] UAS: fix alignment of scatter/gather segments
@ 2019-04-30 10:32 ` Greg KH
0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2019-04-30 10:32 UTC (permalink / raw)
To: Oliver Neukum; +Cc: linux-usb
On Tue, Apr 30, 2019 at 12:21:45PM +0200, Oliver Neukum wrote:
> 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.
> The issue has been existing since the inception of the driver.
>
> Fixes: 115bb1ffa54ac ("USB: Add UAS driver")
Shouldn't this be:
Fixes: 115bb1ffa54c ("USB: Add UAS driver")
The sha1 you put here isn't valid :(
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCHv2] UAS: fix alignment of scatter/gather segments
@ 2019-04-30 14:50 ` Alan Stern
0 siblings, 0 replies; 6+ messages in thread
From: Alan Stern @ 2019-04-30 14:50 UTC (permalink / raw)
To: Oliver Neukum; +Cc: gregKH, linux-usb
On Tue, 30 Apr 2019, Oliver Neukum wrote:
> 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
s/unlikelier/less likely/
A matter of English grammatical style -- it might be even better to
write: "... as UAS is less likely to run ...".
> that UAS is run over a controller without native support for SG,
> but the issue exists.
> The issue has been existing since the inception of the driver.
>
> Fixes: 115bb1ffa54ac ("USB: Add UAS driver")
> Signed-off-by: Oliver Neukum <oneukum@suse.com>
> ---
> drivers/usb/storage/uas.c | 35 ++++++++++++++++++++++-------------
> 1 file changed, 22 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
> index 6d71b8fff9df..3856f34b89b8 100644
> --- a/drivers/usb/storage/uas.c
> +++ b/drivers/usb/storage/uas.c
> @@ -789,24 +789,33 @@ 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.
> + * We have two requirements here. We must satisfy the requirements
> + * of the physical HC and the demands of the protocol, as we
> + * definitely want no additional memory allocation in this path
> + * ruling out using bounce buffers.
> *
> - * 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.
> + * For a transmission on USB to continue we must never send
> + * a package that is smaller than maxpacket. Hence the length of each
> + * scatterlist element except the last must be divisible by the
> + * Bulk maxpacket value.
Spaces vs. tabs.
Alan Stern
> + * If the HC does not ensure that through SG,
> + * the upper layer must do that. We must assume nothing
> + * about the capabilities off the HC, so we use the most
> + * pessimistic requirement.
> + */
> +
> + maxp = usb_maxpacket(devinfo->udev, devinfo->data_in_pipe, 0);
> + blk_queue_virt_boundary(sdev->request_queue, maxp - 1);
> +
> + /*
> + * The protocol has no requirements on alignment in the strict sense.
> + * Controllers may or may not have alignment restrictions.
> + * As this is not exported, we use an extremely conservative guess.
> */
> blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCHv2] UAS: fix alignment of scatter/gather segments
@ 2019-04-30 14:50 ` Alan Stern
0 siblings, 0 replies; 6+ messages in thread
From: Alan Stern @ 2019-04-30 14:50 UTC (permalink / raw)
To: Oliver Neukum; +Cc: gregKH, linux-usb
On Tue, 30 Apr 2019, Oliver Neukum wrote:
> 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
s/unlikelier/less likely/
A matter of English grammatical style -- it might be even better to
write: "... as UAS is less likely to run ...".
> that UAS is run over a controller without native support for SG,
> but the issue exists.
> The issue has been existing since the inception of the driver.
>
> Fixes: 115bb1ffa54ac ("USB: Add UAS driver")
> Signed-off-by: Oliver Neukum <oneukum@suse.com>
> ---
> drivers/usb/storage/uas.c | 35 ++++++++++++++++++++++-------------
> 1 file changed, 22 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
> index 6d71b8fff9df..3856f34b89b8 100644
> --- a/drivers/usb/storage/uas.c
> +++ b/drivers/usb/storage/uas.c
> @@ -789,24 +789,33 @@ 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.
> + * We have two requirements here. We must satisfy the requirements
> + * of the physical HC and the demands of the protocol, as we
> + * definitely want no additional memory allocation in this path
> + * ruling out using bounce buffers.
> *
> - * 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.
> + * For a transmission on USB to continue we must never send
> + * a package that is smaller than maxpacket. Hence the length of each
> + * scatterlist element except the last must be divisible by the
> + * Bulk maxpacket value.
Spaces vs. tabs.
Alan Stern
> + * If the HC does not ensure that through SG,
> + * the upper layer must do that. We must assume nothing
> + * about the capabilities off the HC, so we use the most
> + * pessimistic requirement.
> + */
> +
> + maxp = usb_maxpacket(devinfo->udev, devinfo->data_in_pipe, 0);
> + blk_queue_virt_boundary(sdev->request_queue, maxp - 1);
> +
> + /*
> + * The protocol has no requirements on alignment in the strict sense.
> + * Controllers may or may not have alignment restrictions.
> + * As this is not exported, we use an extremely conservative guess.
> */
> blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-04-30 14:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-30 14:50 [PATCHv2] UAS: fix alignment of scatter/gather segments Alan Stern
2019-04-30 14:50 ` Alan Stern
-- strict thread matches above, loose matches on Subject: below --
2019-04-30 10:32 Greg Kroah-Hartman
2019-04-30 10:32 ` Greg KH
2019-04-30 10:21 Oliver Neukum
2019-04-30 10:21 ` Oliver Neukum
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.