]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/5.0.15/uas-fix-alignment-of-scatter-gather-segments.patch
Linux 4.19.42
[thirdparty/kernel/stable-queue.git] / releases / 5.0.15 / uas-fix-alignment-of-scatter-gather-segments.patch
1 From 3ae62a42090f1ed48e2313ed256a1182a85fb575 Mon Sep 17 00:00:00 2001
2 From: Oliver Neukum <oneukum@suse.com>
3 Date: Tue, 30 Apr 2019 12:21:45 +0200
4 Subject: UAS: fix alignment of scatter/gather segments
5
6 From: Oliver Neukum <oneukum@suse.com>
7
8 commit 3ae62a42090f1ed48e2313ed256a1182a85fb575 upstream.
9
10 This is the UAS version of
11
12 747668dbc061b3e62bc1982767a3a1f9815fcf0e
13 usb-storage: Set virt_boundary_mask to avoid SG overflows
14
15 We are not as likely to be vulnerable as storage, as it is unlikelier
16 that UAS is run over a controller without native support for SG,
17 but the issue exists.
18 The issue has been existing since the inception of the driver.
19
20 Fixes: 115bb1ffa54c ("USB: Add UAS driver")
21 Signed-off-by: Oliver Neukum <oneukum@suse.com>
22 Cc: stable <stable@vger.kernel.org>
23 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24
25 ---
26 drivers/usb/storage/uas.c | 35 ++++++++++++++++++++++-------------
27 1 file changed, 22 insertions(+), 13 deletions(-)
28
29 --- a/drivers/usb/storage/uas.c
30 +++ b/drivers/usb/storage/uas.c
31 @@ -796,24 +796,33 @@ static int uas_slave_alloc(struct scsi_d
32 {
33 struct uas_dev_info *devinfo =
34 (struct uas_dev_info *)sdev->host->hostdata;
35 + int maxp;
36
37 sdev->hostdata = devinfo;
38
39 /*
40 - * USB has unusual DMA-alignment requirements: Although the
41 - * starting address of each scatter-gather element doesn't matter,
42 - * the length of each element except the last must be divisible
43 - * by the Bulk maxpacket value. There's currently no way to
44 - * express this by block-layer constraints, so we'll cop out
45 - * and simply require addresses to be aligned at 512-byte
46 - * boundaries. This is okay since most block I/O involves
47 - * hardware sectors that are multiples of 512 bytes in length,
48 - * and since host controllers up through USB 2.0 have maxpacket
49 - * values no larger than 512.
50 + * We have two requirements here. We must satisfy the requirements
51 + * of the physical HC and the demands of the protocol, as we
52 + * definitely want no additional memory allocation in this path
53 + * ruling out using bounce buffers.
54 *
55 - * But it doesn't suffice for Wireless USB, where Bulk maxpacket
56 - * values can be as large as 2048. To make that work properly
57 - * will require changes to the block layer.
58 + * For a transmission on USB to continue we must never send
59 + * a package that is smaller than maxpacket. Hence the length of each
60 + * scatterlist element except the last must be divisible by the
61 + * Bulk maxpacket value.
62 + * If the HC does not ensure that through SG,
63 + * the upper layer must do that. We must assume nothing
64 + * about the capabilities off the HC, so we use the most
65 + * pessimistic requirement.
66 + */
67 +
68 + maxp = usb_maxpacket(devinfo->udev, devinfo->data_in_pipe, 0);
69 + blk_queue_virt_boundary(sdev->request_queue, maxp - 1);
70 +
71 + /*
72 + * The protocol has no requirements on alignment in the strict sense.
73 + * Controllers may or may not have alignment restrictions.
74 + * As this is not exported, we use an extremely conservative guess.
75 */
76 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
77