Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp265246pxu; Thu, 7 Jan 2021 04:34:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJygXZO2jgAVwzK/tcqlQOr6h2pk6D8frpMVVhzyHfaeM3rGaOCiIRPcS9WGPIzOHXQFdHRw X-Received: by 2002:a17:906:1393:: with SMTP id f19mr6146521ejc.431.1610022870838; Thu, 07 Jan 2021 04:34:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610022870; cv=none; d=google.com; s=arc-20160816; b=OVVAmdstTRjHs0jhhmh3NTV6HUmPpUvwcI5eaJNvZsn8koPwOjJAn7U4po5UhvXEog AfT0jKdTNfu7+waI5H8CotLZ9PD1+utru/8X9BvVU63KztAQwY+Cn42LlDIZYvnMzt25 XynCeXP9GeXAik+YbQQcKjtgeql/xhozUDzcQxz37nmNyt1RVPMZxRJk8MgSAmeiOGre w9qfHmbaEliRvcTB6tquHgkbBVyTaKwemrX/jkGUv5Jd0f9h36j0DULnqIzjfd0mkG7S bH8m2OzTdByIN0HYEJH6RArgh6hEL3V1FLa1cEN6Gqvrr5myCJKFeC94DOzF91UrmQLi XrAw== 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=Rj6VO1SDPmbrOeyRnIW2v5EK149J5fqDI/Y4B3zwqrI=; b=DRJCu1Fv4J52up2SyNoX7T7KHlxewzXnUYmDKeekH8wU5O32BOKhSmtnzpNRYpafmn zBpgCrb+/+2azYnc0s9UQmICxYXjzX5fI4kCiJpzwC63LDFPSZopqsK+P7e1ubgbO51X xz+vjXy1snzNmPqonDNkSqMmFIFXy628Crntp7L6EPGyycT6mXMBzIFE9ohioNuJ7wTf i6JmLXR+ijTCZ1mjt0dwIY0qDoG7uI1SE956p9LxebagBqxX019HMRARkkbTNXU0/Liz 5SIvZ10/RtbQNZkCkutlf59Htnk1HvuGQDi0cH0HKCZEMY9hHsntHqL0Z9jX4Bomww3C 7d+Q== 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 l3si2269804edq.175.2021.01.07.04.34.06; Thu, 07 Jan 2021 04:34:30 -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 S1728270AbhAGMbO (ORCPT + 99 others); Thu, 7 Jan 2021 07:31:14 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:57840 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728233AbhAGMbN (ORCPT ); Thu, 7 Jan 2021 07:31:13 -0500 X-UUID: 060ac8cd00b24e38bc17ff443bc4edf6-20210107 X-UUID: 060ac8cd00b24e38bc17ff443bc4edf6-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 915304804; Thu, 07 Jan 2021 20:30:26 +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:30:24 +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:30:24 +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 6/7] iommu/mediatek: Gather iova in iommu_unmap to achieve tlb sync once Date: Thu, 7 Jan 2021 20:29:08 +0800 Message-ID: <20210107122909.16317-7-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 current iommu_unmap, this code is: iommu_iotlb_gather_init(&iotlb_gather); ret = __iommu_unmap(domain, iova, size, &iotlb_gather); iommu_iotlb_sync(domain, &iotlb_gather); We could gather the whole iova range in __iommu_unmap, and then do tlb synchronization in the iommu_iotlb_sync. This patch implement this, Gather the range in mtk_iommu_unmap. then iommu_iotlb_sync call tlb synchronization for the gathered iova range. we don't call iommu_iotlb_gather_add_page since our tlb synchronization could be regardless of granule size. In this way, gather->start is impossible ULONG_MAX, remove the checking. This patch aims to do tlb synchronization *once* in the iommu_unmap. Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 66a00a2cb445..d3b8a1649093 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -430,7 +430,12 @@ static size_t mtk_iommu_unmap(struct iommu_domain *domain, struct iommu_iotlb_gather *gather) { struct mtk_iommu_domain *dom = to_mtk_domain(domain); + unsigned long end = iova + size - 1; + if (gather->start > iova) + gather->start = iova; + if (gather->end < end) + gather->end = end; return dom->iop->unmap(dom->iop, iova, size, gather); } @@ -445,9 +450,6 @@ static void mtk_iommu_iotlb_sync(struct iommu_domain *domain, struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); size_t length = gather->end - gather->start + 1; - if (gather->start == ULONG_MAX) - return; - mtk_iommu_tlb_flush_range_sync(gather->start, length, gather->pgsize, data); } -- 2.18.0