Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp223009pxb; Wed, 18 Nov 2020 22:22:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNho8FutuKi4oe8kpOOjydrZ7aXIn0i8jaP6PCaYoL7Wfemw9MbzP/n8eHRHUhvKL7JEM+ X-Received: by 2002:aa7:dc52:: with SMTP id g18mr29348562edu.369.1605766925641; Wed, 18 Nov 2020 22:22:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605766925; cv=none; d=google.com; s=arc-20160816; b=igtEc30opQgwRwJOk/QT9Jef7a2TkIHJMnODH/bzVCdKh1Z7CVtisQ8L/DI/P36JHr Cgp6dMycgnWWlNKykiwH956RREuDnIPpNJrLHOjRr8KADrd8HbahspPn1a5ptIs0e6Se frrCZdd6iwVBhnckvZpg5wWu+zW2iDtvCeWHSLE1JAnnCFoweKKVOSXZEjE7Bb4KGJ4I YnswrCey+UGcKzyVSLEzaxT1MtHUWXoaPv7tvxz4IAGzwgI/1E5OTr2Fx2G26aB319HX Ih+7NCzx5fdT3sIGU16KsrEl7EHysL3DDuwOPOB3kl7Y4cob5gtNyZzd0YzsdV2N3VxX ciZQ== 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=cAwohTs+SL9GZP9VkHrOPMINfi4i7zIK+KdjgZ1bpPM=; b=PIZvkyk543oHv8nEA14GpElWhn3pIsTfQCwuFk6ZRj3uIKYcMSwVLv5nTcHT2Jy0wV wZUEQtq1N9fzE05bV+ynLgD8N9jI731+9K+IUBZEQlP3xt3KWUJifgCtJUMxs/tkpeBn KvdiB19fqfCjZHmoriPOFyaVpmakQ9D8yqTIt3Rf/ieA230FAdCq3sLPMfwWKc2sIlaC n9H/uUoqjRE12ZdDtWCD/WY9TTTkgETfm60blAv5l4gJmRwDr/5O6GiKJsaHp+PhYNzr hGCLe5rwS9WWm9DE+IuLUldlCiuYHjtS0BgqigIWSqrBCcgfW989u0BJ2bbkW+nkiRAk YDZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dx21si1926894ejb.197.2020.11.18.22.21.43; Wed, 18 Nov 2020 22:22:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726328AbgKSGS4 (ORCPT + 99 others); Thu, 19 Nov 2020 01:18:56 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:39879 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726224AbgKSGS4 (ORCPT ); Thu, 19 Nov 2020 01:18:56 -0500 X-UUID: 87bbfd34fd32496ca4c4a70b7e2356cc-20201119 X-UUID: 87bbfd34fd32496ca4c4a70b7e2356cc-20201119 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1222017783; Thu, 19 Nov 2020 14:18:54 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 19 Nov 2020 14:18:52 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 19 Nov 2020 14:18:50 +0800 From: Yong Wu To: Joerg Roedel , Will Deacon , Robin Murphy CC: Matthias Brugger , Krzysztof Kozlowski , Tomasz Figa , , , , , , , , Nicolas Boichat , , , Subject: [PATCH v2 1/6] iommu: Move iotlb_sync_map out from __iommu_map Date: Thu, 19 Nov 2020 14:18:31 +0800 Message-ID: <20201119061836.15238-2-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20201119061836.15238-1-yong.wu@mediatek.com> References: <20201119061836.15238-1-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the end of __iommu_map, It alway call iotlb_sync_map. This patch moves iotlb_sync_map out from __iommu_map since it is unnecessary to call this for each sg segment especially iotlb_sync_map is flush tlb all currently. Signed-off-by: Yong Wu --- drivers/iommu/iommu.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 8c470f451a32..decef851fa3a 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2407,9 +2407,6 @@ static int __iommu_map(struct iommu_domain *domain, unsigned long iova, size -= pgsize; } - if (ops->iotlb_sync_map) - ops->iotlb_sync_map(domain); - /* unroll mapping in case something went wrong */ if (ret) iommu_unmap(domain, orig_iova, orig_size - size); @@ -2422,15 +2419,29 @@ static int __iommu_map(struct iommu_domain *domain, unsigned long iova, int iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot) { + const struct iommu_ops *ops = domain->ops; + int ret; + might_sleep(); - return __iommu_map(domain, iova, paddr, size, prot, GFP_KERNEL); + ret = __iommu_map(domain, iova, paddr, size, prot, GFP_KERNEL); + if (ret == 0 && ops->iotlb_sync_map) + ops->iotlb_sync_map(domain); + + return ret; } EXPORT_SYMBOL_GPL(iommu_map); int iommu_map_atomic(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot) { - return __iommu_map(domain, iova, paddr, size, prot, GFP_ATOMIC); + const struct iommu_ops *ops = domain->ops; + int ret; + + ret = __iommu_map(domain, iova, paddr, size, prot, GFP_ATOMIC); + if (ret == 0 && ops->iotlb_sync_map) + ops->iotlb_sync_map(domain); + + return ret; } EXPORT_SYMBOL_GPL(iommu_map_atomic); @@ -2514,6 +2525,7 @@ static size_t __iommu_map_sg(struct iommu_domain *domain, unsigned long iova, struct scatterlist *sg, unsigned int nents, int prot, gfp_t gfp) { + const struct iommu_ops *ops = domain->ops; size_t len = 0, mapped = 0; phys_addr_t start; unsigned int i = 0; @@ -2544,6 +2556,8 @@ static size_t __iommu_map_sg(struct iommu_domain *domain, unsigned long iova, sg = sg_next(sg); } + if (ops->iotlb_sync_map) + ops->iotlb_sync_map(domain); return mapped; out_err: -- 2.18.0