From patchwork Fri Jan 27 06:14:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 9540617 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 B076C60429 for ; Fri, 27 Jan 2017 06:23:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F9AE27F85 for ; Fri, 27 Jan 2017 06:23:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9270228112; Fri, 27 Jan 2017 06:23:48 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=no 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 280C627F85 for ; Fri, 27 Jan 2017 06:23:48 +0000 (UTC) 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 1cWzwm-0003un-0r; Fri, 27 Jan 2017 06:23:44 +0000 Received: from mail-pg0-f67.google.com ([74.125.83.67]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cWzvK-0002vO-Rm for linux-arm-kernel@lists.infradead.org; Fri, 27 Jan 2017 06:22:17 +0000 Received: by mail-pg0-f67.google.com with SMTP id 194so24246227pgd.0 for ; Thu, 26 Jan 2017 22:21:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:date:message-id:in-reply-to:references:subject; bh=HE68FArIC3XwMMjnvVaD4Xml1Orp+CffbM3/qu87eWY=; b=A/PDsSYkvx+KuUwSN3PG25vDJqxe1DlXRir4gGsMMvnDQNlb5UNLzk+ykxaDi/EqnT C+wr2SYxFRxO4niYRit09EGRr+qAszxVXqdcAnxAEbANzLBr6GFC3mZLw9Jpf1mh3FdW QJciQ899fVtSawY+71KbEQRSt8eqCimxBBZdVJ4MZsrqKIVD8X4yyV8HQccwhz9tKIo9 hPuGRiBrk3HKUfUrIppdfSfaxIZ+/rZ1zLMMYiFg8Cz4o3xYPcKBkuktYhcGLKuWN+7x lJbVWYoMGuZG4tCw3LogBSuHSuUQ/HcF3IjCJbq5j2S1AV2/r6A0ijiX6P5fznGQ9gWc ADrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:date:message-id:in-reply-to :references:subject; bh=HE68FArIC3XwMMjnvVaD4Xml1Orp+CffbM3/qu87eWY=; b=EwqWLOyO237AKENyRiB+mEQadTZ2h1oUq2mBT/Vw0G3CQyo8eFtua6b6QQWg8JFB77 DWUAkUZvHzhNuZJw+FYZ2XkjFiicX/nFARWOQt5MuHdafec4hgtgdUeAamuhOei8zUtY fd6CrCCssaWeKBPUWNkE2QQdidh4MCp1RU5TAQJ7CBnXU3dU5wfGcUeU1zSdGQBzxASh 9fx2sQuaQL1VZud6bhptRfAHu1+VF3ihsU2iZagOsmMEgMtpWJXQroHZixvwvw3J2Zrp N6yZO2nhddE3+O3H7Z54shNG308cFtjQuzlcK1JGnLB7Nq0RFe8u7FibAhxyy4XELw4g fr3g== X-Gm-Message-State: AIkVDXIBVSQMQeYiRfPYnuKdwvLmro7zc1CTiARPD5pqHuttO0RE6htZWyybrEoOlpjCrg== X-Received: by 10.99.113.82 with SMTP id b18mr7732694pgn.118.1485498053970; Thu, 26 Jan 2017 22:20:53 -0800 (PST) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by smtp.gmail.com with ESMTPSA id t14sm7740783pfk.85.2017.01.26.22.20.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jan 2017 22:20:53 -0800 (PST) From: Magnus Damm To: iommu@lists.linux-foundation.org Date: Fri, 27 Jan 2017 15:14:36 +0900 Message-Id: <148549767671.22203.10735883809069203556.sendpatchset@little-apple> In-Reply-To: <148549764733.22203.16459470412085471955.sendpatchset@little-apple> References: <148549764733.22203.16459470412085471955.sendpatchset@little-apple> Subject: [PATCH/RFC v2 3/4] iommu/ipmmu-vmsa: Check devices in xlate() X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170126_222215_004667_61E513AF X-CRM114-Status: GOOD ( 13.67 ) 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: laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be, joro@8bytes.org, Magnus Damm , linux-renesas-soc@vger.kernel.org, horms+renesas@verge.net.au, robin.murphy@arm.com, 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 From: Magnus Damm Rework the IPMMU code to validate devices in ->xlate() instead of accepting all devices in xlate() and instead validating devices in ->add_device(). This makes it possible for the IPMMU device driver to reject slave devices based on software policy. Once a slave device is rejected by the ->xlate() callback the shared function of_iommu_configure() will fail as well which in turn disables per-device IOMMU handing in the arch-specific mapping code by not passing any IOMMU callbacks to arch_setup_dma_ops(). Signed-off-by: Magnus Damm --- TODO: Make sure this does not break R-Car Gen2 support drivers/iommu/ipmmu-vmsa.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) --- 0007/drivers/iommu/ipmmu-vmsa.c +++ work/drivers/iommu/ipmmu-vmsa.c 2017-01-27 13:11:35.970607110 +0900 @@ -1007,16 +1007,14 @@ static int ipmmu_add_device_dma(struct d struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu; struct iommu_group *group; - /* only accept devices with iommus property */ - if (of_count_phandle_with_args(dev->of_node, "iommus", - "#iommu-cells") < 0) + /* The device needs to be verified in xlate() */ + if (!archdata) return -ENODEV; group = iommu_group_get_for_dev(dev); if (IS_ERR(group)) return PTR_ERR(group); - archdata = dev->archdata.iommu; spin_lock(&ipmmu_slave_devices_lock); list_add(&archdata->list, &ipmmu_slave_devices); spin_unlock(&ipmmu_slave_devices_lock); @@ -1034,24 +1032,13 @@ static void ipmmu_remove_device_dma(stru iommu_group_remove_device(dev); } -static struct iommu_group *ipmmu_device_group_dma(struct device *dev) -{ - struct iommu_group *group; - int ret; - - ret = ipmmu_init_platform_device(dev); - if (!ret) - group = ipmmu_find_group(dev); - else - group = ERR_PTR(ret); - - return group; -} - static int ipmmu_of_xlate_dma(struct device *dev, struct of_phandle_args *spec) { - return 0; + /* For now only tested on R-Car Gen3 with ARM64 arch init order + * TODO: Test R-Car Gen2 with ARM32 arch init order + */ + return ipmmu_init_platform_device(dev); } static const struct iommu_ops ipmmu_ops = { @@ -1065,7 +1052,7 @@ static const struct iommu_ops ipmmu_ops .iova_to_phys = ipmmu_iova_to_phys, .add_device = ipmmu_add_device_dma, .remove_device = ipmmu_remove_device_dma, - .device_group = ipmmu_device_group_dma, + .device_group = ipmmu_find_group, .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, .of_xlate = ipmmu_of_xlate_dma, };