From: Eric Auger <eric.auger@linaro.org>
To: eric.auger@st.com, eric.auger@linaro.org, robin.murphy@arm.com,
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
Cc: patches@linaro.org, Manish.Jaggi@caviumnetworks.com,
linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org
Subject: [RFC v5 15/17] vfio/type1: also check IRQ remapping capability at msi domain
Date: Tue, 1 Mar 2016 18:27:55 +0000 [thread overview]
Message-ID: <1456856877-4817-16-git-send-email-eric.auger@linaro.org> (raw)
In-Reply-To: <1456856877-4817-1-git-send-email-eric.auger@linaro.org>
On x86 IRQ remapping is abstracted by the IOMMU. On ARM this is abstracted
by the msi controller. vfio_safe_irq_domain allows to check whether
interrupts are "safe" for a given device. They 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,
we 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 <eric.auger@linaro.org>
---
v3 -> v4:
- rename vfio_msi_parent_irq_remapping_capable into vfio_safe_irq_domain
and irq_remapping into safe_irq_domains
v2 -> v3:
- protect vfio_msi_parent_irq_remapping_capable with
CONFIG_GENERIC_MSI_IRQ_DOMAIN
---
drivers/vfio/vfio_iommu_type1.c | 44 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 42 insertions(+), 2 deletions(-)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 4e01ebe..88a40f1 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -37,6 +37,8 @@
#include <linux/vfio.h>
#include <linux/workqueue.h>
#include <linux/dma-reserved-iommu.h>
+#include <linux/irqdomain.h>
+#include <linux/msi.h>
#define DRIVER_VERSION "0.2"
#define DRIVER_AUTHOR "Alex Williamson <alex.williamson@redhat.com>"
@@ -788,6 +790,33 @@ static int vfio_bus_type(struct device *dev, void *data)
return 0;
}
+/**
+ * vfio_safe_irq_domain: returns whether the irq domain
+ * the device is attached to is safe with respect to MSI isolation.
+ * If the irq domain is not an MSI domain, we return it is safe.
+ *
+ * @dev: device handle
+ * @data: unused
+ * returns 0 if the irq domain is safe, -1 if not.
+ */
+static int vfio_safe_irq_domain(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)
{
@@ -882,7 +911,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, safe_irq_domains;
mutex_lock(&iommu->lock);
@@ -905,6 +934,13 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
group->iommu_group = iommu_group;
+ /*
+ * Determine if all the devices of the group have a safe irq domain
+ * with respect to MSI isolation
+ */
+ safe_irq_domains = !iommu_group_for_each_dev(iommu_group, &bus,
+ vfio_safe_irq_domain);
+
/* Determine bus_type in order to allocate a domain */
ret = iommu_group_for_each_dev(iommu_group, &bus, vfio_bus_type);
if (ret)
@@ -932,8 +968,12 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
INIT_LIST_HEAD(&domain->group_list);
list_add(&group->next, &domain->group_list);
+ /*
+ * to advertise safe interrupts either the IOMMU or the MSI controllers
+ * must support IRQ remapping/interrupt translation
+ */
if (!allow_unsafe_interrupts &&
- !iommu_capable(bus, IOMMU_CAP_INTR_REMAP)) {
+ (!iommu_capable(bus, IOMMU_CAP_INTR_REMAP) && !safe_irq_domains)) {
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;
--
1.9.1
next prev parent reply other threads:[~2016-03-01 18:27 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-01 18:27 [RFC v5 00/17] KVM PCIe/MSI passthrough on ARM/ARM64 Eric Auger
[not found] ` <1456856877-4817-1-git-send-email-eric.auger-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-03-01 18:27 ` [RFC v5 01/17] iommu: Add DOMAIN_ATTR_MSI_MAPPING attribute Eric Auger
2016-03-01 18:27 ` [RFC v5 06/17] dma-reserved-iommu: iommu_get/put_single_reserved Eric Auger
[not found] ` <1456856877-4817-7-git-send-email-eric.auger-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-03-10 11:52 ` Jean-Philippe Brucker
[not found] ` <20160310115253.GA14609-lfHAr0XZR/HZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2016-03-29 17:07 ` Eric Auger
2016-03-01 18:27 ` [RFC v5 02/17] iommu/arm-smmu: advertise DOMAIN_ATTR_MSI_MAPPING attribute Eric Auger
2016-03-01 18:27 ` [RFC v5 03/17] iommu: introduce a reserved iova cookie Eric Auger
2016-03-03 16:26 ` Julien Grall
2016-03-29 17:26 ` Eric Auger
2016-03-01 18:27 ` [RFC v5 04/17] dma-reserved-iommu: alloc/free_reserved_iova_domain Eric Auger
2016-03-01 18:27 ` [RFC v5 05/17] dma-reserved-iommu: reserved binding rb-tree and helpers Eric Auger
2016-03-01 18:27 ` [RFC v5 07/17] dma-reserved-iommu: iommu_unmap_reserved Eric Auger
2016-03-01 18:27 ` [RFC v5 08/17] msi: Add a new MSI_FLAG_IRQ_REMAPPING flag Eric Auger
2016-03-01 18:27 ` [RFC v5 09/17] irqchip/gic-v3-its: ITS advertises MSI_FLAG_IRQ_REMAPPING Eric Auger
2016-03-01 18:27 ` [RFC v5 10/17] msi: export msi_get_domain_info Eric Auger
2016-03-01 18:27 ` [RFC v5 11/17] msi: msi_compose wrapper Eric Auger
2016-03-01 18:27 ` [RFC v5 12/17] msi: IOMMU map the doorbell address when needed Eric Auger
2016-03-01 18:27 ` [RFC v5 13/17] vfio: introduce VFIO_IOVA_RESERVED vfio_dma type Eric Auger
2016-03-01 18:27 ` [RFC v5 14/17] vfio: allow the user to register reserved iova range for MSI mapping Eric Auger
2016-03-01 18:27 ` Eric Auger [this message]
2016-03-01 18:27 ` [RFC v5 16/17] iommu/arm-smmu: do not advertise IOMMU_CAP_INTR_REMAP Eric Auger
2016-03-01 18:27 ` [RFC v5 17/17] vfio/type1: return MSI mapping requirements with VFIO_IOMMU_GET_INFO Eric Auger
2016-03-02 8:11 ` [RFC v5 00/17] KVM PCIe/MSI passthrough on ARM/ARM64 Jaggi, Manish
[not found] ` <BY1PR0701MB1594168E79366B507B7C8A16E1BC0-vsFp3N3nJ9josxbTuffl3E5OhdzP3rhOnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2016-03-02 12:30 ` Eric Auger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456856877-4817-16-git-send-email-eric.auger@linaro.org \
--to=eric.auger@linaro.org \
--cc=Manish.Jaggi@caviumnetworks.com \
--cc=alex.williamson@redhat.com \
--cc=christoffer.dall@linaro.org \
--cc=eric.auger@st.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jason@lakedaemon.net \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=patches@linaro.org \
--cc=robin.murphy@arm.com \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).