From patchwork Wed Jan 4 13:32:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9496863 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 2E797606DE for ; Wed, 4 Jan 2017 13:42:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 236BA27EED for ; Wed, 4 Jan 2017 13:42:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1833E27F90; Wed, 4 Jan 2017 13:42:23 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 C16D727F89 for ; Wed, 4 Jan 2017 13:42:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760371AbdADNmR (ORCPT ); Wed, 4 Jan 2017 08:42:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36112 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030521AbdADNdg (ORCPT ); Wed, 4 Jan 2017 08:33:36 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 215074D690; Wed, 4 Jan 2017 13:33:37 +0000 (UTC) Received: from localhost.redhat.com (vpn1-4-93.ams2.redhat.com [10.36.4.93]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v04DWS26024520; Wed, 4 Jan 2017 08:33:32 -0500 From: Eric Auger To: eric.auger@redhat.com, eric.auger.pro@gmail.com, christoffer.dall@linaro.org, marc.zyngier@arm.com, robin.murphy@arm.com, alex.williamson@redhat.com, will.deacon@arm.com, joro@8bytes.org, tglx@linutronix.de, jason@lakedaemon.net, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, drjones@redhat.com, linux-kernel@vger.kernel.org, pranav.sawargaonkar@gmail.com, iommu@lists.linux-foundation.org, punit.agrawal@arm.com, diana.craciun@nxp.com, gpkulkarni@gmail.com, shankerd@codeaurora.org, bharat.bhushan@nxp.com, geethasowjanya.akula@gmail.com Subject: [PATCH v5 13/17] irqdomain: irq_domain_check_msi_remap Date: Wed, 4 Jan 2017 13:32:22 +0000 Message-Id: <1483536746-2725-14-git-send-email-eric.auger@redhat.com> In-Reply-To: <1483536746-2725-1-git-send-email-eric.auger@redhat.com> References: <1483536746-2725-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 04 Jan 2017 13:33:37 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This new function checks whether all platform and PCI MSI domains implement IRQ remapping. This is useful to understand whether VFIO passthrough is safe with respect to interrupts. On ARM typically an MSI controller can sit downstream to the IOMMU without preventing VFIO passthrough. As such any assigned device can write into the MSI doorbell. In case the MSI controller implements IRQ remapping, assigned devices will not be able to trigger interrupts towards the host. On the contrary, the assignment must be emphasized as unsafe with respect to interrupts. Signed-off-by: Eric Auger --- v4 -> v5: - Handle DOMAIN_BUS_FSL_MC_MSI domains - Check parents --- include/linux/irqdomain.h | 1 + kernel/irq/irqdomain.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h index ab017b2..281a40f 100644 --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -219,6 +219,7 @@ struct irq_domain *irq_domain_add_legacy(struct device_node *of_node, void *host_data); extern struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec, enum irq_domain_bus_token bus_token); +extern bool irq_domain_check_msi_remap(void); extern void irq_set_default_host(struct irq_domain *host); extern int irq_domain_alloc_descs(int virq, unsigned int nr_irqs, irq_hw_number_t hwirq, int node, diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index 8c0a0ae..700caea 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -278,6 +278,47 @@ struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec, EXPORT_SYMBOL_GPL(irq_find_matching_fwspec); /** + * irq_domain_is_msi_remap - Check if @domain or any parent + * has MSI remapping support + * @domain: domain pointer + */ +static bool irq_domain_is_msi_remap(struct irq_domain *domain) +{ + struct irq_domain *h = domain; + + for (; h; h = h->parent) { + if (h->flags & IRQ_DOMAIN_FLAG_MSI_REMAP) + return true; + } + return false; +} + +/** + * irq_domain_check_msi_remap() - Checks whether all MSI + * irq domains implement IRQ remapping + */ +bool irq_domain_check_msi_remap(void) +{ + struct irq_domain *h; + bool ret = true; + + mutex_lock(&irq_domain_mutex); + list_for_each_entry(h, &irq_domain_list, link) { + if (((h->bus_token & DOMAIN_BUS_PCI_MSI) || + (h->bus_token & DOMAIN_BUS_PLATFORM_MSI) || + (h->bus_token & DOMAIN_BUS_FSL_MC_MSI)) && + !irq_domain_is_msi_remap(h)) { + ret = false; + goto out; + } + } +out: + mutex_unlock(&irq_domain_mutex); + return ret; +} +EXPORT_SYMBOL_GPL(irq_domain_check_msi_remap); + +/** * irq_set_default_host() - Set a "default" irq domain * @domain: default domain pointer *