diff mbox series

[v4,08/13] iommu/vt-d: Make identity_domain_set_dev_pasid() to handle domain replacement

Message ID 20241104131842.13303-9-yi.l.liu@intel.com (mailing list archive)
State New
Headers show
Series Make set_dev_pasid op supporting domain replacement | expand

Commit Message

Yi Liu Nov. 4, 2024, 1:18 p.m. UTC
Let identity_domain_set_dev_pasid() call the pasid replace helpers hence
be able to do domain replacement.

Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/intel/iommu.c | 8 +++++++-
 drivers/iommu/intel/pasid.h | 9 +++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

Comments

Baolu Lu Nov. 5, 2024, 3:03 a.m. UTC | #1
On 11/4/24 21:18, Yi Liu wrote:
> Let identity_domain_set_dev_pasid() call the pasid replace helpers hence
> be able to do domain replacement.
> 
> Signed-off-by: Yi Liu<yi.l.liu@intel.com>
> ---
>   drivers/iommu/intel/iommu.c | 8 +++++++-
>   drivers/iommu/intel/pasid.h | 9 +++++++++
>   2 files changed, 16 insertions(+), 1 deletion(-)

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
diff mbox series

Patch

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 58df1cbc1590..c5b07ccbe621 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4618,11 +4618,17 @@  static int identity_domain_set_dev_pasid(struct iommu_domain *domain,
 {
 	struct device_domain_info *info = dev_iommu_priv_get(dev);
 	struct intel_iommu *iommu = info->iommu;
+	int ret;
 
 	if (!pasid_supported(iommu) || dev_is_real_dma_subdevice(dev))
 		return -EOPNOTSUPP;
 
-	return intel_pasid_setup_pass_through(iommu, dev, pasid);
+	ret = domain_setup_passthrough(iommu, dev, pasid, old);
+	if (ret)
+		return ret;
+
+	domain_remove_dev_pasid(old, dev, pasid);
+	return 0;
 }
 
 static struct iommu_domain identity_domain = {
diff --git a/drivers/iommu/intel/pasid.h b/drivers/iommu/intel/pasid.h
index 3f82f69a7bce..a3b5945a1812 100644
--- a/drivers/iommu/intel/pasid.h
+++ b/drivers/iommu/intel/pasid.h
@@ -326,6 +326,15 @@  static inline int domain_setup_second_level(struct intel_iommu *iommu,
 	return intel_pasid_setup_second_level(iommu, domain, dev, pasid);
 }
 
+static inline int domain_setup_passthrough(struct intel_iommu *iommu,
+					   struct device *dev, ioasid_t pasid,
+					   struct iommu_domain *old)
+{
+	if (old)
+		return intel_pasid_replace_pass_through(iommu, dev, pasid);
+	return intel_pasid_setup_pass_through(iommu, dev, pasid);
+}
+
 void intel_pasid_tear_down_entry(struct intel_iommu *iommu,
 				 struct device *dev, u32 pasid,
 				 bool fault_ignore);