Re: [PATCH v2 2/3] iommu/sva: Stop using ioasid_set for SVA

From: Jason Gunthorpe
Date: Wed Feb 15 2023 - 13:47:41 EST


On Wed, Feb 15, 2023 at 10:38:22AM -0800, Jacob Pan wrote:
> Hi Kevin,
>
> On Wed, 15 Feb 2023 03:24:18 +0000, "Tian, Kevin" <kevin.tian@xxxxxxxxx>
> wrote:
>
> > > From: Jacob Pan <jacob.jun.pan@xxxxxxxxxxxxxxx>
> > > Sent: Tuesday, February 14, 2023 2:44 PM
> > >
> > > From: Jason Gunthorpe <jgg@xxxxxxxxxx>
> > >
> > > Instead SVA drivers can use a simple global IDA to allocate PASIDs for
> > > each mm_struct.
> > >
> > > Future work would be to allow drivers using the SVA APIs to reserve
> > > global PASIDs from this IDA for their internal use, eg with the DMA API
> > > PASID support.
> >
> > I think DMA API PASID will need new API around this IDA. SVA APIs should
> > be just for SVA.
> >
> > > +void mm_pasid_drop(struct mm_struct *mm)
> > > {
> > > - return mmget_not_zero(mm);
> > > -}
> > > + pr_alert("%s %d", __func__, mm->pasid);
> > > + if (likely(!pasid_valid(mm->pasid)))
> > > + return;
> > >
> > > -/**
> > > - * iommu_sva_find() - Find mm associated to the given PASID
> > > - * @pasid: Process Address Space ID assigned to the mm
> > > - *
> > > - * On success a reference to the mm is taken, and must be released with
> > > mmput().
> > > - *
> > > - * Returns the mm corresponding to this PASID, or an error if not
> > > found.
> > > - */
> > > -struct mm_struct *iommu_sva_find(ioasid_t pasid)
> > > -{
> > > - return ioasid_find(&iommu_sva_pasid, pasid, __mmget_not_zero);
> > > + ida_free(&iommu_global_pasid_ida, mm->pasid);
> > > }
> >
> > when moving this function following line is missed:
> >
> > mm->pasid = INVALID_IOASID;
> >
> not needed, mm is gone by now.
>
> > btw the current placement looks asymmetric. We now have
> > mm_pasid_init() and mm_pasid_set() in mm.h while mm_pasid_drop()
> > in iommu-sva.c.
> > Is it cleaner to introduce a iommu_sva_free_pasid() helper and then
> > call it from mm_pasid_drop() in mm.h?
> That is what we had before, it seems logical to me. Jason?

I don't much like a maze of functions calling each other.

Renaming the helper might help, especially if it comes from iommu.h

Jason