From: "Liu, Yi L" <yi.l.liu@intel.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: "eric.auger@redhat.com" <eric.auger@redhat.com>,
"Tian, Kevin" <kevin.tian@intel.com>,
"jacob.jun.pan@linux.intel.com" <jacob.jun.pan@linux.intel.com>,
"joro@8bytes.org" <joro@8bytes.org>,
"Raj, Ashok" <ashok.raj@intel.com>,
"Tian, Jun J" <jun.j.tian@intel.com>,
"Sun, Yi Y" <yi.y.sun@intel.com>,
"jean-philippe.brucker@arm.com" <jean-philippe.brucker@arm.com>,
"peterx@redhat.com" <peterx@redhat.com>,
"iommu@lists.linux-foundation.org"
<iommu@lists.linux-foundation.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [RFC v3 3/8] vfio: Reclaim PASIDs when application is down
Date: Fri, 31 Jan 2020 12:42:11 +0000 [thread overview]
Message-ID: <A2975661238FB949B60364EF0F2C25743A199412@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <20200129165640.4f1d42e0@w520.home>
Hi Alex,
> From: Alex Williamson [mailto:alex.williamson@redhat.com]
> Sent: Thursday, January 30, 2020 7:57 AM
> To: Liu, Yi L <yi.l.liu@intel.com>
> Subject: Re: [RFC v3 3/8] vfio: Reclaim PASIDs when application is down
>
> On Wed, 29 Jan 2020 04:11:47 -0800
> "Liu, Yi L" <yi.l.liu@intel.com> wrote:
>
> > From: Liu Yi L <yi.l.liu@intel.com>
> >
> > When userspace application is down, kernel should reclaim the PASIDs
> > allocated for this application to avoid PASID leak. This patch adds a
> > PASID list in vfio_mm structure to track the allocated PASIDs. The
> > PASID reclaim will be triggered when last vfio container is released.
> >
> > Previous discussions:
> > https://patchwork.kernel.org/patch/11209429/
> >
> > Cc: Kevin Tian <kevin.tian@intel.com>
> > CC: Jacob Pan <jacob.jun.pan@linux.intel.com>
> > Cc: Alex Williamson <alex.williamson@redhat.com>
> > Cc: Eric Auger <eric.auger@redhat.com>
> > Cc: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
> > Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
> > ---
> > drivers/vfio/vfio.c | 61
> > +++++++++++++++++++++++++++++++++++++++++++++++++---
> > include/linux/vfio.h | 6 ++++++
> > 2 files changed, 64 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index
> > c43c757..425d60a 100644
> > --- a/drivers/vfio/vfio.c
> > +++ b/drivers/vfio/vfio.c
> > @@ -2148,15 +2148,31 @@ static struct vfio_mm *vfio_create_mm(struct
> mm_struct *mm)
> > vmm->pasid_quota = VFIO_DEFAULT_PASID_QUOTA;
> > vmm->pasid_count = 0;
> > mutex_init(&vmm->pasid_lock);
> > + INIT_LIST_HEAD(&vmm->pasid_list);
> >
> > list_add(&vmm->vfio_next, &vfio.vfio_mm_list);
> >
> > return vmm;
> > }
> >
> > +static void vfio_mm_reclaim_pasid(struct vfio_mm *vmm) {
> > + struct pasid_node *pnode, *tmp;
> > +
> > + mutex_lock(&vmm->pasid_lock);
> > + list_for_each_entry_safe(pnode, tmp, &vmm->pasid_list, next) {
> > + pr_info("%s, reclaim pasid: %u\n", __func__, pnode->pasid);
> > + list_del(&pnode->next);
> > + ioasid_free(pnode->pasid);
> > + kfree(pnode);
> > + }
> > + mutex_unlock(&vmm->pasid_lock);
> > +}
> > +
> > static void vfio_mm_unlock_and_free(struct vfio_mm *vmm) {
> > mutex_unlock(&vfio.vfio_mm_lock);
> > + vfio_mm_reclaim_pasid(vmm);
> > kfree(vmm);
> > }
> >
> > @@ -2204,6 +2220,39 @@ struct vfio_mm *vfio_mm_get_from_task(struct
> > task_struct *task) } EXPORT_SYMBOL_GPL(vfio_mm_get_from_task);
> >
> > +/**
> > + * Caller should hold vmm->pasid_lock */ static int
> > +vfio_mm_insert_pasid_node(struct vfio_mm *vmm, u32 pasid) {
> > + struct pasid_node *pnode;
> > +
> > + pnode = kzalloc(sizeof(*pnode), GFP_KERNEL);
> > + if (!pnode)
> > + return -ENOMEM;
> > + pnode->pasid = pasid;
> > + list_add(&pnode->next, &vmm->pasid_list);
> > +
> > + return 0;
> > +}
> > +
> > +/**
> > + * Caller should hold vmm->pasid_lock */ static void
> > +vfio_mm_remove_pasid_node(struct vfio_mm *vmm, u32 pasid) {
> > + struct pasid_node *pnode, *tmp;
> > +
> > + list_for_each_entry_safe(pnode, tmp, &vmm->pasid_list, next) {
> > + if (pnode->pasid == pasid) {
> > + list_del(&pnode->next);
> > + kfree(pnode);
> > + break;
> > + }
>
> The _safe() list walk variant is only needed when we continue to walk the list after
> removing an entry. Thanks,
Nice catch. thanks, :-)
Regards,
Yi Liu
next prev parent reply other threads:[~2020-01-31 12:42 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-29 12:11 [RFC v3 0/8] vfio: expose virtual Shared Virtual Addressing to VMs Liu, Yi L
2020-01-29 12:11 ` [RFC v3 1/8] vfio: Add VFIO_IOMMU_PASID_REQUEST(alloc/free) Liu, Yi L
2020-01-29 23:55 ` Alex Williamson
2020-01-31 12:41 ` Liu, Yi L
2020-02-06 9:41 ` Liu, Yi L
2020-02-06 18:12 ` Jacob Pan
2020-02-18 5:07 ` Liu, Yi L
2020-01-29 12:11 ` [RFC v3 2/8] vfio/type1: Make per-application (VM) PASID quota tunable Liu, Yi L
2020-01-29 23:56 ` Alex Williamson
2020-02-05 6:23 ` Liu, Yi L
2020-02-07 19:43 ` Jacob Pan
2020-02-08 8:46 ` Liu, Yi L
2020-01-29 12:11 ` [RFC v3 3/8] vfio: Reclaim PASIDs when application is down Liu, Yi L
2020-01-29 23:56 ` Alex Williamson
2020-01-31 12:42 ` Liu, Yi L [this message]
2020-01-29 12:11 ` [RFC v3 4/8] vfio/type1: Add VFIO_NESTING_GET_IOMMU_UAPI_VERSION Liu, Yi L
2020-01-29 23:56 ` Alex Williamson
2020-01-31 13:04 ` Liu, Yi L
2020-02-03 18:00 ` Alex Williamson
2020-02-05 6:19 ` Liu, Yi L
2020-01-29 12:11 ` [RFC v3 5/8] vfio/type1: Report 1st-level/stage-1 page table format to userspace Liu, Yi L
2020-01-29 12:11 ` [RFC v3 6/8] vfio/type1: Bind guest page tables to host Liu, Yi L
2020-01-29 12:11 ` [RFC v3 7/8] vfio/type1: Add VFIO_IOMMU_CACHE_INVALIDATE Liu, Yi L
2020-01-29 12:11 ` [RFC v3 8/8] vfio/type1: Add vSVA support for IOMMU-backed mdevs Liu, Yi L
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=A2975661238FB949B60364EF0F2C25743A199412@SHSMSX104.ccr.corp.intel.com \
--to=yi.l.liu@intel.com \
--cc=alex.williamson@redhat.com \
--cc=ashok.raj@intel.com \
--cc=eric.auger@redhat.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jacob.jun.pan@linux.intel.com \
--cc=jean-philippe.brucker@arm.com \
--cc=joro@8bytes.org \
--cc=jun.j.tian@intel.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=yi.y.sun@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).