[PATCH v2 12/13] vfio/type1: use iommu_attach_group() for wrapping PF/VF as mdev

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

 



This patch uses iommu_attach_group() to do group attach when it is
for the case of wrapping a PF/VF as a mdev. iommu_attach_device()
doesn't support non-singleton iommu group attach. With this change,
wrapping PF/VF as mdev can work on non-singleton iommu groups.

Cc: Kevin Tian <kevin.tian@xxxxxxxxx>
Cc: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
Suggested-by: Alex Williamson <alex.williamson@xxxxxxxxxx>
Signed-off-by: Liu Yi L <yi.l.liu@xxxxxxxxx>
---
 drivers/vfio/vfio_iommu_type1.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 054391f..317430d 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -1312,13 +1312,20 @@ static int vfio_mdev_attach_domain(struct device *dev, void *data)
 {
 	struct iommu_domain *domain = data;
 	struct device *iommu_device;
+	struct iommu_group *group;
 
 	iommu_device = vfio_mdev_get_iommu_device(dev);
 	if (iommu_device) {
 		if (iommu_dev_feature_enabled(iommu_device, IOMMU_DEV_FEAT_AUX))
 			return iommu_aux_attach_device(domain, iommu_device);
-		else
-			return iommu_attach_device(domain, iommu_device);
+		else {
+			group = iommu_group_get(iommu_device);
+			if (!group) {
+				WARN_ON(1);
+				return -EINVAL;
+			}
+			return iommu_attach_group(domain, group);
+		}
 	}
 
 	return -EINVAL;
@@ -1328,13 +1335,20 @@ static int vfio_mdev_detach_domain(struct device *dev, void *data)
 {
 	struct iommu_domain *domain = data;
 	struct device *iommu_device;
+	struct iommu_group *group;
 
 	iommu_device = vfio_mdev_get_iommu_device(dev);
 	if (iommu_device) {
 		if (iommu_dev_feature_enabled(iommu_device, IOMMU_DEV_FEAT_AUX))
 			iommu_aux_detach_device(domain, iommu_device);
-		else
-			iommu_detach_device(domain, iommu_device);
+		else {
+			group = iommu_group_get(iommu_device);
+			if (!group) {
+				WARN_ON(1);
+				return -EINVAL;
+			}
+			iommu_detach_group(domain, group);
+		}
 	}
 
 	return 0;
-- 
2.7.4




[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