diff options
author | Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> | 2019-07-22 06:58:25 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-07-25 04:40:02 -0400 |
commit | d74ffae8b8dd17eaa8b82fc163e6aa2076dc8fb1 (patch) | |
tree | 4ee065aaaa87bdfdaddda5fc20e8bea01be9ed53 | |
parent | 4fbb8aa75836c3361987f431d9451aecc1830bdd (diff) |
usb-storage: Add a limitation for blk_queue_max_hw_sectors()
This patch fixes an issue that the following error happens on
swiotlb environment:
xhci-hcd ee000000.usb: swiotlb buffer is full (sz: 524288 bytes), total 32768 (slots), used 1338 (slots)
On the kernel v5.1, block settings of a usb-storage with SuperSpeed
were the following so that the block layer will allocate buffers
up to 64 KiB, and then the issue didn't happen.
max_segment_size = 65536
max_hw_sectors_kb = 1024
After the commit 09324d32d2a0 ("block: force an unlimited segment
size on queues with a virt boundary") is applied, the block settings
are the following. So, the block layer will allocate buffers up to
1024 KiB, and then the issue happens:
max_segment_size = 4294967295
max_hw_sectors_kb = 1024
To fix the issue, the usb-storage driver checks the maximum size of
a mapping for the device and then adjusts the max_hw_sectors_kb
if required. After this patch is applied, the block settings will
be the following, and then the issue doesn't happen.
max_segment_size = 4294967295
max_hw_sectors_kb = 256
Fixes: 09324d32d2a0 ("block: force an unlimited segment size on queues with a virt boundary")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/1563793105-20597-1-git-send-email-yoshihiro.shimoda.uh@renesas.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/usb/storage/scsiglue.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c index 30790240aec6..05b80211290d 100644 --- a/drivers/usb/storage/scsiglue.c +++ b/drivers/usb/storage/scsiglue.c | |||
@@ -28,6 +28,8 @@ | |||
28 | * status of a command. | 28 | * status of a command. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <linux/blkdev.h> | ||
32 | #include <linux/dma-mapping.h> | ||
31 | #include <linux/module.h> | 33 | #include <linux/module.h> |
32 | #include <linux/mutex.h> | 34 | #include <linux/mutex.h> |
33 | 35 | ||
@@ -99,6 +101,7 @@ static int slave_alloc (struct scsi_device *sdev) | |||
99 | static int slave_configure(struct scsi_device *sdev) | 101 | static int slave_configure(struct scsi_device *sdev) |
100 | { | 102 | { |
101 | struct us_data *us = host_to_us(sdev->host); | 103 | struct us_data *us = host_to_us(sdev->host); |
104 | struct device *dev = us->pusb_dev->bus->sysdev; | ||
102 | 105 | ||
103 | /* | 106 | /* |
104 | * Many devices have trouble transferring more than 32KB at a time, | 107 | * Many devices have trouble transferring more than 32KB at a time, |
@@ -129,6 +132,14 @@ static int slave_configure(struct scsi_device *sdev) | |||
129 | } | 132 | } |
130 | 133 | ||
131 | /* | 134 | /* |
135 | * The max_hw_sectors should be up to maximum size of a mapping for | ||
136 | * the device. Otherwise, a DMA API might fail on swiotlb environment. | ||
137 | */ | ||
138 | blk_queue_max_hw_sectors(sdev->request_queue, | ||
139 | min_t(size_t, queue_max_hw_sectors(sdev->request_queue), | ||
140 | dma_max_mapping_size(dev) >> SECTOR_SHIFT)); | ||
141 | |||
142 | /* | ||
132 | * Some USB host controllers can't do DMA; they have to use PIO. | 143 | * Some USB host controllers can't do DMA; they have to use PIO. |
133 | * They indicate this by setting their dma_mask to NULL. For | 144 | * They indicate this by setting their dma_mask to NULL. For |
134 | * such controllers we need to make sure the block layer sets | 145 | * such controllers we need to make sure the block layer sets |