On Mon, 6 Jul 2020 13:32:18 +0200 Markus Elfring wrote:
> =E2=80=A6
> > +++ b/drivers/vfio/vfio_iommu_type1.c
> > @@ -2798,7 +2798,8 @@ static int vfio_iommu_type1_dma_rw_chunk
> =E2=80=A6
> > - bool kthread =3D current->mm =3D=3D NULL;
> > + bool kthread =3D current->flags & PF_KTHREAD;
> > + bool use_mm =3D current->mm =3D=3D NULL;
> =E2=80=A6
>
> Can it be helpful to convert initialisations for these variables
> into later assignments?
Perhaps. Then it looks like the below.
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -2798,9 +2798,12 @@ 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;
+ bool use_mm;
size_t offset;
+ kthread = current->flags & PF_KTHREAD;
+ use_mm = current->mm == NULL;
*copied = 0;
dma = vfio_find_dma(iommu, user_iova, 1);
@@ -2812,11 +2815,10 @@ static int vfio_iommu_type1_dma_rw_chunk
return -EPERM;
mm = get_task_mm(dma->task);
-
if (!mm)
return -EPERM;
- if (kthread)
+ 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