Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp263935pxu; Thu, 7 Jan 2021 04:32:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwtMEjFAGw7YeX5BQPUGRU+ge9m3ay6w1S6NZ1lxjmZ1dLC5YZP7yWbFGBMUQIMMFGO8igN X-Received: by 2002:a50:fc13:: with SMTP id i19mr1568825edr.281.1610022739865; Thu, 07 Jan 2021 04:32:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610022739; cv=none; d=google.com; s=arc-20160816; b=IaF8HcUOf3KSR9/VD70UFNtzg3+Ut3hKqeYdG1sjNtdNWHq6rV0lqqhdQrq+/qg+RC JqBFLHqnqhgLJL06itc3gTKTycm+q1pTSOcJo9NfpFlsA0bDUE36NvqPEzZ42hks9UQR nkEiykBORPBMzlSLYvp3tjL/i3nUI4jVqLrHz3FseGnN+/heSnsNB9oVnuYgrg7nVtnI C7MeCVYsX8TLd/s87RcBC9TZtsUXs4dxSfuG/30mck3EROYNymtYc16fgW0w5rjGXXqO 8P5DydDlDmkmz19lJ+R/DyDjo+1wee6ey9QJ++Do+m9868AcRERGWinxVeET+j4OdCK5 vB7A== 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=9b5uueIvv9elAf/4fkKkg5jtdMjz9yH8xfdYJGP7i6E=; b=pTDDXQrw5loBNj7eqGbsOnVf/yXI4dEOShs7Bt+T0zetSnNNQS2s6FEpXB1kJj5Ilx UNGwn1W9b60JYxmip0z52baiLAIK0AiD/p6QUUvZdhb0/JOf2dGlz9TNXOutUqL0bwS0 9sVxnEmBPilaZwG6oIif9cr4rJqVPjeMJbFtpSKZdOuG9njSbCvJjbW7MpzXC8yov1+f KA4mJ59sOsBxDnXFu1/X1jtKOWmn7qofUO2i0Q4id6Uz4MAztW9hHlD0gZzYvUGZvzxV Im6mYnuol9SPfNA2yI+VZ+tb3BTksOcX1R/yXrlL7bNN4L/2q1dsbLR9gCX9vyR9yHsO EXDw== 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 a5si2041795ejj.142.2021.01.07.04.31.55; Thu, 07 Jan 2021 04:32:19 -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 S1727753AbhAGMaX (ORCPT + 99 others); Thu, 7 Jan 2021 07:30:23 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:57299 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725835AbhAGMaX (ORCPT ); Thu, 7 Jan 2021 07:30:23 -0500 X-UUID: a179893b427c46adb591d83809fc8caf-20210107 X-UUID: a179893b427c46adb591d83809fc8caf-20210107 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 7058970; Thu, 07 Jan 2021 20:29:36 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 7 Jan 2021 20:29:35 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 7 Jan 2021 20:29:34 +0800 From: Yong Wu To: Joerg Roedel , Will Deacon , Robin Murphy CC: Matthias Brugger , Krzysztof Kozlowski , Tomasz Figa , , , , , , , , Nicolas Boichat , , , Greg Kroah-Hartman , , Christoph Hellwig , David Laight Subject: [PATCH v4 1/7] iommu: Move iotlb_sync_map out from __iommu_map Date: Thu, 7 Jan 2021 20:29:03 +0800 Message-ID: <20210107122909.16317-2-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210107122909.16317-1-yong.wu@mediatek.com> References: <20210107122909.16317-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. Add a little helper _iommu_map for this. Signed-off-by: Yong Wu Reviewed-by: Robin Murphy --- drivers/iommu/iommu.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index ffeebda8d6de..c304a6a30d42 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2426,9 +2426,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); @@ -2438,18 +2435,31 @@ static int __iommu_map(struct iommu_domain *domain, unsigned long iova, return ret; } +static int _iommu_map(struct iommu_domain *domain, unsigned long iova, + phys_addr_t paddr, size_t size, int prot, gfp_t gfp) +{ + const struct iommu_ops *ops = domain->ops; + int ret; + + ret = __iommu_map(domain, iova, paddr, size, prot, GFP_KERNEL); + if (ret == 0 && ops->iotlb_sync_map) + ops->iotlb_sync_map(domain); + + return ret; +} + int iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot) { might_sleep(); - return __iommu_map(domain, iova, paddr, size, prot, GFP_KERNEL); + return _iommu_map(domain, iova, paddr, size, prot, GFP_KERNEL); } 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); + return _iommu_map(domain, iova, paddr, size, prot, GFP_ATOMIC); } EXPORT_SYMBOL_GPL(iommu_map_atomic); @@ -2533,6 +2543,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; @@ -2563,6 +2574,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