Re: [PATCH v2 3/8] iommu/vt-d: Implement device_pasid domain attach ops

Jacob Pan
2022-03-16T20:47:05Z

Hi Jason,

On Tue, 15 Mar 2022 20:04:57 -0300, Jason Gunthorpe <jgg@nvidia.com> wrote:

> On Tue, Mar 15, 2022 at 03:36:20PM -0700, Jacob Pan wrote:
> > Hi Jason,
> >
> > On Tue, 15 Mar 2022 11:33:22 -0300, Jason Gunthorpe <jgg@nvidia.com>
> > wrote:
> > > On Mon, Mar 14, 2022 at 10:07:07PM -0700, Jacob Pan wrote:
> > > > + /*
> > > > + * Each domain could have multiple devices attached with
> > > > shared or per
> > > > + * device PASIDs. At the domain level, we keep track of
> > > > unique PASIDs and
> > > > + * device user count.
> > > > + * E.g. If a domain has two devices attached, device A has
> > > > PASID 0, 1;
> > > > + * device B has PASID 0, 2. Then the domain would have
> > > > PASID 0, 1, 2.
> > > > + */
> > >
> > > A 2d array of xarray's seems like a poor data structure for this task.
> > >
> > > AFACIT this wants to store a list of (device, pasid) tuples, so a
> > > simple linked list, 1d xarray vector or a red black tree seems more
> > > appropriate..
> > >
> > Agreed.
> > It might need some surgery for dmar_domain and device_domain_info, which
> > already has a simple device list. I am trying to leverage the existing
> > data struct, let me take a closer look.
>
> Maybe the core code should provide this data structure in the
> iommu_domain.
>
> Figuring out what stuff is attached is something every driver has to
> do right?
yeah, seems we already have some duplicated device list in vendor domain
struct, e.g. VT-d's dmar_domain, AMD's protection_domain. Similarly for
device_domain_info equivalent.

If core code provides domain-device-pasid tracking, we could do device-pasid
tracking in ioasid.c, when we support per device PASID allocation, each
phy device could be an IOASID set, thus its own namespace.

Perhaps, we could do the following: add a device list to struct
iommu_domain, this will replace vender's domain lists. The data would be
something like:
struct iommu_dev_pasid_data {
struct list_head list; /* For iommu_domain->dev_list */
struct ioasid_set *pasids; /* For the PASIDs used by the device */
struct device *dev;
};

I guess a list of (device, pasid) tuples as you suggested could work but it
will have duplicated device entries since each device could have multiple
PASIDs. right?

Have to code this up to see.

Thanks for the pointers,

Jacob