Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2492057pxb; Mon, 18 Jan 2021 21:04:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+nr7ekgz3Pcc06BVjujyea70TdOFiV9lnPEgFKPrs6KgIdNjuBf+YeIHwNFilZuywbp4V X-Received: by 2002:a17:907:3e1b:: with SMTP id hp27mr1737887ejc.506.1611032650056; Mon, 18 Jan 2021 21:04:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611032650; cv=none; d=google.com; s=arc-20160816; b=QAt5+m/f5xKf1DdE2N+rekkH86ZjkH5aCDNTqmyELB/UvZCQDqGnLCMQzB5mYZ9ngg t3iO/bvfNwyLlYvwWGywnXeBqGaYlNNmQInKkknWSD4aRj3n7Wf9T4TW8C7ez6Z0GifC oO1BadfM/Rx6drWLllOIk913ZOy7VMdp17/BExItmw/Y3GC6GRSqb/WNfnfy//TGRiJr 0/7Fo39EybAUNSTfxuXolVwdMvukD7H7As8EV4Xb+bxCGmHQqSalz0WxfAd9isTLffOH EN9b4rtI4tdznGKoZsdEpxu4UV8u+19qsE/lJul6cuybjYO13Wu4QZ0FNM0Isozm2BPn UJUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=R8S+o2vEX7nuTPcMi2C2QDSlEozTVHPVACGNmA1Dbds=; b=nbMt+ht04gzKFxTzrPwmtou33I7U5IZma14CBJBZufUwQ4UFJxvsuJlNhQ1Jkyqi0e feyRK8XZ7WVDw4q8koyV4PWDO1U2ztx0ENpB3tSsZvU0bvZkL9rtbmbbwd0fJgkJFYK6 zSwsBRYTk82Yw4LMeHztdsiP5sWpkZkQcNsFXc6ROKMCY1jou/ED1w2i44ybX56UJrWr V2yipfGWG8X+MzM4INwHzY3JCxERTVOdixDsYKqjwy/BDkNzGlc1TBTvsc0rW2IuKsSn tOANHviVgHO1pEGpuERRsP0haQjmarHEIau4QCgja9vjeUtVD0UVoRJH+SbFbTovu255 yk+A== 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=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay17si4903114ejb.356.2021.01.18.21.03.45; Mon, 18 Jan 2021 21:04:10 -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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407812AbhARSud (ORCPT + 99 others); Mon, 18 Jan 2021 13:50:33 -0500 Received: from foss.arm.com ([217.140.110.172]:42250 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407723AbhARSpp (ORCPT ); Mon, 18 Jan 2021 13:45:45 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4908BD6E; Mon, 18 Jan 2021 10:44:59 -0800 (PST) Received: from [10.57.39.58] (unknown [10.57.39.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1F54D3F719; Mon, 18 Jan 2021 10:44:55 -0800 (PST) Subject: Re: [PATCH v4 6/7] iommu/mediatek: Gather iova in iommu_unmap to achieve tlb sync once To: Yong Wu , Joerg Roedel , Will Deacon Cc: Matthias Brugger , Krzysztof Kozlowski , Tomasz Figa , linux-mediatek@lists.infradead.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, youlin.pei@mediatek.com, Nicolas Boichat , anan.sun@mediatek.com, chao.hao@mediatek.com, Greg Kroah-Hartman , kernel-team@android.com, Christoph Hellwig , David Laight References: <20210107122909.16317-1-yong.wu@mediatek.com> <20210107122909.16317-7-yong.wu@mediatek.com> From: Robin Murphy Message-ID: <57eb2ea5-f44c-9828-cbd4-9cb2af877ad8@arm.com> Date: Mon, 18 Jan 2021 18:44:56 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20210107122909.16317-7-yong.wu@mediatek.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-07 12:29, Yong Wu wrote: > 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. Reviewed-by: Robin Murphy > 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); > } >