]>
Commit | Line | Data |
---|---|---|
7c14fc92 GKH |
1 | From 747668dbc061b3e62bc1982767a3a1f9815fcf0e Mon Sep 17 00:00:00 2001 |
2 | From: Alan Stern <stern@rowland.harvard.edu> | |
3 | Date: Mon, 15 Apr 2019 13:19:25 -0400 | |
4 | Subject: usb-storage: Set virt_boundary_mask to avoid SG overflows | |
5 | ||
6 | From: Alan Stern <stern@rowland.harvard.edu> | |
7 | ||
8 | commit 747668dbc061b3e62bc1982767a3a1f9815fcf0e upstream. | |
9 | ||
10 | The USB subsystem has always had an unusual requirement for its | |
11 | scatter-gather transfers: Each element in the scatterlist (except the | |
12 | last one) must have a length divisible by the bulk maxpacket size. | |
13 | This is a particular issue for USB mass storage, which uses SG lists | |
14 | created by the block layer rather than setting up its own. | |
15 | ||
16 | So far we have scraped by okay because most devices have a logical | |
17 | block size of 512 bytes or larger, and the bulk maxpacket sizes for | |
18 | USB 2 and below are all <= 512. However, USB 3 has a bulk maxpacket | |
19 | size of 1024. Since the xhci-hcd driver includes native SG support, | |
20 | this hasn't mattered much. But now people are trying to use USB-3 | |
21 | mass storage devices with USBIP, and the vhci-hcd driver currently | |
22 | does not have full SG support. | |
23 | ||
24 | The result is an overflow error, when the driver attempts to implement | |
25 | an SG transfer of 63 512-byte blocks as a single | |
26 | 3584-byte (7 blocks) transfer followed by seven 4096-byte (8 blocks) | |
27 | transfers. The device instead sends 31 1024-byte packets followed by | |
28 | a 512-byte packet, and this overruns the first SG buffer. | |
29 | ||
30 | Ideally this would be fixed by adding better SG support to vhci-hcd. | |
31 | But for now it appears we can work around the problem by | |
32 | asking the block layer to respect the maxpacket limitation, through | |
33 | the use of the virt_boundary_mask. | |
34 | ||
35 | Signed-off-by: Alan Stern <stern@rowland.harvard.edu> | |
36 | Reported-by: Seth Bollinger <Seth.Bollinger@digi.com> | |
37 | Tested-by: Seth Bollinger <Seth.Bollinger@digi.com> | |
38 | CC: Ming Lei <tom.leiming@gmail.com> | |
39 | Cc: stable <stable@vger.kernel.org> | |
40 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
41 | ||
42 | --- | |
43 | drivers/usb/storage/scsiglue.c | 26 ++++++++++++-------------- | |
44 | 1 file changed, 12 insertions(+), 14 deletions(-) | |
45 | ||
46 | --- a/drivers/usb/storage/scsiglue.c | |
47 | +++ b/drivers/usb/storage/scsiglue.c | |
48 | @@ -81,6 +81,7 @@ static const char* host_info(struct Scsi | |
49 | static int slave_alloc (struct scsi_device *sdev) | |
50 | { | |
51 | struct us_data *us = host_to_us(sdev->host); | |
52 | + int maxp; | |
53 | ||
54 | /* | |
55 | * Set the INQUIRY transfer length to 36. We don't use any of | |
56 | @@ -90,20 +91,17 @@ static int slave_alloc (struct scsi_devi | |
57 | sdev->inquiry_len = 36; | |
58 | ||
59 | /* | |
60 | - * USB has unusual DMA-alignment requirements: Although the | |
61 | - * starting address of each scatter-gather element doesn't matter, | |
62 | - * the length of each element except the last must be divisible | |
63 | - * by the Bulk maxpacket value. There's currently no way to | |
64 | - * express this by block-layer constraints, so we'll cop out | |
65 | - * and simply require addresses to be aligned at 512-byte | |
66 | - * boundaries. This is okay since most block I/O involves | |
67 | - * hardware sectors that are multiples of 512 bytes in length, | |
68 | - * and since host controllers up through USB 2.0 have maxpacket | |
69 | - * values no larger than 512. | |
70 | - * | |
71 | - * But it doesn't suffice for Wireless USB, where Bulk maxpacket | |
72 | - * values can be as large as 2048. To make that work properly | |
73 | - * will require changes to the block layer. | |
74 | + * USB has unusual scatter-gather requirements: the length of each | |
75 | + * scatterlist element except the last must be divisible by the | |
76 | + * Bulk maxpacket value. Fortunately this value is always a | |
77 | + * power of 2. Inform the block layer about this requirement. | |
78 | + */ | |
79 | + maxp = usb_maxpacket(us->pusb_dev, us->recv_bulk_pipe, 0); | |
80 | + blk_queue_virt_boundary(sdev->request_queue, maxp - 1); | |
81 | + | |
82 | + /* | |
83 | + * Some host controllers may have alignment requirements. | |
84 | + * We'll play it safe by requiring 512-byte alignment always. | |
85 | */ | |
86 | blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1)); | |
87 |