Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp518244iog; Thu, 30 Jun 2022 05:23:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1srolIZlKn2SBqqGP7yz94teHVwb8otuXgy3aUR/loUJ1stDiVXlYHvcbgk2/39k773vISs X-Received: by 2002:a17:902:e741:b0:16a:351f:d029 with SMTP id p1-20020a170902e74100b0016a351fd029mr14339452plf.0.1656591829348; Thu, 30 Jun 2022 05:23:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656591829; cv=none; d=google.com; s=arc-20160816; b=cxp6rOJrC7hGMne3FQ5Ir55p5sjBovnxxoy1H6FsL8AuCQCLwZG90UFHj+4lPrsUSO xhZOElmSDQHpfpD0QVmILQGZEgecuBeVrcH797AUsCaZi+4l/13dZMiBYAn36GF3kHcZ yW6WIl03cinSPFSWRzKyhhkQSH2LTu6KElTddh4P5uKO0ekoZqZxTPLm3aehK8+QKIRN GvEUcv5tLZcLYati9fVcKvEFX4d2U1vhBUY8bagJ2jMgdqdR62X1sPIxB7vHXdofYO+E 19D6iCsJw65G40TSdS39tgep8Hf0pfd2yJfo492pfRLaPTwpx43V0mrXqis/wAgP+2qe Dp/A== 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=t+XAOz5F3q6J/vi7XZXudvjhiHKe6p22aJDB+4ocG24=; b=BSErxkouOKBXbeQobdTUbKZuh3PM9tPWQxWcgC8H5vzZy2vR9x4+DSAanpifpPNuC5 VYAr2zk4MNu43VXjwlXiguSo68Ztm6sjWehcchhOgi31tV71uiwJkQ9VeAurBC/V+fCY I//1XQfkMB9+pqlmXKNS66TAxkqLI1s+TgdATe9ZZXFeHCZ+13ZkVKts1UlRoW1i3dej AoohbarrzjmIYIppRwiqq3DN5ytwpzhZCmf75LDF3H2a0dYvzUvPunLkAr8Qf0vzSVml fUS1E1BNiERMI/HMJrzcEt5KSW1BEKMUs8n5zfJ0w7lh60YrCTmQYKjbs3rsombbf4u3 kFPA== 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 c12-20020a655a8c000000b003fb04d0b55dsi27297404pgt.565.2022.06.30.05.23.37; Thu, 30 Jun 2022 05:23:49 -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 S234794AbiF3MOe (ORCPT + 99 others); Thu, 30 Jun 2022 08:14:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232632AbiF3MO3 (ORCPT ); Thu, 30 Jun 2022 08:14:29 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5634A1D0F7; Thu, 30 Jun 2022 05:14:28 -0700 (PDT) Received: from fraeml710-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LYcdb0JWsz6H7vf; Thu, 30 Jun 2022 20:12:03 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml710-chm.china.huawei.com (10.206.15.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 30 Jun 2022 14:14:26 +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, 30 Jun 2022 13:14:22 +0100 From: John Garry To: , , , , , , , CC: , , , , , , , John Garry Subject: [PATCH v5 2/5] dma-iommu: Add iommu_dma_opt_mapping_size() Date: Thu, 30 Jun 2022 20:08:09 +0800 Message-ID: <1656590892-42307-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1656590892-42307-1-git-send-email-john.garry@huawei.com> References: <1656590892-42307-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: dggems706-chm.china.huawei.com (10.3.19.183) 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 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 --- 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