Message ID | 20241104131842.13303-10-yi.l.liu@intel.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Make set_dev_pasid op supporting domain replacement | expand |
On 11/4/24 21:18, Yi Liu wrote: > Use the domain_add_dev_pasid() and domain_remove_dev_pasid(). > > Signed-off-by: Yi Liu<yi.l.liu@intel.com> > --- > drivers/iommu/intel/iommu.c | 6 +++--- > drivers/iommu/intel/iommu.h | 6 ++++++ > drivers/iommu/intel/svm.c | 28 +++++++--------------------- > 3 files changed, 16 insertions(+), 24 deletions(-) Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
> From: Liu, Yi L <yi.l.liu@intel.com> > Sent: Monday, November 4, 2024 9:19 PM > > Use the domain_add_dev_pasid() and domain_remove_dev_pasid(). > > Signed-off-by: Yi Liu <yi.l.liu@intel.com> this could move to follow patch5 as it's an immediate user on the two helpers before talking about replacement. > @@ -201,43 +201,29 @@ static int intel_svm_set_dev_pasid(struct > iommu_domain *domain, > struct iommu_domain *old) > { > struct device_domain_info *info = dev_iommu_priv_get(dev); > - struct dmar_domain *dmar_domain = to_dmar_domain(domain); > struct intel_iommu *iommu = info->iommu; > struct mm_struct *mm = domain->mm; > struct dev_pasid_info *dev_pasid; > unsigned long sflags; > - unsigned long flags; > int ret = 0; > > - dev_pasid = kzalloc(sizeof(*dev_pasid), GFP_KERNEL); > - if (!dev_pasid) > - return -ENOMEM; > - > - dev_pasid->dev = dev; > - dev_pasid->pasid = pasid; > - > - ret = cache_tag_assign_domain(to_dmar_domain(domain), dev, > pasid); > - if (ret) > - goto free_dev_pasid; > + dev_pasid = domain_add_dev_pasid(domain, dev, pasid); > + if (IS_ERR(dev_pasid)) > + return PTR_ERR(dev_pasid); > > /* Setup the pasid table: */ > sflags = cpu_feature_enabled(X86_FEATURE_LA57) ? > PASID_FLAG_FL5LP : 0; > ret = intel_pasid_setup_first_level(iommu, dev, mm->pgd, pasid, > FLPT_DEFAULT_DID, sflags); > if (ret) > - goto unassign_tag; > + goto out_remove_dev_pasid; > > - spin_lock_irqsave(&dmar_domain->lock, flags); > - list_add(&dev_pasid->link_domain, &dmar_domain->dev_pasids); > - spin_unlock_irqrestore(&dmar_domain->lock, flags); > + domain_remove_dev_pasid(old, dev, pasid); > this also changes the order between pasid entry setup and the list update. and intel_mm_release() walks the dev_pasids list and call intel_pasid_tear_down_entry() which WARN_ON if an entry is not valid. but looks it's still OK here as intel_mm_release() is triggered in the last step of iommu_domain_free() which cannot happen when an attach is still in progress. Just raise this point in case something is overlooked. otherwise, Reviewed-by: Kevin Tian <kevin.tian@intel.com>
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c5b07ccbe621..0e0e9eb5188a 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4257,8 +4257,8 @@ static int intel_iommu_iotlb_sync_map(struct iommu_domain *domain, return 0; } -static void domain_remove_dev_pasid(struct iommu_domain *domain, - struct device *dev, ioasid_t pasid) +void domain_remove_dev_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t pasid) { struct device_domain_info *info = dev_iommu_priv_get(dev); struct dev_pasid_info *curr, *dev_pasid = NULL; @@ -4302,7 +4302,7 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid, domain_remove_dev_pasid(domain, dev, pasid); } -static struct dev_pasid_info * +struct dev_pasid_info * domain_add_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t pasid) { diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 009f518722e0..8e7ffb421ac4 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -1232,6 +1232,12 @@ int prepare_domain_attach_device(struct iommu_domain *domain, struct device *dev); void domain_update_iommu_cap(struct dmar_domain *domain); +struct dev_pasid_info * +domain_add_dev_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t pasid); +void domain_remove_dev_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t pasid); + int dmar_ir_support(void); void iommu_flush_write_buffer(struct intel_iommu *iommu); diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 3b5e3da24f19..925afca7529e 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -201,43 +201,29 @@ static int intel_svm_set_dev_pasid(struct iommu_domain *domain, struct iommu_domain *old) { struct device_domain_info *info = dev_iommu_priv_get(dev); - struct dmar_domain *dmar_domain = to_dmar_domain(domain); struct intel_iommu *iommu = info->iommu; struct mm_struct *mm = domain->mm; struct dev_pasid_info *dev_pasid; unsigned long sflags; - unsigned long flags; int ret = 0; - dev_pasid = kzalloc(sizeof(*dev_pasid), GFP_KERNEL); - if (!dev_pasid) - return -ENOMEM; - - dev_pasid->dev = dev; - dev_pasid->pasid = pasid; - - ret = cache_tag_assign_domain(to_dmar_domain(domain), dev, pasid); - if (ret) - goto free_dev_pasid; + dev_pasid = domain_add_dev_pasid(domain, dev, pasid); + if (IS_ERR(dev_pasid)) + return PTR_ERR(dev_pasid); /* Setup the pasid table: */ sflags = cpu_feature_enabled(X86_FEATURE_LA57) ? PASID_FLAG_FL5LP : 0; ret = intel_pasid_setup_first_level(iommu, dev, mm->pgd, pasid, FLPT_DEFAULT_DID, sflags); if (ret) - goto unassign_tag; + goto out_remove_dev_pasid; - spin_lock_irqsave(&dmar_domain->lock, flags); - list_add(&dev_pasid->link_domain, &dmar_domain->dev_pasids); - spin_unlock_irqrestore(&dmar_domain->lock, flags); + domain_remove_dev_pasid(old, dev, pasid); return 0; -unassign_tag: - cache_tag_unassign_domain(to_dmar_domain(domain), dev, pasid); -free_dev_pasid: - kfree(dev_pasid); - +out_remove_dev_pasid: + domain_remove_dev_pasid(domain, dev, pasid); return ret; }
Use the domain_add_dev_pasid() and domain_remove_dev_pasid(). Signed-off-by: Yi Liu <yi.l.liu@intel.com> --- drivers/iommu/intel/iommu.c | 6 +++--- drivers/iommu/intel/iommu.h | 6 ++++++ drivers/iommu/intel/svm.c | 28 +++++++--------------------- 3 files changed, 16 insertions(+), 24 deletions(-)