Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2091477ybg; Thu, 24 Oct 2019 04:43:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqxD7Zsuh6Fj7+ChcN0FguEeAhpHvkB9T7b54chTnLpCuNUkTsusPi67wG+I3brn6AM2CEyq X-Received: by 2002:aa7:c498:: with SMTP id m24mr30392367edq.113.1571917386262; Thu, 24 Oct 2019 04:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571917386; cv=none; d=google.com; s=arc-20160816; b=YZF4zYCIZouBbafvSuuzOe9lkI1Uo92UJIjp0HEQhdKAyVPTUsezKhNlqU3jMhXEAi FHTfoMYhMuX+Dwi6kaIAQ5FpEotGUZiDnmhd6pKm0R98GgwRi9nsL5FY6xh9ztBtvbu3 veA7LGDqPz40dTP9jS3XvLBZ7N0gheal1nUGeOuB1QhcdN1f6WQELmPsMQ7y0YH8Jyuz UC50LXYxrULIzfR1wkuLgjscGQ7S2EroimkCKMeMh/oqSV+BuZVmBPO5d0VcjJVV1SYm rR/KuWxcGMsa5amA2eUQNZ7vBPn5S/YIP8uMYWIW1lAifC5q8vvBKuuAGXZiKJzUNu07 htaA== 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=qIUj307g2HVOjp7Rr3ddFrARIDz6NW8BKG/2/DExYrU=; b=veG2EjcNDsbQtKeuM9RjDss/7b5h+fAMu+U7maEIgkxS+YsQ7ZOFQXBAokAknOX1WC X3QAdggju4KCR8iWqrsrgF5Id3NinQyYmPtHy07Jby+EI8GGt8tpbOwHwnTZSH3TMB3f 62eBPWTik4K7PORNFw92rHxKi89PY7zIyY1EQWbjpwWjXhrhJ77XpohzY0W4Cj/B4ayW TyDIohCxdPV6/ZhQZcjJhJ1xKNnEw548eS9NJnKChtYz2ufBSXHPKE0QeRucSEIgTG9J k9yGCnqtVQFaxHt9UW7rnMQZU54v5l7yv2ZH8uG2hgT2ToD/dE1c20W1D801IGKUW6JZ 7I9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vM3wriHv; 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 z97si10515271ede.122.2019.10.24.04.42.41; Thu, 24 Oct 2019 04:43:06 -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=vM3wriHv; 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 S1726528AbfJWQxA (ORCPT + 99 others); Wed, 23 Oct 2019 12:53:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:33620 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbfJWQxA (ORCPT ); Wed, 23 Oct 2019 12:53:00 -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 8F2EF21906; Wed, 23 Oct 2019 16:52:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571849579; bh=F5Izp3I8AX+Ri+LTIkBe2psZof2nJUu/2jw8CqPmo+4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vM3wriHv2BCfsl4QWE/Yo0Tr9tEwuSOYD/+jXqoi+TwKpYLw+r7KqC/INuDeE6paR 8kN95fF7O/278RKBRp+COHuOA0qlcJLdeS3sShi0ETrCZk8FOTwW3RTHbduQUIfc83 EcxQlpdh+2SDSt3EWDK/G1983yOPo7V7MQo9/1sY= Date: Wed, 23 Oct 2019 17:52:53 +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 2/7] iommu/mediatek: Add a new tlb_lock for tlb_flush Message-ID: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1571196792-12382-3-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: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()? Will