From: Alex Williamson <alex.williamson@redhat.com>
To: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: linuxppc-dev@lists.ozlabs.org,
David Gibson <david@gibson.dropbear.id.au>,
Paul Mackerras <paulus@samba.org>,
kvm@vger.kernel.org
Subject: Re: [PATCH kernel v5 5/6] vfio/spapr: Reference mm in tce_container
Date: Thu, 17 Nov 2016 14:56:42 -0700 [thread overview]
Message-ID: <20161117145642.748a12ae@t450s.home> (raw)
In-Reply-To: <7bf695fa-502a-80b1-85be-79f0aff55366@ozlabs.ru>
On Thu, 17 Nov 2016 18:39:41 +1100
Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
> On 11/11/16 23:32, Alexey Kardashevskiy wrote:
> > In some situations the userspace memory context may live longer than
> > the userspace process itself so if we need to do proper memory context
> > cleanup, we better have tce_container take a reference to mm_struct and
> > use it later when the process is gone (@current or @current->mm is NULL).
> >
> > This references mm and stores the pointer in the container; this is done
> > in a new helper - tce_iommu_mm_set() - when one of the following happens:
> > - a container is enabled (IOMMU v1);
> > - a first attempt to pre-register memory is made (IOMMU v2);
> > - a DMA window is created (IOMMU v2).
> > The @mm stays referenced till the container is destroyed.
> >
> > This replaces current->mm with container->mm everywhere except debug
> > prints.
> >
> > This adds a check that current->mm is the same as the one stored in
> > the container to prevent userspace from making changes to a memory
> > context of other processes.
> >
> > DMA map/unmap ioctls() do not check for @mm as they already check
> > for @enabled which is set after tce_iommu_mm_set() is called.
> >
> > Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> > ---
> > Changes:
> > v5:
> > * postpone referencing of mm
> >
> > v4:
> > * added check for container->mm!=current->mm in tce_iommu_ioctl()
> > for all ioctls and removed other redundand checks
> > ---
> > drivers/vfio/vfio_iommu_spapr_tce.c | 159 ++++++++++++++++++++++--------------
> > 1 file changed, 99 insertions(+), 60 deletions(-)
> >
> > diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
> > index 1c02498..9a81a7e 100644
> > --- a/drivers/vfio/vfio_iommu_spapr_tce.c
> > +++ b/drivers/vfio/vfio_iommu_spapr_tce.c
> > @@ -31,49 +31,49 @@
> > static void tce_iommu_detach_group(void *iommu_data,
> > struct iommu_group *iommu_group);
> >
> > -static long try_increment_locked_vm(long npages)
> > +static long try_increment_locked_vm(struct mm_struct *mm, long npages)
> > {
> > long ret = 0, locked, lock_limit;
> >
> > - if (!current || !current->mm)
> > - return -ESRCH; /* process exited */
> > + if (!mm)
> > + return -EPERM;
> >
> > if (!npages)
> > return 0;
> >
> > - down_write(¤t->mm->mmap_sem);
> > - locked = current->mm->locked_vm + npages;
> > + down_write(&mm->mmap_sem);
> > + locked = mm->locked_vm + npages;
> > lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
> > if (locked > lock_limit && !capable(CAP_IPC_LOCK))
>
>
>
> Oh boy. Now it seems I have to reference a task, not just mm (which I may
> not have to reference at all after all as the task reference should keep mm
> alive) as I missed the fact capable() and rlimit() are working with @current.
>
>
> Alex,
>
> Is there anything else I should fix before posting v6? Thanks.
Nope, I was just hoping to see a R-b from David, you guys know the
spapr-tce iommu code far better than me. Thanks,
Alex
next prev parent reply other threads:[~2016-11-17 21:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-11 12:32 [PATCH kernel v5 0/6] powerpc/spapr/vfio: Put pages on VFIO container shutdown Alexey Kardashevskiy
2016-11-11 12:32 ` [PATCH kernel v5 1/6] powerpc/iommu: Pass mm_struct to init/cleanup helpers Alexey Kardashevskiy
2016-11-11 12:32 ` [PATCH kernel v5 2/6] powerpc/iommu: Stop using @current in mm_iommu_xxx Alexey Kardashevskiy
2016-11-11 12:32 ` [PATCH kernel v5 3/6] vfio/spapr: Postpone allocation of userspace version of TCE table Alexey Kardashevskiy
2016-11-21 23:27 ` David Gibson
2016-11-11 12:32 ` [PATCH kernel v5 4/6] vfio/spapr: Postpone default window creation Alexey Kardashevskiy
2016-11-22 2:50 ` David Gibson
2016-11-22 7:29 ` Alexey Kardashevskiy
2016-11-23 1:35 ` David Gibson
2016-11-23 5:06 ` Alexey Kardashevskiy
2016-11-24 4:08 ` David Gibson
2016-11-11 12:32 ` [PATCH kernel v5 5/6] vfio/spapr: Reference mm in tce_container Alexey Kardashevskiy
2016-11-17 7:39 ` Alexey Kardashevskiy
2016-11-17 21:56 ` Alex Williamson [this message]
2016-11-22 2:38 ` David Gibson
2016-11-22 3:49 ` Alexey Kardashevskiy
2016-11-22 7:34 ` Alexey Kardashevskiy
2016-11-23 1:36 ` David Gibson
2016-11-11 12:32 ` [PATCH kernel v5 6/6] powerpc/mm/iommu, vfio/spapr: Put pages on VFIO container shutdown Alexey Kardashevskiy
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=20161117145642.748a12ae@t450s.home \
--to=alex.williamson@redhat.com \
--cc=aik@ozlabs.ru \
--cc=david@gibson.dropbear.id.au \
--cc=kvm@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=paulus@samba.org \
/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).