[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <158751208274.36773.9573092458996405211.stgit@djiang5-desk3.ch.intel.com>
Date: Tue, 21 Apr 2020 16:34:42 -0700
From: Dave Jiang <dave.jiang@...el.com>
To: vkoul@...nel.org, megha.dey@...ux.intel.com, maz@...nel.org,
bhelgaas@...gle.com, rafael@...nel.org, gregkh@...uxfoundation.org,
tglx@...utronix.de, hpa@...or.com, alex.williamson@...hat.com,
jacob.jun.pan@...el.com, ashok.raj@...el.com, jgg@...lanox.com,
yi.l.liu@...el.com, baolu.lu@...el.com, kevin.tian@...el.com,
sanjay.k.kumar@...el.com, tony.luck@...el.com, jing.lin@...el.com,
dan.j.williams@...el.com, kwankhede@...dia.com,
eric.auger@...hat.com, parav@...lanox.com
Cc: dmaengine@...r.kernel.org, linux-kernel@...r.kernel.org,
x86@...nel.org, linux-pci@...r.kernel.org, kvm@...r.kernel.org
Subject: [PATCH RFC 09/15] vfio/type1: Save domain when attach domain to mdev
From: Lu Baolu <baolu.lu@...ux.intel.com>
This saves the iommu domain in mdev on attaching a domain
to it and clear it on detaching.
Cc: Ashok Raj <ashok.raj@...el.com>
Cc: Jacob Pan <jacob.jun.pan@...ux.intel.com>
Cc: Kevin Tian <kevin.tian@...el.com>
Cc: Liu Yi L <yi.l.liu@...el.com>
Signed-off-by: Lu Baolu <baolu.lu@...ux.intel.com>
---
drivers/vfio/vfio_iommu_type1.c | 52 ++++++++++++++++++++++++++++++++++++---
1 file changed, 48 insertions(+), 4 deletions(-)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 85b32c325282..40b22c456b06 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -1309,20 +1309,62 @@ static struct device *vfio_mdev_get_iommu_device(struct device *dev)
return NULL;
}
+static int vfio_mdev_set_domain(struct device *dev, struct iommu_domain *domain)
+{
+ void (*fn)(struct device *dev, void *domain);
+
+ fn = symbol_get(mdev_set_iommu_domain);
+ if (fn) {
+ fn(dev, domain);
+ symbol_put(mdev_set_iommu_domain);
+
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+static struct iommu_domain *vfio_mdev_get_domain(struct device *dev)
+{
+ void *(*fn)(struct device *dev);
+
+ fn = symbol_get(mdev_get_iommu_domain);
+ if (fn) {
+ struct iommu_domain *domain;
+
+ domain = fn(dev);
+ symbol_put(mdev_get_iommu_domain);
+
+ return domain;
+ }
+
+ return NULL;
+}
+
static int vfio_mdev_attach_domain(struct device *dev, void *data)
{
- struct iommu_domain *domain = data;
+ struct iommu_domain *domain;
struct device *iommu_device;
+ int ret = -ENODEV;
+
+ /* Only single domain is allowed to attach to an mdev. */
+ domain = vfio_mdev_get_domain(dev);
+ if (domain)
+ return -EINVAL;
+ domain = data;
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);
+ ret = iommu_aux_attach_device(domain, iommu_device);
else
- return iommu_attach_device(domain, iommu_device);
+ ret = iommu_attach_device(domain, iommu_device);
}
- return -EINVAL;
+ if (!ret)
+ vfio_mdev_set_domain(dev, domain);
+
+ return ret;
}
static int vfio_mdev_detach_domain(struct device *dev, void *data)
@@ -1338,6 +1380,8 @@ static int vfio_mdev_detach_domain(struct device *dev, void *data)
iommu_detach_device(domain, iommu_device);
}
+ vfio_mdev_set_domain(dev, NULL);
+
return 0;
}
Powered by blists - more mailing lists