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: 9540609 X-Patchwork-Delegate: geert@linux-m68k.org 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 7E80B604B9 for ; Fri, 27 Jan 2017 06:21:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F83127F17 for ; Fri, 27 Jan 2017 06:21:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61E9228112; Fri, 27 Jan 2017 06:21:52 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B11727F17 for ; Fri, 27 Jan 2017 06:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753898AbdA0GVv (ORCPT ); Fri, 27 Jan 2017 01:21:51 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:34333 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753948AbdA0GVt (ORCPT ); Fri, 27 Jan 2017 01:21:49 -0500 Received: by mail-pg0-f67.google.com with SMTP id 3so6484548pgj.1 for ; Thu, 26 Jan 2017 22:20: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=RL8UAnsGsMPUa59/69ttsNOfpAI8Pqa5udzHiPon2eLnru4d592hziY1xb2xeIPnCb MM2w4EpxTVh7ItXpMak71ciU+MIL7ObmFQRH1VvcUwAqT0/Wasrqlf5DRvAmUthn3jw0 I65liB0OPDM3wC5Spds/wcXvE15P4FWLfQXpFMsN5ItuJhXknTVyt+g+Dx2OCGVK/Qv4 k9EXI/wJeTS3Dsq4dB6sjZ1bZAIPheoL048aloWndhmKHvAJjYFbaZBUFjeRfm/DWxpB 6xJABJaEbiDa98rwfBLvfEmxYmq7aS3chbOt4/zA7SfRy+i5ktaejqlpg1dNg27YNxSM w0fQ== X-Gm-Message-State: AIkVDXKqnRyGvUR5ySz2h3kypS5Qnn8L0T8svqWKiNrfGsvggt/LG68c0FtJ8vrX9Z65Tg== 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 Cc: laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be, joro@8bytes.org, linux-renesas-soc@vger.kernel.org, horms+renesas@verge.net.au, Magnus Damm , robin.murphy@arm.com, linux-arm-kernel@lists.infradead.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() Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.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, };