[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1401987808-23596-8-git-send-email-a.motakis@virtualopensystems.com>
Date: Thu, 5 Jun 2014 19:03:15 +0200
From: Antonios Motakis <a.motakis@...tualopensystems.com>
To: alex.williamson@...hat.com, kvmarm@...ts.cs.columbia.edu,
iommu@...ts.linux-foundation.org
Cc: tech@...tualopensystems.com, a.rigo@...tualopensystems.com,
kvm@...r.kernel.org, christoffer.dall@...aro.org,
will.deacon@....com, kim.phillips@...escale.com,
stuart.yoder@...escale.com, eric.auger@...aro.org,
Antonios Motakis <a.motakis@...tualopensystems.com>,
linux-kernel@...r.kernel.org (open list)
Subject: [RFC PATCH v6 07/20] vfio/iommu_type1: implement the VFIO_DMA_MAP_FLAG_NOEXEC flag
Some IOMMU drivers, such as the ARM SMMU driver, make available the
IOMMU_NOEXEC flag, to set the page tables for a device as XN (execute never).
This affects devices such as the ARM PL330 DMA Controller, which respects
this flag and will refuse to fetch DMA instructions from memory where the
XN flag has been set.
Signed-off-by: Antonios Motakis <a.motakis@...tualopensystems.com>
---
drivers/vfio/vfio_iommu_type1.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 6673e7b..e2566fd 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -80,6 +80,24 @@ struct vfio_group {
struct list_head next;
};
+static int vfio_domains_have_cap_noexec(struct vfio_iommu *iommu)
+{
+ struct vfio_domain *d;
+ int ret = 1;
+
+ mutex_lock(&iommu->lock);
+ list_for_each_entry(d, &iommu->domain_list, next) {
+ if (!iommu_domain_has_cap(d->domain, IOMMU_CAP_NOEXEC)) {
+ ret = 0;
+ break;
+ }
+ }
+ mutex_unlock(&iommu->lock);
+
+ return ret;
+}
+
+
/*
* This code handles mapping and unmapping of user data buffers
* into DMA'ble space using the IOMMU
@@ -542,6 +560,11 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu,
prot |= IOMMU_WRITE;
if (map->flags & VFIO_DMA_MAP_FLAG_READ)
prot |= IOMMU_READ;
+ if (map->flags & VFIO_DMA_MAP_FLAG_NOEXEC) {
+ if (!vfio_domains_have_cap_noexec(iommu))
+ return -EINVAL;
+ prot |= IOMMU_NOEXEC;
+ }
if (!prot)
return -EINVAL; /* No READ/WRITE? */
@@ -899,6 +922,10 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
if (!iommu)
return 0;
return vfio_domains_have_iommu_cache(iommu);
+ case VFIO_IOMMU_PROT_NOEXEC:
+ if (!iommu)
+ return 0;
+ return vfio_domains_have_cap_noexec(iommu);
default:
return 0;
}
@@ -922,7 +949,8 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
} else if (cmd == VFIO_IOMMU_MAP_DMA) {
struct vfio_iommu_type1_dma_map map;
uint32_t mask = VFIO_DMA_MAP_FLAG_READ |
- VFIO_DMA_MAP_FLAG_WRITE;
+ VFIO_DMA_MAP_FLAG_WRITE |
+ VFIO_DMA_MAP_FLAG_NOEXEC;
minsz = offsetofend(struct vfio_iommu_type1_dma_map, size);
--
1.8.3.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists