Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp435522imw; Thu, 14 Jul 2022 04:24:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v1jsUiBI2Vk0G+IA17H4gjPgharc8U0SpFfcVaMFbvCwp2jOzeIitXCGtjV7ZHaqCQWdsW X-Received: by 2002:aa7:db50:0:b0:43a:6319:e2bc with SMTP id n16-20020aa7db50000000b0043a6319e2bcmr11657848edt.237.1657797891781; Thu, 14 Jul 2022 04:24:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657797891; cv=none; d=google.com; s=arc-20160816; b=OzAJ+M5HPypRMKnF592AhVMNFtvrQcKiJsLVyB+6/45cCxDUyElgxjlmQnWXe81OuU GmcYpv/dBP+Kw/fhRKHuE/bZExVJH4C0L7M2JNc3b8CBr6NHtoafiqQFADrrLqHB8Ow2 wEvcgXhNOV8TRESyVDfwt8xsfXMeWXlBMchC27vrbMp/8f+CwTZvds6V3sBy47Y0zUtV WXavnewTBKYGZsp2q925IDWpdDBqjqsYJhOJEkUCXorfOD33tUE+btWEKhW7+v5Awtwh 2K5jwCtM0I1isQjdxZ79y+vOapZDyQ87lZDVtoJ5KfNbql6qHr+GjVKlPxeLhBKRGKPo zwzQ== 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=ytUYryffKFRDxh3Q3PRd9TjpeIcYavoy5TLwSBpiOy8=; b=lUqprANrOFTQOvEJt9fSNklfGiZysbl1OoBrfh4xkq749yWqaIWptToCMjkTJXMR+o bTLRwa1gTXw2tebB2xrnouOxZRwCKUFfnZpKpvAUsg/JlnjN+fgLza/FPTay0NJ/+fFb N7Z323zq4vxPP13i9W54Q7rAQ3UHDAcvlPQiwez4sTVKtMEw+TJp8uruUnHrBLCNvJ+8 QGTxL/2bFe0l+QVa6mVANG9C2m+I4qrZpsJb2rB9TEXlLdfdVFoWdpsm95rO5KAEccxV 7EWMFx5JF5WE2l2hhOd2PrLArP5qHpt1LYTC6oKLUF18l9lvWdwEzI1mv6jC+c/Yh13n 0vRA== 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 w10-20020a17090649ca00b006fe9a0289d5si1435662ejv.885.2022.07.14.04.24.26; Thu, 14 Jul 2022 04:24:51 -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 S238658AbiGNLW0 (ORCPT + 99 others); Thu, 14 Jul 2022 07:22:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238462AbiGNLWT (ORCPT ); Thu, 14 Jul 2022 07:22:19 -0400 Received: from sinmsgout01.his.huawei.com (sinmsgout01.his.huawei.com [119.8.177.36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78499558CF; Thu, 14 Jul 2022 04:22:18 -0700 (PDT) Received: from fraeml739-chm.china.huawei.com (unknown [172.18.156.207]) by sinmsgout01.his.huawei.com (SkyGuard) with ESMTP id 4LkBm13vF2z9v7Hd; Thu, 14 Jul 2022 19:17:21 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml739-chm.china.huawei.com (10.206.15.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 14 Jul 2022 13:22:11 +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, 14 Jul 2022 12:22:07 +0100 From: John Garry To: , , , , , , , CC: , , , , , , John Garry Subject: [PATCH v6 2/6] dma-iommu: Add iommu_dma_opt_mapping_size() Date: Thu, 14 Jul 2022 19:15:25 +0800 Message-ID: <1657797329-98541-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1657797329-98541-1-git-send-email-john.garry@huawei.com> References: <1657797329-98541-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: dggems705-chm.china.huawei.com (10.3.19.182) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 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. Signed-off-by: John Garry Reviewed-by: Damien Le Moal Acked-by: Robin Murphy Acked-by: Martin K. Petersen --- 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, -- 2.35.3