patch "usb-storage: Add a limitation for blk_queue_max_hw_sectors()" added to usb-linus
Subsystems (3)
This is a note to let you know that I've just added the patch titled
usb-storage: Add a limitation for blk_queue_max_hw_sectors()
to my usb git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git
in the usb-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
From d74ffae8b8dd17eaa8b82fc163e6aa2076dc8fb1 Mon Sep 17 00:00:00 2001
From: Yoshihiro Shimoda <[email protected]>
Date: Mon, 22 Jul 2019 19:58:25 +0900
Subject: 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
--- drivers/usb/storage/scsiglue.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/usb/storage/scsiglue.c +11 -0
@@ -28,6 +28,8 @@* status of a command. */ +#include <linux/blkdev.h> +#include <linux/dma-mapping.h> #include <linux/module.h> #include <linux/mutex.h>
@@ -99,6 +101,7 @@ static int slave_alloc (struct scsi_device *sdev)static int slave_configure (struct scsi_device *sdev) {struct us_data *us =host_to_us (sdev->host); +struct device *dev = us->pusb_dev->bus->sysdev;/* * Many devices have trouble transferring more than 32KB at a time,
@@ -128,6 +131,14 @@ static int slave_configure(struct scsi_device *sdev)blk_queue_max_hw_sectors (sdev->request_queue,2048 ); } +/* +* The max_hw_sectors should be up to maximum size of a mapping for +* the device. Otherwise, a DMA API might fail on swiotlb environment. +*/ +blk_queue_max_hw_sectors (sdev->request_queue, +min_t (size_t,queue_max_hw_sectors (sdev->request_queue), +dma_max_mapping_size (dev) >>SECTOR_SHIFT )); +/* * Some USB host controllers can't do DMA; they have to use PIO. * They indicate this by setting their dma_mask to NULL. For
Signature · 1 line
2.22.0