IDK, is there more users of this? AFAIK SVA is the only place thatAssuming we leave room for multi-device groups this logic should justAgreed. As a helper in iommu core, how about making it more generic like
be
group = iommu_group_get(dev);
if (!group)
return -ENODEV;
mutex_lock(&group->mutex);
domain = xa_load(&group->pasid_array, mm->pasid);
if (!domain || domain->type != IOMMU_DOMAIN_SVA || domain->mm != mm)
domain = iommu_sva_alloc_domain(dev, mm);
?
below?
will be auto-sharing?
+ mutex_lock(&group->mutex);This is bad locking, group->pasid_array values cannot be taken outside
+ domain = xa_load(&group->pasid_array, pasid);
+ if (domain && domain->type != type)
+ domain = NULL;
+ mutex_unlock(&group->mutex);
+ iommu_group_put(group);
+
+ return domain;
the lock.
I'm still not sure that bond is necessaryAnd stick the refcount in the sva_domainFair enough. How about below wrapper?
Also, given the current arrangement it might make sense to have a
struct iommu_domain_sva given that no driver is wrappering this in
something else.
+struct iommu_sva_domain {
+ /*
+ * Common iommu domain header,*must* be put at the top
+ * of the structure.
+ */
+ struct iommu_domain domain;
+ struct mm_struct *mm;
+ struct iommu_sva bond;
+}
The refcount is wrapped in bond.
But yes, something like that