Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp192105lfo; Tue, 17 May 2022 21:54:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqQM7WkzA57guMKZuhUKWQbTkgYBwos1OSD0OsPUYdlGQzEX81fy/Py/GAvSmuK7iibniA X-Received: by 2002:a17:902:dacd:b0:15e:a53e:3239 with SMTP id q13-20020a170902dacd00b0015ea53e3239mr25416385plx.7.1652849697104; Tue, 17 May 2022 21:54:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652849697; cv=none; d=google.com; s=arc-20160816; b=Cdwwl4AdgAOcZjvHRfIYPWzq8xMqfmuFvtG+TQ5820tUJhGEvrm6e2t7Wrsh2e+9bn cpOaqAr/OtAslA80pb8bdrd2tvi51CAZdqs0BGTwF9MXcFvvc2lhuahIApTUdd1FttUM jQ4IQ545R7l2lgYU4haPEREsAEevM8+kc+9pOVw4Jj5xiSUWLeDB5i4pb3Ap++lpSmI+ 8VK6+uSh1hbPQhngNLIWa5TJQBvTOXyYfMInPk4jTJPhtoDXhCM/Y1JSCZXc98hJXvn4 4SAqNqNJZzDwBdeWeJng1C6hhGkU3Z9a3jzDcJyG3g7diN9tlL26XC+ddHl606fFZN+q XVTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=mlBlHV0YHmoaqBKD2K353c/uop7GdjW2uTqUre4FIjk=; b=jph3iYX1Daxm4RdcriMeO2J+hWfnmDQ9abKdu1SpNTvE1ZgdC5tdWtKKw/PiLOqe9B aY1VVmwqIvbfDVBnwVXgNM8QLP4jIkFeG6Tz5xPYBimMzqUCOSov3Slr3uX/0iE59y6t Y1jSgSe6F61ZLKYq2rhXiqKdD81HNj2KbIvi58kirYT8RxMvgEci4r88qh2LKXowxe3e rIiU25vPOTK3ic/uzvW2M2PAFR+DKgMO+YTkwV+L0OLdVOiScBLTPKFNxXsqbsGf9koN w/qa1c/MjhiEj5uiVup6LrfBh6ghhxYJWK6DDCmvcY/OTvtsfV/Xa6dwUWnzoilXQmLz ZXYQ== 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:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bk3-20020a056a02028300b003ab0e0a6b62si1291067pgb.803.2022.05.17.21.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 21:54:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D221F69B60; Tue, 17 May 2022 21:02:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237651AbiEQKlW (ORCPT + 99 others); Tue, 17 May 2022 06:41:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344446AbiEQKlB (ORCPT ); Tue, 17 May 2022 06:41:01 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2B784B49A for ; Tue, 17 May 2022 03:41:00 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E845A1042; Tue, 17 May 2022 03:40:59 -0700 (PDT) Received: from [10.57.82.55] (unknown [10.57.82.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 590E93F66F; Tue, 17 May 2022 03:40:58 -0700 (PDT) Message-ID: Date: Tue, 17 May 2022 11:40:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [RFC PATCH] dma-iommu: Add iommu_dma_max_mapping_size() Content-Language: en-GB To: John Garry , joro@8bytes.org, will@kernel.org, hch@lst.de, m.szyprowski@samsung.com Cc: chenxiang66@hisilicon.com, thunder.leizhen@huawei.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, liyihang6@hisilicon.com References: <1652706361-92557-1-git-send-email-john.garry@huawei.com> From: Robin Murphy In-Reply-To: <1652706361-92557-1-git-send-email-john.garry@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 2022-05-16 14:06, John Garry wrote: > For streaming DMA mappings involving an IOMMU and whose IOVA len regularly > exceeds the IOVA rcache upper limit (meaning that they are not cached), > performance can be reduced. > > Add the IOMMU callback for DMA mapping API dma_max_mapping_size(), which > allows the drivers to know the mapping limit and thus limit the requested > IOVA lengths. > > This resolves the performance issue originally reported in [0] for a SCSI > HBA driver which was regularly mapping SGLs which required IOVAs in > excess of the IOVA caching limit. In this case the block layer limits the > max sectors per request - as configured in __scsi_init_queue() - which > will limit the total SGL length the driver tries to map and in turn limits > IOVA lengths requested. > > [0] https://lore.kernel.org/linux-iommu/20210129092120.1482-1-thunder.leizhen@huawei.com/ > > Signed-off-by: John Garry > --- > Sending as an RFC as iommu_dma_max_mapping_size() is a soft limit, and not > a hard limit which I expect is the semantics of dma_map_ops.max_mapping_size Indeed, sorry but NAK for this being nonsense. As I've said at least once before, if the unnecessary SAC address allocation attempt slows down your workload, make it not do that in the first place. If you don't like the existing command-line parameter then fine, there are plenty of other options, it just needs to be done in a way that doesn't break x86 systems with dodgy firmware, as my first attempt turned out to. Furthermore, if a particular SCSI driver doesn't benefit from mappings larger than 256KB, then that driver is also free to limit its own mapping size. There are other folks out there with use-cases for mapping *gigabytes* at once; you don't get to cripple the API and say that that's suddenly not allowed just because it happens to make your thing go faster, that's absurd. Thanks, Robin. > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index 09f6e1c0f9c0..e2d5205cde37 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -1442,6 +1442,21 @@ static unsigned long iommu_dma_get_merge_boundary(struct device *dev) > return (1UL << __ffs(domain->pgsize_bitmap)) - 1; > } > > +static size_t iommu_dma_max_mapping_size(struct device *dev) > +{ > + struct iommu_domain *domain = iommu_get_domain_for_dev(dev); > + struct iommu_dma_cookie *cookie; > + > + if (!domain) > + return 0; > + > + cookie = domain->iova_cookie; > + if (!cookie || cookie->type != IOMMU_DMA_IOVA_COOKIE) > + return 0; > + > + return iova_rcache_range(); > +} > + > static const struct dma_map_ops iommu_dma_ops = { > .alloc = iommu_dma_alloc, > .free = iommu_dma_free, > @@ -1462,6 +1477,7 @@ static const struct dma_map_ops iommu_dma_ops = { > .map_resource = iommu_dma_map_resource, > .unmap_resource = iommu_dma_unmap_resource, > .get_merge_boundary = iommu_dma_get_merge_boundary, > + .max_mapping_size = iommu_dma_max_mapping_size, > }; > > /* > diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c > index db77aa675145..9f00b58d546e 100644 > --- a/drivers/iommu/iova.c > +++ b/drivers/iommu/iova.c > @@ -26,6 +26,11 @@ static unsigned long iova_rcache_get(struct iova_domain *iovad, > static void free_cpu_cached_iovas(unsigned int cpu, struct iova_domain *iovad); > static void free_iova_rcaches(struct iova_domain *iovad); > > +unsigned long iova_rcache_range(void) > +{ > + return PAGE_SIZE << (IOVA_RANGE_CACHE_MAX_SIZE - 1); > +} > + > static int iova_cpuhp_dead(unsigned int cpu, struct hlist_node *node) > { > struct iova_domain *iovad; > diff --git a/include/linux/iova.h b/include/linux/iova.h > index 320a70e40233..ae3e18d77e6c 100644 > --- a/include/linux/iova.h > +++ b/include/linux/iova.h > @@ -79,6 +79,8 @@ static inline unsigned long iova_pfn(struct iova_domain *iovad, dma_addr_t iova) > int iova_cache_get(void); > void iova_cache_put(void); > > +unsigned long iova_rcache_range(void); > + > void free_iova(struct iova_domain *iovad, unsigned long pfn); > void __free_iova(struct iova_domain *iovad, struct iova *iova); > struct iova *alloc_iova(struct iova_domain *iovad, unsigned long size, > @@ -105,6 +107,11 @@ static inline void iova_cache_put(void) > { > } > > +static inline unsigned long iova_rcache_range(void) > +{ > + return 0; > +} > + > static inline void free_iova(struct iova_domain *iovad, unsigned long pfn) > { > }