Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp514383pxu; Wed, 25 Nov 2020 08:42:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJz22SleSsizpfUe40ri5j7KsQg3oy3z5GrDDmFCjrs56CbeUFDuVw7fxRDed0z+Au7RO4tK X-Received: by 2002:a50:b224:: with SMTP id o33mr4155526edd.21.1606322529734; Wed, 25 Nov 2020 08:42:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606322529; cv=none; d=google.com; s=arc-20160816; b=kekXumsvuABLHiTqzzVdbXSUY+/8fO77+1X5VhaGyINuOitTnT1LRhVmD6LsAL8GiX 7RbTe40nTbr7x62tqT3UPLzsHg6Oc7x2HQnHoJk8i48UsSSZaAVDtHzxUm6W+JSnjF/x 2ix5+PKPNDjimkTekwaX1hKYB51plVhbe94TcEVnPCN41/NCzX/9+5+BkU0hNxoi2DFx RmePZApgHv28Tv/0MeZtEiFFLv/2C8PevkNS6iszG4BmP5xBgg9VwTXE9rmkZLP2eyeo 2uSyeeeSm9LradHozXEWKs7Nsu10nVLb8bIkgPVMJeFqDatlBZSZ60ArdrbvxoWqewqw n+7g== 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=4+iGrUh5riZITjY7Jy9wvSqUfPTdlPP+zs07AfgA2iM=; b=mEeMZJlw3fqoyQ6ZyUUsrGb+olHOqkAxN18EY1rUsURpjFGUqVwir+tSsVW7Qqokkr RyqMDgHNdrdoxdyZbkbfbUkPpEJBSljSv+zW4oVHiXbmVbTeAYbx4/XaWMCbJYDjbGAC vaMdWYfp32xzcw7cER1BVMbrbX3N55SmJ1wJ2hzxcoKXS/TrxCaDzhNGlogQJhvOhztT qkkQ6OSUCq/KAR/m7SHmwXTqbNuycWdWUWjUbAd1kjM8kIMtx0T1jiSKxP5kt0YV4cHr IsTMPBuCg+b2UygcajQ78/XwOHGYPgpfs0SVibLgHHaiTiz/ztFlWSXoaMIdwtqzdHsk HfsQ== 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 hs26si1523168ejc.229.2020.11.25.08.41.46; Wed, 25 Nov 2020 08:42:09 -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 S1730519AbgKYQhy (ORCPT + 99 others); Wed, 25 Nov 2020 11:37:54 -0500 Received: from foss.arm.com ([217.140.110.172]:58420 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730247AbgKYQhy (ORCPT ); Wed, 25 Nov 2020 11:37:54 -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 514B331B; Wed, 25 Nov 2020 08:37:53 -0800 (PST) Received: from [10.57.59.159] (unknown [10.57.59.159]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6FFA53F7BB; Wed, 25 Nov 2020 08:37:50 -0800 (PST) Subject: Re: [PATCH v2 1/6] iommu: Move iotlb_sync_map out from __iommu_map 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, jun.wen@mediatek.com References: <20201119061836.15238-1-yong.wu@mediatek.com> <20201119061836.15238-2-yong.wu@mediatek.com> From: Robin Murphy Message-ID: Date: Wed, 25 Nov 2020 16:37:48 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20201119061836.15238-2-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 2020-11-19 06:18, Yong Wu wrote: > 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. I don't see a way to avoid the boilerplate that wouldn't end up making things even more ugly and complicated, so: Reviewed-by: Robin Murphy > 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: >