Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3855520iog; Tue, 28 Jun 2022 04:19:04 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ty8akVt8gUc+Tgxzm2BnO080syolEH3rGDUKz4WfimAwgTD757ZHbEq7KLge4/NjnjIfDd X-Received: by 2002:a17:903:25c5:b0:16a:30e:34b8 with SMTP id jc5-20020a17090325c500b0016a030e34b8mr3111851plb.170.1656415144218; Tue, 28 Jun 2022 04:19:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656415144; cv=none; d=google.com; s=arc-20160816; b=ytZdQk+dLCA6bRDmAqyYgHxfPrUt/tzi2SXaoO/x8zWuzqou5B2aYekw1jmzJu9T8t 3PSBbIIoTmbw7f8AigojlB95p8pG8MJRNEaf9AGmrvO215qWnZ1CHt+0K6SyVn1SiA0l pCMueKmXfUFmVzGgBQ8JezdlAylAXAsOy7Oc1uv2uQFH9rrMTzOHEiBuaTjeZz1xpFQ+ pLhgYUQhJQGkk4M9psjApo8+eiyuJZXCQ5bvxApkNaMeHD8nwaQhVWIxnpidqzobLfRx 6yzKDYwausuMxLDlxPyFHueLrrhvMNSKOW5kj9595ERA3nq5zmJL4DSz/Vb3JmoQBtml qlSg== 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=HsR7k9sD4UF6kKsbdsbMNvAcuUwdcnmJQafm7eSfeuI=; b=Pi3Lbj4EcSjsRqCfDdtlAkeRXaKI9UbjKsOF2THYBGuznJH26KlH7B7wWNCVJj7G97 PVnu0u4OBY9+8Ksx2evLdNntuVicBdGS5IFcIhtufZyCuy1t3imTxJPi4xmUVyt5YP0n pbB+zhW9qQ9b2aUIz5ZiBFQLH8E3umWO7TM3x+XcPYquEU9L1QeCDJp+rEw4eaXZRrhS fsnUOMpeqZ/YUbA4UpIld0BFq/irzHXCiZOnpEcn6olTsDUzGR9yl2M4sAT6TD4CBnKx 2Fm5pYzBGhrO3L/xS4T6zpE9Ot7NCMLeGnh/JRL0mbenteEFhW7ZcBX0+LE6QbgHqoUr dYHQ== 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=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b6-20020a17090a800600b001e0552f722asi19470726pjn.87.2022.06.28.04.18.51; Tue, 28 Jun 2022 04:19:04 -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=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345110AbiF1K45 (ORCPT + 99 others); Tue, 28 Jun 2022 06:56:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231682AbiF1K4z (ORCPT ); Tue, 28 Jun 2022 06:56:55 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4DE2D31DC0; Tue, 28 Jun 2022 03:56:54 -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 D139F152B; Tue, 28 Jun 2022 03:56:53 -0700 (PDT) Received: from [10.57.85.130] (unknown [10.57.85.130]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 48C603F5A1; Tue, 28 Jun 2022 03:56:51 -0700 (PDT) Message-ID: <06ece223-c71e-baf8-e35e-dbc22a9cf9da@arm.com> Date: Tue, 28 Jun 2022 11:56:46 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v4 2/5] dma-iommu: Add iommu_dma_opt_mapping_size() Content-Language: en-GB To: John Garry , damien.lemoal@opensource.wdc.com, joro@8bytes.org, will@kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com, hch@lst.de, m.szyprowski@samsung.com Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org, iommu@lists.linux-foundation.org, iommu@lists.linux.dev, linux-scsi@vger.kernel.org, linuxarm@huawei.com References: <1656343521-62897-1-git-send-email-john.garry@huawei.com> <1656343521-62897-3-git-send-email-john.garry@huawei.com> From: Robin Murphy In-Reply-To: <1656343521-62897-3-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=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE,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 On 2022-06-27 16:25, John Garry wrote: > Add the IOMMU callback for DMA mapping API dma_opt_mapping_size(), which > allows the drivers to know the optimal mapping limit and thus limit the > requested IOVA lengths. > > This value is based on the IOVA rcache range limit, as IOVAs allocated > above this limit must always be newly allocated, which may be quite slow. Acked-by: Robin Murphy > Signed-off-by: John Garry > Reviewed-by: Damien Le Moal > --- > drivers/iommu/dma-iommu.c | 6 ++++++ > drivers/iommu/iova.c | 5 +++++ > include/linux/iova.h | 2 ++ > 3 files changed, 13 insertions(+) > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index f90251572a5d..9e1586447ee8 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -1459,6 +1459,11 @@ static unsigned long iommu_dma_get_merge_boundary(struct device *dev) > return (1UL << __ffs(domain->pgsize_bitmap)) - 1; > } > > +static size_t iommu_dma_opt_mapping_size(void) > +{ > + return iova_rcache_range(); > +} > + > static const struct dma_map_ops iommu_dma_ops = { > .alloc = iommu_dma_alloc, > .free = iommu_dma_free, > @@ -1479,6 +1484,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, > + .opt_mapping_size = iommu_dma_opt_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..c6ba6d95d79c 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,