[RFC,v1,2/2] vfio/iommu-type1: set only stage 2 translation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Normally, VFIO should use only stage 2 translation of
iommu, to create the address mapping. If nesting translation
is disabled from VFIO core, enable iommu domain only stage 2
attribute, otherwise, enable iommu domain nesting attribute.

Signed-off-by: Rick Song <songwenjun@xxxxxxxxxx>
---
 drivers/vfio/vfio_iommu_type1.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 2ba1942..c0265fe 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -741,7 +741,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 attr, ret;
 
 	mutex_lock(&iommu->lock);
 
@@ -775,13 +775,22 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
 		goto out_free;
 	}
 
+	/*
+	 * Set iommu nesting domain attribute if nesting translation
+	 * is enabled from iommu vfio, otherwise set iommu only stage
+	 * 2 domain attribute.
+	 */
+	attr = 1;
 	if (iommu->nesting) {
-		int attr = 1;
-
 		ret = iommu_domain_set_attr(domain->domain, DOMAIN_ATTR_NESTING,
 					    &attr);
 		if (ret)
 			goto out_domain;
+	} else {
+		ret = iommu_domain_set_attr(domain->domain, DOMAIN_ATTR_S2,
+					    &attr);
+		if (ret)
+			goto out_domain;
 	}
 
 	ret = iommu_attach_group(domain->domain, iommu_group);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux