From: Nicholas Piggin <npiggin@gmail.com>
To: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: linuxppc-dev@lists.ozlabs.org,
Alex Williamson <alex.williamson@redhat.com>,
David Gibson <david@gibson.dropbear.id.au>,
Paul Mackerras <paulus@samba.org>
Subject: Re: [PATCH kernel v4 3/4] vfio/spapr: Reference mm in tce_container
Date: Mon, 24 Oct 2016 18:14:24 +1100 [thread overview]
Message-ID: <20161024181424.2887fc03@roar.ozlabs.ibm.com> (raw)
In-Reply-To: <1477291990-2872-4-git-send-email-aik@ozlabs.ru>
On Mon, 24 Oct 2016 17:53:09 +1100
Alexey Kardashevskiy <aik@ozlabs.ru> 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
> when a container is just created so checking for !current->mm in other
> places becomes pointless.
>
> 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; in order to add this check,
> VFIO_CHECK_EXTENSION is moved out of the switch(cmd) as it is
> quite special anyway - it is the only ioctl() called when neither
> container nor container->mm is initialized.
>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
> Changes:
> v4:
> * added check for container->mm!=current->mm in tce_iommu_ioctl()
> for all ioctls and removed other redundand checks
[...]
> @@ -326,13 +314,18 @@ static void *tce_iommu_open(unsigned long arg)
>
> container->v2 = arg == VFIO_SPAPR_TCE_v2_IOMMU;
>
> + /* current->mm cannot be NULL in this context */
> + container->mm = current->mm;
> + atomic_inc(&container->mm->mm_count);
[...]
> @@ -733,7 +728,13 @@ static long tce_iommu_ioctl(void *iommu_data,
> }
>
> return (ret < 0) ? 0 : ret;
> + }
>
> + /* tce_iommu_open() initializes container->mm so it can't be NULL here */
> + if (container->mm != current->mm)
> + return -ESRCH;
> +
> + switch (cmd) {
> case VFIO_IOMMU_SPAPR_TCE_GET_INFO: {
> struct vfio_iommu_spapr_tce_info info;
> struct tce_iommu_group *tcegrp;
I think doing the mm checks like this is a great improvement.
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Thanks,
Nick
next prev parent reply other threads:[~2016-10-24 7:14 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-24 6:53 [PATCH kernel v4 0/4] powerpc/spapr/vfio: Put pages on VFIO container shutdown Alexey Kardashevskiy
2016-10-24 6:53 ` [PATCH kernel v4 1/4] powerpc/iommu: Pass mm_struct to init/cleanup helpers Alexey Kardashevskiy
2016-10-24 6:53 ` [PATCH kernel v4 2/4] powerpc/iommu: Stop using @current in mm_iommu_xxx Alexey Kardashevskiy
2016-10-24 6:53 ` [PATCH kernel v4 3/4] vfio/spapr: Reference mm in tce_container Alexey Kardashevskiy
2016-10-24 7:14 ` Nicholas Piggin [this message]
2016-11-08 3:33 ` David Gibson
2016-11-08 22:25 ` Alex Williamson
2016-11-09 0:46 ` David Gibson
2016-10-24 6:53 ` [PATCH kernel v4 4/4] powerpc/mm/iommu, vfio/spapr: Put pages on VFIO container shutdown Alexey Kardashevskiy
2016-10-25 4:44 ` David Gibson
2016-10-25 4:55 ` Alexey Kardashevskiy
2016-10-31 3:13 ` David Gibson
2016-10-31 4:13 ` Alexey Kardashevskiy
2016-10-31 4:23 ` David Gibson
2016-11-02 2:44 ` Alexey Kardashevskiy
2016-11-03 1:02 ` Paul Mackerras
2016-11-08 3:33 ` David Gibson
2016-11-08 3:35 ` David Gibson
2016-11-08 7:54 ` [PATCH kernel v4 0/4] powerpc/spapr/vfio: " Michael Ellerman
2016-11-08 23:06 ` Alex Williamson
2016-11-10 1:37 ` Michael Ellerman
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=20161024181424.2887fc03@roar.ozlabs.ibm.com \
--to=npiggin@gmail.com \
--cc=aik@ozlabs.ru \
--cc=alex.williamson@redhat.com \
--cc=david@gibson.dropbear.id.au \
--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).