From patchwork Tue Feb 20 20:25:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 10230817 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 08F48602A7 for ; Tue, 20 Feb 2018 20:25:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA541288E0 for ; Tue, 20 Feb 2018 20:25:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC144288E2; Tue, 20 Feb 2018 20:25:50 +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 [198.137.202.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 4ECBC288E0 for ; Tue, 20 Feb 2018 20:25:49 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=a0c1kXhYMy3lxcvJhgV/LaWRSdlaC/ch9GGfsqAM+04=; b=Ksw 6N8rCL35F8RigDNJuojT0yQ1ZUC5Zfrjt/FKZRtMpt7xwZSVRdeDwVX9rkihvfRi//+U0NNoFgKMy 4S1xxni/BGXXIU54yaG4bpzcLNsaB7Q2hQSnOGubKjZvkNhKbO4hOG1hkmdUPzK69GDV8nXZE74jm vW0XDPkam4RtYMAFdgBWDdz3iXA57lAjIzLYJacri6s4qXoy1tzZz8U82GHog3zASVyxH5jDAGGUb qzMbRlpMNP7XMCsvMhwu6QlBA/MZ7p+4wp+5RnT6c8i91Cg6zJlcHLDlET2OK7Q9KHGYpCoCQAdAG KAiboUxtgiiVDZI+RI/GoEaErjyiaOw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eoETl-0004DD-NF; Tue, 20 Feb 2018 20:25:33 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eoETh-0004Ar-6l; Tue, 20 Feb 2018 20:25:31 +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 A7F581529; Tue, 20 Feb 2018 12:25:16 -0800 (PST) Received: from why.lan (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3CAF43F25C; Tue, 20 Feb 2018 12:25:14 -0800 (PST) From: Marc Zyngier To: Joerg Roedel , Heiko Stuebner Subject: [PATCH] iommu/rockchip: Perform a reset on shutdown Date: Tue, 20 Feb 2018 20:25:04 +0000 Message-Id: <20180220202504.19275-1-marc.zyngier@arm.com> X-Mailer: git-send-email 2.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180220_122529_309895_166AF16B X-CRM114-Status: GOOD ( 11.35 ) 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: linux-rockchip@lists.infradead.org, iommu@lists.linux-foundation.org, Robin Murphy , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 Trying to do a kexec whilst the iommus are still on is proving to be a challenging exercise. It is terribly unsafe, as we're reusing the memory allocated for the page tables, leading to a likely crash. Let's implement a shutdown method that will at least try to stop DMA from going crazy behind our back. Note that we need to be extra cautious when doing so, as the IOMMU may not be clocked if controlled by a another master, as typical on Rockchip system. Suggested-by: Robin Murphy Signed-off-by: Marc Zyngier Reviewed-by: Robin Murphy --- drivers/iommu/rockchip-iommu.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 9d991c2d8767..6a3719e118da 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1209,6 +1209,23 @@ static int rk_iommu_remove(struct platform_device *pdev) return 0; } +static void rk_iommu_shutdown(struct platform_device *pdev) +{ + struct rk_iommu *iommu = platform_get_drvdata(pdev); + + /* + * Be careful not to try to shutdown an otherwise unused + * IOMMU, as it is likely not to be clocked, and accessing it + * would just block. An IOMMU without a domain is likely to be + * unused, so let's use this as a (weak) guard. + */ + if (iommu && iommu->domain) { + rk_iommu_enable_stall(iommu); + rk_iommu_disable_paging(iommu); + rk_iommu_force_reset(iommu); + } +} + static const struct of_device_id rk_iommu_dt_ids[] = { { .compatible = "rockchip,iommu" }, { /* sentinel */ } @@ -1218,6 +1235,7 @@ MODULE_DEVICE_TABLE(of, rk_iommu_dt_ids); static struct platform_driver rk_iommu_driver = { .probe = rk_iommu_probe, .remove = rk_iommu_remove, + .shutdown = rk_iommu_shutdown, .driver = { .name = "rk_iommu", .of_match_table = rk_iommu_dt_ids,