Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3805469ybi; Mon, 29 Jul 2019 13:00:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqy24ZEzBc/uZhS6Je+u0oTnunM2z2I1YHY/iyiTmS/RsROADBYrwvNpmMjrZRXn6B0BCLIA X-Received: by 2002:a63:9e56:: with SMTP id r22mr48919813pgo.221.1564430406281; Mon, 29 Jul 2019 13:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430406; cv=none; d=google.com; s=arc-20160816; b=a1q2meF6Cu7Zkv14sjgG+7JDLFrojUdpPNmLUYvMkaMmxcYuwz181x8g7inL3aZQYg z0vtd/W9z504JixUlnzN9jSb+6LKhxW1vGOOYgf+MokCW3IxAGoAWmQf4q62/EEZYdhv Vst7Hpl1pVF5GBAnxw9kP0zb//oWaRc+JFAdQvfcwShv8r0KH+cZ9YIsF9pw1ShDeih4 RUbBeMeSdwC+7GALL2EFeeQoHgR6bKDE9Co9+ttKsmnCYu8T1yTW79UAG2N6NeP5sWVg XQ5+GUkBGD1xV31h4DUGPyv/YEejy3qDx13j3N7Gq/u1kBOU3AkdllObRstkNYlw1SuM uvhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qUnwXS8QBTyvUh2iRe07snBeryIcM1s5v2KFcOuDIlI=; b=xURvzHRYDZbD0RONIy/zTdNzcyG6KMQdeEwSpvEy4GAXt91B4j9uTDH/iavkhPdmRt V4JAJADoIgUK6Igr7ZXSlRSibH0h+LCfumJ0KBhBEqB70K4VjeHjt3ZAiKBeDLFsiCJC rxuSjJxGE7OHVSPryLd2hc++XQ8I0/vcYdOiBOlo3QT9z885x7RRs29zs3mnSwT3o81K iod+kD8rft0xlSsecOeWlhSaTJUXE0DVvzwwKUR6Yq5Bd0Fj32Z9jTEfYa3JBdR9ce5u a6yPilvDSdzocGXqOW5n0Waed0EAzdsFtgw6VUwY5wNv3sUQvF+xtGru21UW6dvM6INx 7drw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="i4/yfyhl"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t70si31621709pgd.573.2019.07.29.12.59.50; Mon, 29 Jul 2019 13:00:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="i4/yfyhl"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391034AbfG2T6j (ORCPT + 99 others); Mon, 29 Jul 2019 15:58:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:45860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404003AbfG2Txa (ORCPT ); Mon, 29 Jul 2019 15:53:30 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4BB9A2171F; Mon, 29 Jul 2019 19:53:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564430009; bh=ZfoP31n5GUF7bzTvIabAhQHOtyckrMdjUQ76F0eMe+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i4/yfyhl+6LYJpsqleVlVdQFWymbNhgOYKZsuNwmPLilX8RWx9kB2PZPxckSgDneK aGZEcigYJgEEG9TaKLdw5Tp2stM8HlEZ8UqolB7bP8lx0WVFQDYy7pY6uPQ6SqOxa8 loGSYpgBcBYgcoHIqPq3aYJHLpz/3q2DsWXHijA0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yoshihiro Shimoda , Alan Stern , Christoph Hellwig Subject: [PATCH 5.2 168/215] usb-storage: Add a limitation for blk_queue_max_hw_sectors() Date: Mon, 29 Jul 2019 21:22:44 +0200 Message-Id: <20190729190808.996241839@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yoshihiro Shimoda commit d74ffae8b8dd17eaa8b82fc163e6aa2076dc8fb1 upstream. 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 Signed-off-by: Yoshihiro Shimoda Acked-by: Alan Stern Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/1563793105-20597-1-git-send-email-yoshihiro.shimoda.uh@renesas.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/scsiglue.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/drivers/usb/storage/scsiglue.c +++ b/drivers/usb/storage/scsiglue.c @@ -28,6 +28,8 @@ * status of a command. */ +#include +#include #include #include @@ -99,6 +101,7 @@ static int slave_alloc (struct scsi_devi 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, @@ -129,6 +132,14 @@ static int slave_configure(struct scsi_d } /* + * 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 * such controllers we need to make sure the block layer sets