Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2706865ybg; Thu, 24 Oct 2019 13:55:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6vrCQ3gnqaIqzgCJ4OxF/12q0IbkdC+E//+ABMvM09jM6lZyabCZ4jIlkeF1Qc61W9x01 X-Received: by 2002:aa7:d8c7:: with SMTP id k7mr207679eds.138.1571950546872; Thu, 24 Oct 2019 13:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571950546; cv=none; d=google.com; s=arc-20160816; b=S2KkA+lcHxEz2wiPsFJ7gkvBfolvqNmHghu4a3MAs5DdSVwHr8pgVOG3DqLO9Zk+nk uceS+RooUA0dxLsFbZ80Jp9Gy3sTu+OwoMt8RjwwYLLf+HFpFJaCIFNpsYHdX5yAFSqP 5rE/pDcKg/EB9QdAytMKSmWVygdbL71ViNmF8nh/pGr6tpxV/UOGDKNUTBPJyAzcWrY1 H2N3UXjFoQo0drzTxVe4a5K0VJGnaDEai1k12JjLmonbPIIwPU7X2vI8ptNnD/MGJ7GR Oc+89m6jm4E1I6EUaXlvwNroePXgEuqgTNOtVqSH9WS6dhXrUXGBT250OSD1Q8+SMQn2 vNLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=P+ia8QXQOvWkAMfHnBso9yLLKCBJuxhkkDTmPU0UthY=; b=D2hVoVqaSO2jv524XnjiUPu5kLtM0uE++ywc0BemZAtXLcCHpfXFBx6XWQx/OLm996 IJNUGbwExOXJu2b86eLc0nrav6qSGG5AqQL3wQsRD2EfraJnJsoHqvz7ZhTBJxw1mYFJ 2I8SSlRFX4Beuvom9axygt9U0h6meqnKnVchkp+27RkSrzEsKp7Q/h9AJvLwU98S/yWg cCUY5/44+1XgomVL2dpY/zkuGZBRef8Zp7RMZMgnqNz8JVSAlE/gVeKFKYe/93TzK0tS /UT8KgqSb6m92xG+vfuSyzgUkuxv+tgmqiLQbdiKjoNxQn4jL0SyevOi8ZKKE+VbAsPF 8iHg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j26si5475694ejd.138.2019.10.24.13.55.22; Thu, 24 Oct 2019 13:55:46 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392939AbfJXHWr (ORCPT + 99 others); Thu, 24 Oct 2019 03:22:47 -0400 Received: from Mailgw01.mediatek.com ([1.203.163.78]:63411 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390783AbfJXHWp (ORCPT ); Thu, 24 Oct 2019 03:22:45 -0400 X-UUID: d19484b7065342aa99b1cf23ca602cb3-20191024 X-UUID: d19484b7065342aa99b1cf23ca602cb3-20191024 Received: from mtkcas32.mediatek.inc [(172.27.4.253)] by mailgw01.mediatek.com (envelope-from ) (mailgw01.mediatek.com ESMTP with TLS) with ESMTP id 6435572; Thu, 24 Oct 2019 15:22:30 +0800 Received: from MTKCAS36.mediatek.inc (172.27.4.186) by MTKMBS31N1.mediatek.inc (172.27.4.69) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 24 Oct 2019 15:22:26 +0800 Received: from [10.17.3.153] (172.27.4.253) by MTKCAS36.mediatek.inc (172.27.4.170) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 24 Oct 2019 15:22:25 +0800 Message-ID: <1571901746.19130.134.camel@mhfsdcap03> Subject: Re: [PATCH v4 2/7] iommu/mediatek: Add a new tlb_lock for tlb_flush From: Yong Wu To: Will Deacon CC: Matthias Brugger , Joerg Roedel , Will Deacon , Evan Green , Robin Murphy , Tomasz Figa , , , , , , , Nicolas Boichat , , , , Date: Thu, 24 Oct 2019 15:22:26 +0800 In-Reply-To: <20191023165252.GA27471@willie-the-truck> References: <1571196792-12382-1-git-send-email-yong.wu@mediatek.com> <1571196792-12382-3-git-send-email-yong.wu@mediatek.com> <20191023165252.GA27471@willie-the-truck> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-SNTS-SMTP: A424D45C3762AE65D19C9E0D6AC3052D0F4FDCA255F395DA386AC98B86DDEC702000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2019-10-23 at 17:52 +0100, Will Deacon wrote: > On Wed, Oct 16, 2019 at 11:33:07AM +0800, Yong Wu wrote: > > The commit 4d689b619445 ("iommu/io-pgtable-arm-v7s: Convert to IOMMU API > > TLB sync") help move the tlb_sync of unmap from v7s into the iommu > > framework. It helps add a new function "mtk_iommu_iotlb_sync", But it > > lacked the lock, then it will cause the variable "tlb_flush_active" > > may be changed unexpectedly, we could see this warning log randomly: > > > > mtk-iommu 10205000.iommu: Partial TLB flush timed out, falling back to > > full flush > > > > The HW requires tlb_flush/tlb_sync in pairs strictly, this patch adds > > a new tlb_lock for tlb operations to fix this issue. > > > > Fixes: 4d689b619445 ("iommu/io-pgtable-arm-v7s: Convert to IOMMU API TLB > > sync") > > Signed-off-by: Yong Wu > > --- > > drivers/iommu/mtk_iommu.c | 23 ++++++++++++++++++++++- > > drivers/iommu/mtk_iommu.h | 1 + > > 2 files changed, 23 insertions(+), 1 deletion(-) > > [...] > > > static void mtk_iommu_tlb_flush_page_nosync(struct iommu_iotlb_gather *gather, > > unsigned long iova, size_t granule, > > void *cookie) > > { > > + struct mtk_iommu_data *data = cookie; > > + unsigned long flags; > > + > > + 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); > > Given that you release the lock here, what prevents another nosync() > operation being issued before you've managed to do the sync()? This patch can not guarantee each flush_nosync() always followed by a sync(). The current mainline don't guarantee this too(Current v7s call flush_nosync 16 times, then call tlb_sync 1 time in the supersection/largepage case.). At this situation, it don't guarantee the previous tlb_flushes are finished, But we never got the timeout issue(Fortunately our HW always work well at that time. Maybe the HW finish the previous tlb flush so quickly even though we don't polling its finish flag). We got the timeout issue only after this commit 4d689b619445. This patch only fixes this issue via adding a new lock in iotlb_sync.(It don't adjust the sequence of flush_nosync() and sync()). > > Will