iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Hillf Danton <hdanton@sina.com>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: Hillf Danton <hdanton@sina.com>, Yan Zhao <yan.y.zhao@intel.com>,
	kernel-janitors@vger.kernel.org,
	iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	Kevin Tian <kevin.tian@intel.com>,
	Alex Williamson <alex.williamson@redhat.com>,
	Christoph Hellwig <hch@lst.de>
Subject: Re: [RFC PATCH] vfio: type1: fix kthread use case
Date: Mon,  6 Jul 2020 22:08:06 +0800	[thread overview]
Message-ID: <20200706140806.6028-1-hdanton@sina.com> (raw)
In-Reply-To: <7ed25c44-bb51-2d8d-82d9-f11272f56424@web.de>


On Mon, 6 Jul 2020 15:33:58 +0200 Markus Elfring wrote:
>
> I would prefer the following variable declarations then.
> 
> +	bool kthread, use_mm;
> 
> 
> >  	size_t offset;
> >
> > +	kthread =3D current->flags & PF_KTHREAD;
> > +	use_mm =3D current->mm =3D=3D NULL;
> 
> I propose to move such assignments directly before the corresponding check=
> .

Got it. See below.

> 
> >  	if (!mm)
> >  		return -EPERM;
> 
> 
> +	kthread =3D current->flags & PF_KTHREAD;
> +	use_mm =3D !current->mm;
> 
> > -	if (kthread)
> > +	if (kthread && use_mm)
> >  		kthread_use_mm(mm);


--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -2798,7 +2798,7 @@ static int vfio_iommu_type1_dma_rw_chunk
 	struct mm_struct *mm;
 	unsigned long vaddr;
 	struct vfio_dma *dma;
-	bool kthread = current->mm == NULL;
+	bool kthread, use_mm;
 	size_t offset;
 
 	*copied = 0;
@@ -2812,11 +2812,13 @@ static int vfio_iommu_type1_dma_rw_chunk
 		return -EPERM;
 
 	mm = get_task_mm(dma->task);
-
 	if (!mm)
 		return -EPERM;
 
-	if (kthread)
+	kthread = current->flags & PF_KTHREAD;
+	use_mm = current->mm == NULL;
+
+	if (kthread && use_mm)
 		kthread_use_mm(mm);
 	else if (current->mm != mm)
 		goto out;
@@ -2843,7 +2845,7 @@ static int vfio_iommu_type1_dma_rw_chunk
 	} else
 		*copied = copy_from_user(data, (void __user *)vaddr,
 					   count) ? 0 : count;
-	if (kthread)
+	if (kthread && use_mm)
 		kthread_unuse_mm(mm);
 out:
 	mmput(mm);

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2020-07-06 14:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-06 10:49 Hillf Danton
2020-07-06 11:32 ` Markus Elfring
2020-07-06 12:42   ` Hillf Danton
2020-07-06 13:33     ` Markus Elfring
2020-07-06 14:08       ` Hillf Danton [this message]
2020-07-06 14:04     ` Markus Elfring
2020-07-07  1:14       ` Hillf Danton
2020-07-07  6:04         ` Markus Elfring
2020-07-07  0:31 ` Yan Zhao
2020-07-07  2:00   ` Hillf Danton

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=20200706140806.6028-1-hdanton@sina.com \
    --to=hdanton@sina.com \
    --cc=Markus.Elfring@web.de \
    --cc=alex.williamson@redhat.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yan.y.zhao@intel.com \
    --subject='Re: [RFC PATCH] vfio: type1: fix kthread use case' \
    /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

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).