Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp571035ioo; Thu, 26 May 2022 09:38:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAR1vdVAiFSLPZ9bEI/RCzUcXVOvpXHiS/Tgv+CyQlTou2enVYQL9sTE5BYPYbX9EW/gjv X-Received: by 2002:a05:6402:5409:b0:42a:a643:4eb8 with SMTP id ev9-20020a056402540900b0042aa6434eb8mr41565193edb.71.1653583092700; Thu, 26 May 2022 09:38:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653583092; cv=none; d=google.com; s=arc-20160816; b=ICMOlIvcxEhzWVxv7ABii+O+v84XRZVhjMt3/rXuszJ6tNwlOoekJYrdOMAMxIFm9Q sg3Zz+cAy/lAn0tus60MBCQCAD6a4SZDfyZrUeEp60+HMHHbEuq6oi0cNIC2voNH/3L0 TwpGcOgbPxvb5StaDoJhrwe40uhqNw3aomle9btyXbXyLDD/KOewuvgsByBLJFTnxqSA b68dXzGI9hN1/AimZW0uM/bpgxtz9GUEyc777wjFmhmGMqNmlq1bSdWwsVffISEyeLx2 Xb0Ke2Rxtaybb0RnpaX6Gg2mxieUDNQH7JerOjKf3wtaHOv2yphXFF+1rthNCsaM09ED vuQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=2ocYOSeZOfEqiBaVnFF+ZgmbDse8K5PuynQaVjOuXFc=; b=PuSSnDUrMS5bk2pBOrVhlHM3x+NruMbDi9UFCiRFS4JIZLxPrTTt/uIYyWZ0iK6wHr VYcsLfq710RSDmlgBfGlr7a0Kd4e70vZz7vFeCoIee7JpSjg2095toKQ7wlBIUtBCXBr 6G9/FDRJc5Aap1xmgKQARx6kueb+zR14CsZFY9lpGt111rmFljI0s8cxV5+o2FGWSCSK K+G2BOJaMPq5Rt6koupqaXcVIAufoOGTDoIpD8Ojee8xunfQa4aWJRjviV40CSpbrNUS Gq4vsuB9cYLWJMh2aOjrslqe1I+dOkcoLmqcjfkNGFUynwAhvgJNqOFRQjNWygjV5KFk fuCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m24-20020a509998000000b0042b710e9bc6si1884388edb.279.2022.05.26.09.37.46; Thu, 26 May 2022 09:38:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232087AbiEZKgM (ORCPT + 99 others); Thu, 26 May 2022 06:36:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345407AbiEZKgJ (ORCPT ); Thu, 26 May 2022 06:36:09 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F9BDCEB82; Thu, 26 May 2022 03:35:54 -0700 (PDT) Received: from fraeml742-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4L843z6jdgz6GDBN; Thu, 26 May 2022 18:31:43 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml742-chm.china.huawei.com (10.206.15.223) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 26 May 2022 12:35:52 +0200 Received: from localhost.localdomain (10.69.192.58) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 26 May 2022 11:35:47 +0100 From: John Garry To: , , , , , , , CC: , , , , , , , , John Garry Subject: [PATCH v2 3/4] scsi: core: Cap shost max_sectors according to DMA optimum mapping limits Date: Thu, 26 May 2022 18:28:33 +0800 Message-ID: <1653560914-82185-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1653560914-82185-1-git-send-email-john.garry@huawei.com> References: <1653560914-82185-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Streaming DMA mappings may be considerably slower when mappings go through an IOMMU and the total mapping length is somewhat long. This is because the IOMMU IOVA code allocates and free an IOVA for each mapping, which may affect performance. For performance reasons set the request_queue max_sectors from dma_opt_mapping_size(), which knows this mapping limit. In addition, the shost->max_sectors is repeatedly set for each sdev in __scsi_init_queue(). This is unnecessary, so set once when adding the host. Signed-off-by: John Garry Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen --- drivers/scsi/hosts.c | 5 +++++ drivers/scsi/scsi_lib.c | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index f69b77cbf538..9563c0ac567a 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -240,6 +240,11 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, shost->dma_dev = dma_dev; + if (dma_dev->dma_mask) { + shost->max_sectors = min_t(unsigned int, shost->max_sectors, + dma_opt_mapping_size(dma_dev) >> SECTOR_SHIFT); + } + /* * Increase usage count temporarily here so that calling * scsi_autopm_put_host() will trigger runtime idle if there is diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 8d18cc7e510e..2d43bb8799bd 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1884,10 +1884,6 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q) blk_queue_max_integrity_segments(q, shost->sg_prot_tablesize); } - if (dev->dma_mask) { - shost->max_sectors = min_t(unsigned int, shost->max_sectors, - dma_max_mapping_size(dev) >> SECTOR_SHIFT); - } blk_queue_max_hw_sectors(q, shost->max_sectors); blk_queue_segment_boundary(q, shost->dma_boundary); dma_set_seg_boundary(dev, shost->dma_boundary); -- 2.26.2