On Tue, Mar 29, 2022 at 01:37:52PM +0800, Lu Baolu wrote: > @@ -95,6 +101,7 @@ struct iommu_domain { > void *handler_token; > struct iommu_domain_geometry geometry; > struct iommu_dma_cookie *iova_cookie; > + struct iommu_sva_cookie *sva_cookie;
Cookie is still the wrong word to use here > +struct iommu_sva_cookie { > + struct mm_struct *mm; > + ioasid_t pasid; > + refcount_t users; Really surprised to see a refcount buried inside the iommu_domain.. This design seems inside out, the SVA struct should 'enclose' the domain, not be a pointer inside it. struct iommu_sva_domain { struct kref_t kref; struct mm_struct *mm; ioasid_t pasid; /* All the domains that are linked to this */ struct xarray domain_list; }; And then you could have a pointer to that inside the mm_struct instead of just the naked pasid. > +static __maybe_unused struct iommu_domain * Why maybe unused? > +iommu_sva_get_domain(struct device *dev, struct mm_struct *mm) > +{ > + struct iommu_domain *domain; > + ioasid_t pasid = mm->pasid; > + > + if (pasid == INVALID_IOASID) > + return NULL; > + > + domain = xa_load(&sva_domain_array, pasid); > + if (!domain) > + return iommu_sva_alloc_domain(dev, mm); > + iommu_sva_domain_get_user(domain); This assumes any domain is interchangeable with any device, which is not the iommu model. We need a domain op to check if a device is compatiable with the domain for vfio an iommufd, this should do the same. It means each mm can have a list of domains associated with it and a new domain is auto-created if the device doesn't work with any of the existing domains. Jason _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu