media: atomisp: hmm_bo: Drop PFN code path from alloc_user_pages()
authorHans de Goede <hdegoede@redhat.com>
Sun, 21 Aug 2022 18:43:57 +0000 (20:43 +0200)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Sat, 24 Sep 2022 07:44:52 +0000 (09:44 +0200)
alloc_user_pages() is only ever called on qbuf for USERPTR buffers which
always hits the get_user_pages_fast() path, so the pin_user_pages() path
can be removed.

Getting the vma then also is no longer necessary since that is only
done to determine which path to use.

And this also removes the only users of the mem_type struct hmm_bo member,
so remove that as well.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/staging/media/atomisp/include/hmm/hmm_bo.h
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c

index 901dc37..c5cbae1 100644 (file)
@@ -86,8 +86,6 @@ enum hmm_bo_type {
 #define        HMM_BO_VMAPED           0x10
 #define        HMM_BO_VMAPED_CACHED    0x20
 #define        HMM_BO_ACTIVE           0x1000
-#define        HMM_BO_MEM_TYPE_USER     0x1
-#define        HMM_BO_MEM_TYPE_PFN      0x2
 
 struct hmm_bo_device {
        struct isp_mmu          mmu;
@@ -123,7 +121,6 @@ struct hmm_buffer_object {
        enum hmm_bo_type        type;
        int             mmap_count;
        int             status;
-       int             mem_type;
        void            *vmap_addr; /* kernel virtual address by vmap */
 
        struct rb_node  node;
index d7f42a4..a5fd6d3 100644 (file)
@@ -656,12 +656,8 @@ static void free_user_pages(struct hmm_buffer_object *bo,
 {
        int i;
 
-       if (bo->mem_type == HMM_BO_MEM_TYPE_PFN) {
-               unpin_user_pages(bo->pages, page_nr);
-       } else {
-               for (i = 0; i < page_nr; i++)
-                       put_page(bo->pages[i]);
-       }
+       for (i = 0; i < page_nr; i++)
+               put_page(bo->pages[i]);
 }
 
 /*
@@ -671,43 +667,13 @@ static int alloc_user_pages(struct hmm_buffer_object *bo,
                            const void __user *userptr)
 {
        int page_nr;
-       struct vm_area_struct *vma;
-
-       mutex_unlock(&bo->mutex);
-       mmap_read_lock(current->mm);
-       vma = find_vma(current->mm, (unsigned long)userptr);
-       mmap_read_unlock(current->mm);
-       if (!vma) {
-               dev_err(atomisp_dev, "find_vma failed\n");
-               mutex_lock(&bo->mutex);
-               return -EFAULT;
-       }
-       mutex_lock(&bo->mutex);
-       /*
-        * Handle frame buffer allocated in other kerenl space driver
-        * and map to user space
-        */
 
        userptr = untagged_addr(userptr);
 
-       if (vma->vm_flags & (VM_IO | VM_PFNMAP)) {
-               page_nr = pin_user_pages((unsigned long)userptr, bo->pgnr,
-                                        FOLL_LONGTERM | FOLL_WRITE,
-                                        bo->pages, NULL);
-               bo->mem_type = HMM_BO_MEM_TYPE_PFN;
-       } else {
-               /*Handle frame buffer allocated in user space*/
-               mutex_unlock(&bo->mutex);
-               page_nr = get_user_pages_fast((unsigned long)userptr,
-                                             (int)(bo->pgnr), 1, bo->pages);
-               mutex_lock(&bo->mutex);
-               bo->mem_type = HMM_BO_MEM_TYPE_USER;
-       }
-
-       dev_dbg(atomisp_dev, "%s: %d %s pages were allocated as 0x%08x\n",
-               __func__,
-               bo->pgnr,
-               bo->mem_type == HMM_BO_MEM_TYPE_USER ? "user" : "pfn", page_nr);
+       /* Handle frame buffer allocated in user space */
+       mutex_unlock(&bo->mutex);
+       page_nr = get_user_pages_fast((unsigned long)userptr, bo->pgnr, 1, bo->pages);
+       mutex_lock(&bo->mutex);
 
        /* can be written by caller, not forced */
        if (page_nr != bo->pgnr) {