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
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu