[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <MW5PR11MB58811372039BED21EF588C1B89E0A@MW5PR11MB5881.namprd11.prod.outlook.com>
Date: Mon, 28 Aug 2023 09:10:24 +0000
From: "Zhang, Tina" <tina.zhang@...el.com>
To: Vasant Hegde <vasant.hegde@....com>,
Jason Gunthorpe <jgg@...pe.ca>,
"Tian, Kevin" <kevin.tian@...el.com>,
Lu Baolu <baolu.lu@...ux.intel.com>,
Michael Shavit <mshavit@...gle.com>
CC: "iommu@...ts.linux.dev" <iommu@...ts.linux.dev>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH v2 4/5] iommu: Support mm PASID 1:n with sva domains
Hi Vasant,
> -----Original Message-----
> From: Vasant Hegde <vasant.hegde@....com>
> Sent: Monday, August 28, 2023 4:33 PM
> To: Zhang, Tina <tina.zhang@...el.com>; Jason Gunthorpe <jgg@...pe.ca>;
> Tian, Kevin <kevin.tian@...el.com>; Lu Baolu <baolu.lu@...ux.intel.com>;
> Michael Shavit <mshavit@...gle.com>
> Cc: iommu@...ts.linux.dev; linux-kernel@...r.kernel.org
> Subject: Re: [PATCH v2 4/5] iommu: Support mm PASID 1:n with sva domains
>
> Hi Tina,
>
> On 8/27/2023 2:14 PM, Tina Zhang wrote:
> > Each mm bound to devices gets a PASID and corresponding sva domains
> > allocated in iommu_sva_bind_device(), which are referenced by
> iommu_mm
> > field of the mm. The PASID is released in __mmdrop(), while a sva
> > domain is released when no one is using it (the reference count is
> > decremented in iommu_sva_unbind_device()).
> >
> > Since the required info of PASID and sva domains is kept in struct
> > iommu_mm_data of a mm, use mm->iommu_mm field instead of the old
> pasid
> > field in mm struct. The sva domain list is protected by iommu_sva_lock.
> >
> > Besides, this patch removes mm_pasid_init(), as with the introduced
> > iommu_mm structure, initializing mm pasid in mm_init() is unnecessary.
> >
> > Signed-off-by: Tina Zhang <tina.zhang@...el.com>
> > ---
> > drivers/iommu/iommu-sva.c | 38 +++++++++++++++++++++++++-------------
> > include/linux/iommu.h | 10 +++-------
> > kernel/fork.c | 1 -
> > 3 files changed, 28 insertions(+), 21 deletions(-)
> >
>
>
> .../...
>
> >
> > /* Allocate a new domain and set it on device pasid. */ @@ -105,6
> > +113,8 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev,
> struct mm_struct *mm
> > if (ret)
> > goto out_free_domain;
> > domain->users = 1;
> > + list_add(&domain->next, &mm->iommu_mm->sva_domains);
> > +
> > out:
> > mutex_unlock(&iommu_sva_lock);
> > handle->dev = dev;
> > @@ -137,8 +147,9 @@ void iommu_sva_unbind_device(struct iommu_sva
> *handle)
> > struct device *dev = handle->dev;
> >
> > mutex_lock(&iommu_sva_lock);
> > + iommu_detach_device_pasid(domain, dev, pasid);
> > if (--domain->users == 0) {
> > - iommu_detach_device_pasid(domain, dev, pasid);
> > + list_del(&domain->next);
> > iommu_domain_free(domain);
> > }
> > mutex_unlock(&iommu_sva_lock);
> > @@ -218,4 +229,5 @@ void mm_pasid_drop(struct mm_struct *mm)
> > return;
> >
> > ida_free(&iommu_global_pasid_ida, mm_get_pasid(mm));
> > + kfree(mm->iommu_mm);
>
>
> I am not sure whether I understood the flow completely. Just wondering why
> you are not freeing pasid in iommu_sva_unbind_device().
> I mean once iommu_mm->sva_domains becomes free shouldn't we free the
> iommu_mm->pasid?
No, the sva domain and the PASID are separate objects with their own lifecycles.
The iommu_mm->pasid is released when the mm is being released, meanwhile the sva_domain is released when no one is using it.
Regards,
-Tina
>
> Also in this function (mm_pasid_drop()), should we check/free sva domains?
>
> -Vasant
Powered by blists - more mailing lists