From patchwork Wed Jun 28 11:46:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 9814025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5295860383 for ; Wed, 28 Jun 2017 11:46:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4503E1FF60 for ; Wed, 28 Jun 2017 11:46:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39A8520223; Wed, 28 Jun 2017 11:46:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B9D2C1FF60 for ; Wed, 28 Jun 2017 11:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Na6U25IdhrblBayYFKCRy/jpW619AEBCThY07D1ftE0=; b=bgxP64pl1spd3c CZgu/bDP+Tq7hyw564ZhIa+1/TSp12f3clqoiNqthLtF+w5OTe5mLFLwYrAqVK8RFTjcodSQmCtSK iv1+HZLmx1pXgBMyoYHygFRq4H4bdH7DJGOrzbUfZoDWtlLqQ0mhQuv2Oy/d1eqAPLzK43pqozjGX X3sYtFlEjWir3fzNEsfNruVNuOasVz3/HOnEb66G1V+g8Nx45tLxz9T16CHriF77WmyvHAImTioUW RpP7dczEsYbg1gqwaf58eM9o1jPXiihDxW9XVGG/BdDA5kh9r3rwLs5UE1tQpJz5uZI6OdJEryIq/ c4Nf34OiaLSQVMulO9ig==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dQBQW-0000oJ-UI; Wed, 28 Jun 2017 11:46:32 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dQBQU-0000mD-QS for linux-arm-kernel@lists.infradead.org; Wed, 28 Jun 2017 11:46:32 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3110F344; Wed, 28 Jun 2017 04:46:10 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 029A93F41F; Wed, 28 Jun 2017 04:46:10 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 0AF5D1AE2F3C; Wed, 28 Jun 2017 12:46:10 +0100 (BST) Date: Wed, 28 Jun 2017 12:46:09 +0100 From: Will Deacon To: Ray Jui Subject: Re: [PATCH 0/8] io-pgtable lock removal Message-ID: <20170628114609.GD11053@arm.com> References: <458ad41d-6679-eeca-3c0f-13ccb6c933b6@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170628_044630_867018_27EA7FF5 X-CRM114-Status: GOOD ( 14.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: salil.mehta@huawei.com, sunil.goutham@cavium.com, joro@8bytes.org, iommu@lists.linux-foundation.org, Nate Watterson , linu.cherian@cavium.com, Robin Murphy , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Ray, Robin and I have been bashing our heads against the tlb_sync_pending flag this morning, and we reckon it could have something to do with your timeouts on MMU-500. On Tue, Jun 27, 2017 at 09:43:19AM -0700, Ray Jui wrote: > >> Also, in a few occasions, I observed the following message during the > >> test, when multiple cores are involved: > >> > >> arm-smmu 64000000.mmu: TLB sync timed out -- SMMU may be deadlocked The tlb_sync_pending logic was written under the assumption of a global page-table lock, so it assumes that it only has to care about syncing flushes from the current CPU/context. That's not true anymore, and the current code can accidentally skip syncs and (what I think is happening in your case) allow concurrent syncs, which will potentially lead to timeouts if a CPU is unlucky enough to keep missing the Ack. Please can you try the diff below and see if it fixes things for you? This applies on top of my for-joerg/arm-smmu/updates branch, but note that I've only shown it to the compiler. Not tested at all. Will --->8 diff --git a/drivers/iommu/io-pgtable.c b/drivers/iommu/io-pgtable.c index 127558d83667..cd8d7aaec161 100644 --- a/drivers/iommu/io-pgtable.c +++ b/drivers/iommu/io-pgtable.c @@ -59,6 +59,7 @@ struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt, iop->cookie = cookie; iop->cfg = *cfg; + atomic_set(&iop->tlb_sync_pending, 0); return &iop->ops; } diff --git a/drivers/iommu/io-pgtable.h b/drivers/iommu/io-pgtable.h index 524263a7ae6f..b64580c9d03d 100644 --- a/drivers/iommu/io-pgtable.h +++ b/drivers/iommu/io-pgtable.h @@ -1,5 +1,7 @@ #ifndef __IO_PGTABLE_H #define __IO_PGTABLE_H + +#include #include /* @@ -165,7 +167,7 @@ void free_io_pgtable_ops(struct io_pgtable_ops *ops); struct io_pgtable { enum io_pgtable_fmt fmt; void *cookie; - bool tlb_sync_pending; + atomic_t tlb_sync_pending; struct io_pgtable_cfg cfg; struct io_pgtable_ops ops; }; @@ -175,22 +177,20 @@ struct io_pgtable { static inline void io_pgtable_tlb_flush_all(struct io_pgtable *iop) { iop->cfg.tlb->tlb_flush_all(iop->cookie); - iop->tlb_sync_pending = true; + atomic_set_release(&iop->tlb_sync_pending, 1); } static inline void io_pgtable_tlb_add_flush(struct io_pgtable *iop, unsigned long iova, size_t size, size_t granule, bool leaf) { iop->cfg.tlb->tlb_add_flush(iova, size, granule, leaf, iop->cookie); - iop->tlb_sync_pending = true; + atomic_set_release(&iop->tlb_sync_pending, 1); } static inline void io_pgtable_tlb_sync(struct io_pgtable *iop) { - if (iop->tlb_sync_pending) { + if (atomic_xchg_relaxed(&iop->tlb_sync_pending, 0)) iop->cfg.tlb->tlb_sync(iop->cookie); - iop->tlb_sync_pending = false; - } } /**