On Mon, 6 Jul 2020 16:04:13 +0200 Markus Elfring wrote:
> 
> Can another design approach make sense here?
> 
> +     bool thread_use_mm = ((current->flags & PF_KTHREAD) && !current->mm);
> +     if (thread_use_mm)

Good. See below.
> 
> 
> >             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_load_mm;
        size_t offset;
 
        *copied = 0;
@@ -2812,11 +2812,12 @@ static int vfio_iommu_type1_dma_rw_chunk
                return -EPERM;
 
        mm = get_task_mm(dma->task);
-
        if (!mm)
                return -EPERM;
 
-       if (kthread)
+       kthread_load_mm = current->flags & PF_KTHREAD &&
+                               current->mm == NULL;
+       if (kthread_load_mm)
                kthread_use_mm(mm);
        else if (current->mm != mm)
                goto out;
@@ -2843,7 +2844,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_load_mm)
                kthread_unuse_mm(mm);
 out:
        mmput(mm);

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

Reply via email to