Re: [PATCH RFC v2 06/11] iommu/vt-d: Add SVA domain support
On 2022/3/31 3:09, Jason Gunthorpe wrote: On Tue, Mar 29, 2022 at 01:37:55PM +0800, Lu Baolu wrote: Add support for SVA domain allocation and provide an SVA-specific iommu_domain_ops. Signed-off-by: Lu Baolu include/linux/intel-iommu.h | 1 + drivers/iommu/intel/iommu.c | 10 ++ drivers/iommu/intel/svm.c | 37 + 3 files changed, 48 insertions(+) diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 2f9891cb3d00..c14283137fb5 100644 +++ b/include/linux/intel-iommu.h @@ -744,6 +744,7 @@ void intel_svm_unbind(struct iommu_sva *handle); u32 intel_svm_get_pasid(struct iommu_sva *handle); int intel_svm_page_response(struct device *dev, struct iommu_fault_event *evt, struct iommu_page_response *msg); +extern const struct iommu_domain_ops intel_svm_domain_ops; struct intel_svm_dev { struct list_head list; diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c1b91bce1530..5eae7cf9bee5 100644 +++ b/drivers/iommu/intel/iommu.c @@ -4318,6 +4318,16 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) return domain; case IOMMU_DOMAIN_IDENTITY: return _domain->domain; +#ifdef CONFIG_INTEL_IOMMU_SVM + case IOMMU_DOMAIN_SVA: + dmar_domain = alloc_domain(type); + if (!dmar_domain) + return NULL; + domain = _domain->domain; + domain->ops = _svm_domain_ops; + + return domain; +#endif /* CONFIG_INTEL_IOMMU_SVM */ If this is the usual pattern for drivers I would prefer to see an alloc_sva op instead of more and more types. Multiplexing functions is often not a great idea... Robin mentioned that the iommu domain alloc/free interfaces are under reforming. These cleanups need to wait to see what the final code looks like. Best regards, baolu ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH RFC v2 06/11] iommu/vt-d: Add SVA domain support
On Tue, Mar 29, 2022 at 01:37:55PM +0800, Lu Baolu wrote: > Add support for SVA domain allocation and provide an SVA-specific > iommu_domain_ops. > > Signed-off-by: Lu Baolu > include/linux/intel-iommu.h | 1 + > drivers/iommu/intel/iommu.c | 10 ++ > drivers/iommu/intel/svm.c | 37 + > 3 files changed, 48 insertions(+) > > diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h > index 2f9891cb3d00..c14283137fb5 100644 > +++ b/include/linux/intel-iommu.h > @@ -744,6 +744,7 @@ void intel_svm_unbind(struct iommu_sva *handle); > u32 intel_svm_get_pasid(struct iommu_sva *handle); > int intel_svm_page_response(struct device *dev, struct iommu_fault_event > *evt, > struct iommu_page_response *msg); > +extern const struct iommu_domain_ops intel_svm_domain_ops; > > struct intel_svm_dev { > struct list_head list; > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > index c1b91bce1530..5eae7cf9bee5 100644 > +++ b/drivers/iommu/intel/iommu.c > @@ -4318,6 +4318,16 @@ static struct iommu_domain > *intel_iommu_domain_alloc(unsigned type) > return domain; > case IOMMU_DOMAIN_IDENTITY: > return _domain->domain; > +#ifdef CONFIG_INTEL_IOMMU_SVM > + case IOMMU_DOMAIN_SVA: > + dmar_domain = alloc_domain(type); > + if (!dmar_domain) > + return NULL; > + domain = _domain->domain; > + domain->ops = _svm_domain_ops; > + > + return domain; > +#endif /* CONFIG_INTEL_IOMMU_SVM */ If this is the usual pattern for drivers I would prefer to see an alloc_sva op instead of more and more types. Multiplexing functions is often not a great idea... Jason ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH RFC v2 06/11] iommu/vt-d: Add SVA domain support
Add support for SVA domain allocation and provide an SVA-specific iommu_domain_ops. Signed-off-by: Lu Baolu --- include/linux/intel-iommu.h | 1 + drivers/iommu/intel/iommu.c | 10 ++ drivers/iommu/intel/svm.c | 37 + 3 files changed, 48 insertions(+) diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 2f9891cb3d00..c14283137fb5 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -744,6 +744,7 @@ void intel_svm_unbind(struct iommu_sva *handle); u32 intel_svm_get_pasid(struct iommu_sva *handle); int intel_svm_page_response(struct device *dev, struct iommu_fault_event *evt, struct iommu_page_response *msg); +extern const struct iommu_domain_ops intel_svm_domain_ops; struct intel_svm_dev { struct list_head list; diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c1b91bce1530..5eae7cf9bee5 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4318,6 +4318,16 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) return domain; case IOMMU_DOMAIN_IDENTITY: return _domain->domain; +#ifdef CONFIG_INTEL_IOMMU_SVM + case IOMMU_DOMAIN_SVA: + dmar_domain = alloc_domain(type); + if (!dmar_domain) + return NULL; + domain = _domain->domain; + domain->ops = _svm_domain_ops; + + return domain; +#endif /* CONFIG_INTEL_IOMMU_SVM */ default: return NULL; } diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index ee5ecde5b318..8f59dd641b2d 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -932,3 +932,40 @@ int intel_svm_page_response(struct device *dev, mutex_unlock(_mutex); return ret; } + +static int intel_svm_attach_dev_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t pasid) +{ + struct device_domain_info *info = dev_iommu_priv_get(dev); + struct mm_struct *mm = iommu_sva_domain_mm(domain); + struct intel_iommu *iommu = info->iommu; + struct iommu_sva *sva; + int ret = 0; + + mutex_lock(_mutex); + sva = intel_svm_bind_mm(iommu, dev, mm); + if (IS_ERR(sva)) + ret = PTR_ERR(sva); + mutex_unlock(_mutex); + + return ret; +} + +static void intel_svm_detach_dev_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t pasid) +{ + mutex_lock(_mutex); + intel_svm_unbind_mm(dev, pasid); + mutex_unlock(_mutex); +} + +static void intel_svm_domain_free(struct iommu_domain *domain) +{ + kfree(domain); +} + +const struct iommu_domain_ops intel_svm_domain_ops = { + .attach_dev_pasid = intel_svm_attach_dev_pasid, + .detach_dev_pasid = intel_svm_detach_dev_pasid, + .free = intel_svm_domain_free, +}; -- 2.25.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu