]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/uas-fix-alignment-of-scatter-gather-segments.patch
4.4-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.4 / 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 | 38 ++++++++++++++++++++++++--------------
27 1 file changed, 24 insertions(+), 14 deletions(-)
28
29 --- a/drivers/usb/storage/uas.c
30 +++ b/drivers/usb/storage/uas.c
31 @@ -772,23 +772,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 - /* USB has unusual DMA-alignment requirements: Although the
40 - * starting address of each scatter-gather element doesn't matter,
41 - * the length of each element except the last must be divisible
42 - * by the Bulk maxpacket value. There's currently no way to
43 - * express this by block-layer constraints, so we'll cop out
44 - * and simply require addresses to be aligned at 512-byte
45 - * boundaries. This is okay since most block I/O involves
46 - * hardware sectors that are multiples of 512 bytes in length,
47 - * and since host controllers up through USB 2.0 have maxpacket
48 - * values no larger than 512.
49 - *
50 - * But it doesn't suffice for Wireless USB, where Bulk maxpacket
51 - * values can be as large as 2048. To make that work properly
52 - * will require changes to the block layer.
53 + /*
54 + * We have two requirements here. We must satisfy the requirements
55 + * of the physical HC and the demands of the protocol, as we
56 + * definitely want no additional memory allocation in this path
57 + * ruling out using bounce buffers.
58 + *
59 + * For a transmission on USB to continue we must never send
60 + * a package that is smaller than maxpacket. Hence the length of each
61 + * scatterlist element except the last must be divisible by the
62 + * Bulk maxpacket value.
63 + * If the HC does not ensure that through SG,
64 + * the upper layer must do that. We must assume nothing
65 + * about the capabilities off the HC, so we use the most
66 + * pessimistic requirement.
67 + */
68 +
69 + maxp = usb_maxpacket(devinfo->udev, devinfo->data_in_pipe, 0);
70 + blk_queue_virt_boundary(sdev->request_queue, maxp - 1);
71 +
72 + /*
73 + * The protocol has no requirements on alignment in the strict sense.
74 + * Controllers may or may not have alignment restrictions.
75 + * As this is not exported, we use an extremely conservative guess.
76 */
77 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
78