Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2091572ybg; Thu, 24 Oct 2019 04:43:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhW1e6VDWuT4z5TVdsdqJMgFtPULF/abNnlVojaZ/jFUEjxY+Z+mB9JUHjIKDnl069H3yD X-Received: by 2002:a17:906:6544:: with SMTP id u4mr25676880ejn.274.1571917391552; Thu, 24 Oct 2019 04:43:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571917391; cv=none; d=google.com; s=arc-20160816; b=ISvutFyDYGi/1+6Q+p+R0HmuKD9ZWTuLbDUYPGoNmE1X+GCrCHZaGNPDowgHx8l87D hxJCjnNcc3hO9RVgwFfKyUqjh6HqFiZHnGC0laP0pRUYyq62jkDKeVgVSJAo2kdCkNua yLrhMkg6c83auUaiCTXO+CK20gJKfOH1+01ohvZkslcHWZovYo8l0ICQQI+Q1ZqTMxf+ qBkjHUPbMjmezEXw6xGrkX4KuUQHd3NKMBI1gM/y/Xcqgv8VRYiBgaqUJHnpz3+HdPQ4 qO+Dr1WRQl6ljUWMYkIFRw2PgYmQt0IuMe6Xhsg56IKSNdZIB8mVZBrWfq0xKg12bgUm i7+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+KVv9K4DaxemxJp2pX8wCnDahacVu1l57txUkDpF/eM=; b=E8MZjqOpWHIWCnf0lD8kaUlkQ6miGlVdfUPlhWcaRRZX6EvTSd+Sl8NKoFeHEomh6p MzHDb7sOF3ee2UPytFd8Ve0u32IF25nnQrWoSZLvwIUn+x56q/ORAmZI34MslnWPE04Q 6UZz2MuPNUgRGn0s5hMEA52kXw5BkIj0Eh4iPOY/l2j7pUGlYY98wHwgZSd0MDO7v0pE C9NhIgqHBLwwUiEBtjepT9GjJpw9W5kQjk9n1dIW2hPKkMui9lkX+3PHz8pGgP4YvGFC HRqwkClJuuNchFS1Z3zEBef8y30u5mTpmPEK6bT52t4JZEfLv2kzviD2Ff8vwwzA532i EMYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F6EnkV+N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s15si7999120eds.217.2019.10.24.04.42.47; Thu, 24 Oct 2019 04:43:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F6EnkV+N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726598AbfJWQzv (ORCPT + 99 others); Wed, 23 Oct 2019 12:55:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:34346 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbfJWQzu (ORCPT ); Wed, 23 Oct 2019 12:55:50 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 255AC21906; Wed, 23 Oct 2019 16:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571849750; bh=VPyPC4LePKk7uWBltRmK/Fded+OjFkz/1MBUzjK69yE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=F6EnkV+NncnzhwMOW6V6hkw45lZgsqg3/2TZtCGHZozEzQIq3KdMfSDzhP1HG7DEk M7mlDDT1+IBGeBeN7wjqNdxT1gyRg8gcrMld2vzIAOeKMgU6M5qaR4w4RXQRM3f8MR nDVUOk8sxVo9dbcnWMOHzMooezkVxez8zgQU2eWs= Date: Wed, 23 Oct 2019 17:55:44 +0100 From: Will Deacon To: Yong Wu Cc: Matthias Brugger , Joerg Roedel , Will Deacon , Evan Green , Robin Murphy , 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, cui.zhang@mediatek.com, chao.hao@mediatek.com, edison.hsieh@mediatek.com Subject: Re: [PATCH v4 3/7] iommu/mediatek: Use gather to achieve the tlb range flush Message-ID: <20191023165543.GB27471@willie-the-truck> References: <1571196792-12382-1-git-send-email-yong.wu@mediatek.com> <1571196792-12382-4-git-send-email-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1571196792-12382-4-git-send-email-yong.wu@mediatek.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 16, 2019 at 11:33:08AM +0800, Yong Wu wrote: > Use the iommu_gather mechanism to achieve the tlb range flush. > Gather the iova range in the "tlb_add_page", then flush the merged iova > range in iotlb_sync. > > Suggested-by: Tomasz Figa > Signed-off-by: Yong Wu > --- > drivers/iommu/mtk_iommu.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c > index c2f6c78..81ac95f 100644 > --- a/drivers/iommu/mtk_iommu.c > +++ b/drivers/iommu/mtk_iommu.c > @@ -245,11 +245,9 @@ static void mtk_iommu_tlb_flush_page_nosync(struct iommu_iotlb_gather *gather, > void *cookie) > { > struct mtk_iommu_data *data = cookie; > - unsigned long flags; > + struct iommu_domain *domain = &data->m4u_dom->domain; > > - spin_lock_irqsave(&data->tlb_lock, flags); > - mtk_iommu_tlb_add_flush_nosync(iova, granule, granule, true, cookie); > - spin_unlock_irqrestore(&data->tlb_lock, flags); > + iommu_iotlb_gather_add_page(domain, gather, iova, granule); You need to be careful here, because iommu_iotlb_gather_add_page() can call iommu_tlb_sync() in some situations and you don't hold the lock. > static const struct iommu_flush_ops mtk_iommu_flush_ops = { > @@ -469,9 +467,15 @@ static void mtk_iommu_iotlb_sync(struct iommu_domain *domain, > struct iommu_iotlb_gather *gather) > { > struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); > + size_t length = gather->end - gather->start; > unsigned long flags; > > + if (gather->start == ULONG_MAX) > + return; > + > spin_lock_irqsave(&data->tlb_lock, flags); > + mtk_iommu_tlb_add_flush_nosync(gather->start, length, gather->pgsize, > + false, data); > mtk_iommu_tlb_sync(data); > spin_unlock_irqrestore(&data->tlb_lock, flags); Modulo my comment above, this fixes my previous comment. Given that mainline is already broken, I guess the runtime bisectability isn't a problem. Will