From patchwork Thu Dec 4 12:26:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 5437981 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E1D8EBEEA8 for ; Thu, 4 Dec 2014 12:29:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F292520253 for ; Thu, 4 Dec 2014 12:29:54 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 10D532024D for ; Thu, 4 Dec 2014 12:29:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XwVVM-00052e-Tk; Thu, 04 Dec 2014 12:27:32 +0000 Received: from service87.mimecast.com ([91.220.42.44]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XwVVK-0004pN-Am for linux-arm-kernel@lists.infradead.org; Thu, 04 Dec 2014 12:27:31 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by service87.mimecast.com; Thu, 04 Dec 2014 12:27:04 +0000 Received: from [10.1.215.44] ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 4 Dec 2014 12:27:03 +0000 Message-ID: <54805312.6000402@arm.com> Date: Thu, 04 Dec 2014 12:26:58 +0000 From: Robin Murphy User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Arnd Bergmann , "linux-arm-kernel@lists.infradead.org" , Will Deacon , "grant.likely@linaro.org" Subject: Re: [PATCH v6 1/8] iommu: provide early initialisation hook for IOMMU drivers References: <1417453034-21379-1-git-send-email-will.deacon@arm.com> <2579924.PPXuLn3o19@wuerfel> In-Reply-To: <2579924.PPXuLn3o19@wuerfel> X-OriginalArrivalTime: 04 Dec 2014 12:27:03.0212 (UTC) FILETIME=[9BDFDEC0:01D00FBD] X-MC-Unique: 114120412270400201 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141204_042730_666900_70F12C53 X-CRM114-Status: GOOD ( 14.22 ) X-Spam-Score: -2.3 (--) Cc: "jroedel@suse.de" , Pantelis Antoniou , Linux IOMMU , Thierry Reding , Laurent Pinchart , Varun Sethi , Hiroshi Doyu , David Woodhouse , Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Arnd, On 03/12/14 19:57, Arnd Bergmann wrote: [...] >> Good catch. This is not good. The data pointer should be avoided since >> there are no controls over its use. Until a better solution can be >> implemented, probably the safest thing to do is add a struct iommu_ops >> pointer to struct device_node. However, assuming that only a small >> portion of nodes will actually have iommu_ops set, I'd rather see a >> separate registry that matches device_nodes to iommu_ops. > > Fair enough. Will, can you take a copy of drivers/dma/of-dma.c and > adapt it as needed? It should be exactly what we need to start > out and can be extended and generalized later. I'm quite keen to see this series go in, since I'm depending on it to make arm64 IOMMU DMA ops "just work". Will and I came to the conclusion the other day that we pretty much need to build up some kind of bus abstraction based on the probe data in order to be able to assign IOMMU groups correctly, which can also subsume this particular problem in the long run. Since I've made a start on that already, I've hacked the following short-term fix out of it. Tested on my Juno - admittedly with only two SMMUs and one master (EHCI) being probed, but it didn't blow up or regress anything. Regards, Robin. --->8--- From 1f3d2612682c239e53f2c20e2ac5d19ef3f5387c Mon Sep 17 00:00:00 2001 Message-Id: <1f3d2612682c239e53f2c20e2ac5d19ef3f5387c.1417695078.git.robin.murphy@arm.com> From: Robin Murphy Date: Thu, 4 Dec 2014 11:53:13 +0000 Subject: [PATCH] iommu: store DT-probed IOMMU data privately Since the data pointer in the DT node is public and may be overwritten by conflicting code, move the DT-probed IOMMU ops to a private list where they will be safe. Signed-off-by: Robin Murphy --- drivers/iommu/of_iommu.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/of_iommu.h | 12 ++---------- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index 73236d3..5cd451c 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -94,6 +94,44 @@ int of_get_dma_window(struct device_node *dn, const char *prefix, int index, } EXPORT_SYMBOL_GPL(of_get_dma_window); +struct of_iommu_node { + struct hlist_node list; + struct device_node *np; + const struct iommu_ops *ops; +}; +static HLIST_HEAD(of_iommu_list); +static DEFINE_SPINLOCK(of_iommu_lock); + +void of_iommu_set_ops(struct device_node *np, const struct iommu_ops *ops) +{ + struct of_iommu_node *iommu = kmalloc(sizeof(*iommu), GFP_KERNEL); + + if (!iommu) + return; + + INIT_HLIST_NODE(&iommu->list); + iommu->np = np; + iommu->ops = ops; + spin_lock(&of_iommu_lock); + hlist_add_head(&iommu->list, &of_iommu_list); + spin_unlock(&of_iommu_lock); +} + +struct iommu_ops *of_iommu_get_ops(struct device_node *np) +{ + struct of_iommu_node *node; + const struct iommu_ops *ops = NULL; + + spin_lock(&of_iommu_lock); + hlist_for_each_entry(node, &of_iommu_list, list) + if (node->np == np) { + ops = node->ops; + break; + } + spin_unlock(&of_iommu_lock); + return (struct iommu_ops *)ops; +} + struct iommu_ops *of_iommu_configure(struct device *dev) { struct of_phandle_args iommu_spec; diff --git a/include/linux/of_iommu.h b/include/linux/of_iommu.h index d03abbb..e27c53a 100644 --- a/include/linux/of_iommu.h +++ b/include/linux/of_iommu.h @@ -31,16 +31,8 @@ static inline struct iommu_ops *of_iommu_configure(struct device *dev) #endif /* CONFIG_OF_IOMMU */ -static inline void of_iommu_set_ops(struct device_node *np, - const struct iommu_ops *ops) -{ - np->data = (struct iommu_ops *)ops; -} - -static inline struct iommu_ops *of_iommu_get_ops(struct device_node *np) -{ - return np->data; -} +void of_iommu_set_ops(struct device_node *np, const struct iommu_ops *ops); +struct iommu_ops *of_iommu_get_ops(struct device_node *np); extern struct of_device_id __iommu_of_table;