[PATCH v4 10/13] iommu/vt-d: Fail SVA domain replacement

Yi Liu
2024-11-04T13:18:56Z

There is no known usage that will attach SVA domain or detach SVA domain
by replacing PASID to or from SVA domain. It is supposed to use the
iommu_sva_{un}bind_device() which invoke the iommu_{at|de}tach_device_pasid().
So Intel iommu driver decides to fail the domain replacement if the old
domain or new domain is SVA type.

Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
drivers/iommu/intel/iommu.c | 8 ++++++++
drivers/iommu/intel/svm.c | 3 +++
2 files changed, 11 insertions(+)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 0e0e9eb5188a..7e82b3a4bba7 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4352,6 +4352,10 @@ static int intel_iommu_set_dev_pasid(struct iommu_domain *domain,
if (WARN_ON_ONCE(!(domain->type & __IOMMU_DOMAIN_PAGING)))
return -EINVAL;

+ /* No SVA domain replacement usage so far */
+ if (old && old->type == IOMMU_DOMAIN_SVA)
+ return -EOPNOTSUPP;
+
if (!pasid_supported(iommu) || dev_is_real_dma_subdevice(dev))
return -EOPNOTSUPP;

@@ -4620,6 +4624,10 @@ static int identity_domain_set_dev_pasid(struct iommu_domain *domain,
struct intel_iommu *iommu = info->iommu;
int ret;

+ /* No SVA domain replacement usage so far */
+ if (old && old->type == IOMMU_DOMAIN_SVA)
+ return -EOPNOTSUPP;
+
if (!pasid_supported(iommu) || dev_is_real_dma_subdevice(dev))
return -EOPNOTSUPP;

diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c
index 925afca7529e..06404716ad37 100644
--- a/drivers/iommu/intel/svm.c
+++ b/drivers/iommu/intel/svm.c
@@ -207,6 +207,9 @@ static int intel_svm_set_dev_pasid(struct iommu_domain *domain,
unsigned long sflags;
int ret = 0;

+ if (old)
+ return -EOPNOTSUPP;
+
dev_pasid = domain_add_dev_pasid(domain, dev, pasid);
if (IS_ERR(dev_pasid))
return PTR_ERR(dev_pasid);
--
2.34.1