Re: [RFC PATCH 5/6] iommu: Support mm PASID 1:1 with sva domain

From: Jason Gunthorpe
Date: Tue Jul 11 2023 - 10:19:33 EST


On Tue, Jul 11, 2023 at 10:43:43AM +0800, Baolu Lu wrote:
> On 2023/7/11 1:28, Jason Gunthorpe wrote:
> > > @@ -88,31 +98,41 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
> > > goto out_unlock;
> > > }
> > > - if (domain) {
> > > - domain->users++;
> > > - goto out;
> > > + if (unlikely(domain)) {
> > > + /* Re-attach the device to the same domain? */
> > > + if (domain == sva_domain) {
> > > + goto out;
> > > + } else {
> > > + /* Didn't get detached from the previous domain? */
> > > + ret = -EBUSY;
> > > + goto out_unlock;
> > > + }
> > > }
> > And if we do all of this we should just get rid of the horrible
> > iommu_get_domain_for_dev_pasid() entirely.
>
> At the core level, we have no idea about whether an sva domain allocated
> for one device is compatible with another device. Hence, we should loop
> the sva domains in the list and if the attach interface feeds back
> -EINVAL's (not compatible), we should allocate a new domain for the
> attached device and put it in the list if the new attachment is
> successful.

Yes, generally.

It would be good to undertand if the drivers desire one sva domain per
instance or one sva domain per driver - but with this approach it
becomes a driver choice which to use. I would guess that one sva
domain per instance is slightly simpler in the drivers..

iommu_get_domain_for_dev_pasid() turns into a check if the group
already has a SVA domain bound from a list, ie we turn it upside down
and have it search the list under the xa_lock instead of trying to
return a domain pointer back out.

Jason