From patchwork Fri Feb 12 08:13:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8288391 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1B00FBEEE5 for ; Fri, 12 Feb 2016 08:22:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2C097203AC for ; Fri, 12 Feb 2016 08:22:34 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4A844202EC for ; Fri, 12 Feb 2016 08:22:33 +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 1aU8yG-0004MZ-CT; Fri, 12 Feb 2016 08:20:56 +0000 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aU8sS-0004rB-JD for linux-arm-kernel@lists.infradead.org; Fri, 12 Feb 2016 08:15:01 +0000 Received: by mail-wm0-x232.google.com with SMTP id c200so9161812wme.0 for ; Fri, 12 Feb 2016 00:14:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3mDAdVDHlC6T0uVWc3BgPauYiV2hJcxKrr+6xx+hjh8=; b=Z2Tenk9/5FKV0/SIwiyDnANRAEOXGbUigSPJIvpAuZOcV5W3V2yR5mkNwXTioddhF4 H7m3Gid6awLkfn8ZtTlK+YqGhhU243Zpz38sKZkIMniaVQwtcuPxL9DfFvpi+PWGq/5e jG5q4aZTyvFIHu6bb6GWFu81J0FzjGvuEHlqc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3mDAdVDHlC6T0uVWc3BgPauYiV2hJcxKrr+6xx+hjh8=; b=PCujAKnRs6iWFMSj1Tt+KFPvPfWi9NtyjHfmgL8sTjRMFzjuPeG0K+ACGx8QcvGSot H8WwB/QHgGiKlZZTXUGVH7Rg+IJCUguM948rzWva6SgpHkRVMiICeMTca8rrqejzhrKq Xn+v9Qg3Xd93HkxEskrdX8LI6VUvvWB7tHMDS3sJPQi1X6hbfwKx4Ihx9fos9/X0qGT9 WlZukRRwsDdwG9gWuwT4Agk1hJMUTG6zC4Ij3sOIA/cJxYLQ1HSMoUI+BwmSfImUFE2o WkNebWYZoaAMPYFeVdAWDUOKKF12HYc5yEFVwFOJNwT7JUh9zmc5r3lsg9MbuzvkhwrP gS7Q== X-Gm-Message-State: AG10YOS2W5yHNMbDEcFrK0qQ31tzT+RAH87kLUEIPGc0fUKlvLw5xylDxFUmXjQVHSDui0Ds X-Received: by 10.194.92.68 with SMTP id ck4mr260416wjb.144.1455264874917; Fri, 12 Feb 2016 00:14:34 -0800 (PST) Received: from new-host-17.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id x66sm1243977wmb.20.2016.02.12.00.14.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Feb 2016 00:14:33 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, alex.williamson@redhat.com, will.deacon@arm.com, joro@8bytes.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, christoffer.dall@linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [RFC v3 13/15] vfio/type1: also check IRQ remapping capability at msi domain Date: Fri, 12 Feb 2016 08:13:15 +0000 Message-Id: <1455264797-2334-14-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455264797-2334-1-git-send-email-eric.auger@linaro.org> References: <1455264797-2334-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160212_001457_099433_6604F913 X-CRM114-Status: GOOD ( 16.81 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas.Lendacky@amd.com, brijesh.singh@amd.com, patches@linaro.org, Manish.Jaggi@caviumnetworks.com, p.fedin@samsung.com, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, iommu@lists.linux-foundation.org, pranav.sawargaonkar@gmail.com, leo.duran@amd.com, suravee.suthikulpanit@amd.com, sherry.hurwitz@amd.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 On x86 IRQ remapping is abstracted by the IOMMU. On ARM this is abstracted by the msi controller. vfio_msi_parent_irq_remapping_capable allows to check whether interrupts are "safe" for a given device. There are if the device does not use MSI or if the device uses MSI and the msi-parent controller supports IRQ remapping. Then we check at group level if all devices have safe interrupts: if not only allow the group to be attached if allow_unsafe_interrupts is set. At this point ARM sMMU still advertises IOMMU_CAP_INTR_REMAP. This is changed in next patch. Signed-off-by: Eric Auger --- v2 -> v3: - protect vfio_msi_parent_irq_remapping_capable with CONFIG_GENERIC_MSI_IRQ_DOMAIN --- drivers/vfio/vfio_iommu_type1.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index c5d3b48..3afb815 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include #define DRIVER_VERSION "0.2" #define DRIVER_AUTHOR "Alex Williamson " @@ -754,6 +756,32 @@ static int vfio_bus_type(struct device *dev, void *data) return 0; } +/** + * vfio_msi_parent_irq_remapping_capable: returns whether the device msi-parent + * controller supports IRQ remapping, aka interrupt translation + * + * @dev: device handle + * @data: unused + * returns 0 if irq remapping is supported or -1 if not supported. + */ +static int vfio_msi_parent_irq_remapping_capable(struct device *dev, void *data) +{ +#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN + struct irq_domain *domain; + struct msi_domain_info *info; + + domain = dev_get_msi_domain(dev); + if (!domain) + return 0; + + info = msi_get_domain_info(domain); + + if (!(info->flags & MSI_FLAG_IRQ_REMAPPING)) + return -1; +#endif + return 0; +} + static int vfio_iommu_replay(struct vfio_iommu *iommu, struct vfio_domain *domain) { @@ -848,7 +876,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, struct vfio_group *group, *g; struct vfio_domain *domain, *d; struct bus_type *bus = NULL; - int ret; + int ret, irq_remapping; mutex_lock(&iommu->lock); @@ -871,6 +899,13 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, group->iommu_group = iommu_group; + /* + * Determine if all the devices of the group has an MSI-parent that + * supports irq remapping + */ + irq_remapping = !iommu_group_for_each_dev(iommu_group, &bus, + vfio_msi_parent_irq_remapping_capable); + /* Determine bus_type in order to allocate a domain */ ret = iommu_group_for_each_dev(iommu_group, &bus, vfio_bus_type); if (ret) @@ -899,7 +934,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, list_add(&group->next, &domain->group_list); if (!allow_unsafe_interrupts && - !iommu_capable(bus, IOMMU_CAP_INTR_REMAP)) { + (!iommu_capable(bus, IOMMU_CAP_INTR_REMAP) && !irq_remapping)) { pr_warn("%s: No interrupt remapping support. Use the module param \"allow_unsafe_interrupts\" to enable VFIO IOMMU support on this platform\n", __func__); ret = -EPERM;