Re: [PATCH v3 1/4] iommu/vt-d: Implement domain ops for attach_dev_pasid

Jacob Pan
2022-05-18T18:39:28Z

Hi Jason,

On Wed, 11 May 2022 15:29:08 -0300, Jason Gunthorpe <jgg@nvidia.com> wrote:

> On Wed, May 11, 2022 at 10:25:21AM -0700, Jacob Pan wrote:
> > Hi Jason,
> >
> > On Wed, 11 May 2022 14:00:25 -0300, Jason Gunthorpe <jgg@nvidia.com>
> > wrote:
> > > On Wed, May 11, 2022 at 10:02:16AM -0700, Jacob Pan wrote:
> > > > > > If not global, perhaps we could have a list of pasids (e.g.
> > > > > > xarray) attached to the device_domain_info. The TLB flush logic
> > > > > > would just go through the list w/o caring what the PASIDs are
> > > > > > for. Does it make sense to you?
> > > > >
> > > > > Sort of, but we shouldn't duplicate xarrays - the group already
> > > > > has this xarray - need to find some way to allow access to it
> > > > > from the driver.
> > > > >
> > > > I am not following, here are the PASIDs for devTLB flush which is
> > > > per device. Why group?
> > >
> > > Because group is where the core code stores it.
> > I see, with singleton group. I guess I can let dma-iommu code call
> >
> > iommu_attach_dma_pasid {
> > iommu_attach_device_pasid();
> > Then the PASID will be stored in the group xa.
>
> Yes, again, the dma-iommu should not be any different from the normal
> unmanaged path. At this point there is no longer any difference, we
> should not invent new ones.
>
> > The flush code can retrieve PASIDs from device_domain_info.device ->
> > group -> pasid_array. Thanks for pointing it out, I missed the new
> > pasid_array.
>
> Yes.. It seems inefficient to iterate over that xarray multiple times
> on the flush hot path, but maybe there is little choice. Try to use
> use the xas iterators under the xa_lock spinlock..
>
xas_for_each takes a max range, here we don't really have one. So I posted
v4 w/o using the xas advanced API. Please let me know if you have
suggestions.
xa_for_each takes RCU read lock, it should be fast for tlb flush, right? The
worst case maybe over flush when we have stale data but should be very rare.

> The challenge will be accessing the group xa in the first place, but
> maybe the core code can gain a function call to return a pointer to
> that XA or something..
>
I added a helper function to find the matching DMA API PASID in v4.

Thanks,

Jacob