mm/gup: Switch all callers of get_user_pages() to not pass tsk/mm
authorDave Hansen <dave.hansen@linux.intel.com>
Fri, 12 Feb 2016 21:01:56 +0000 (13:01 -0800)
committerIngo Molnar <mingo@kernel.org>
Tue, 16 Feb 2016 09:11:12 +0000 (10:11 +0100)
We will soon modify the vanilla get_user_pages() so it can no
longer be used on mm/tasks other than 'current/current->mm',
which is by far the most common way it is called.  For now,
we allow the old-style calls, but warn when they are used.
(implemented in previous patch)

This patch switches all callers of:

get_user_pages()
get_user_pages_unlocked()
get_user_pages_locked()

to stop passing tsk/mm so they will no longer see the warnings.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave@sr71.net>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: jack@suse.cz
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/20160212210156.113E9407@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
29 files changed:
arch/cris/arch-v32/drivers/cryptocop.c
arch/ia64/kernel/err_inject.c
arch/mips/mm/gup.c
arch/s390/mm/gup.c
arch/sh/mm/gup.c
arch/sparc/mm/gup.c
arch/x86/mm/gup.c
arch/x86/mm/mpx.c
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
drivers/gpu/drm/radeon/radeon_ttm.c
drivers/gpu/drm/via/via_dmablit.c
drivers/infiniband/core/umem.c
drivers/infiniband/hw/mthca/mthca_memfree.c
drivers/infiniband/hw/qib/qib_user_pages.c
drivers/infiniband/hw/usnic/usnic_uiom.c
drivers/media/pci/ivtv/ivtv-udma.c
drivers/media/pci/ivtv/ivtv-yuv.c
drivers/media/v4l2-core/videobuf-dma-sg.c
drivers/misc/mic/scif/scif_rma.c
drivers/misc/sgi-gru/grufault.c
drivers/scsi/st.c
drivers/video/fbdev/pvr2fb.c
drivers/virt/fsl_hypervisor.c
mm/frame_vector.c
mm/gup.c
mm/ksm.c
mm/mempolicy.c
net/ceph/pagevec.c
virt/kvm/kvm_main.c

index 877da1908234b7b027fa92c8476903c9b4832dae..617645d21b20c1ef5b4ff7ee61b9b662334a4c34 100644 (file)
@@ -2719,9 +2719,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
        /* Acquire the mm page semaphore. */
        down_read(&current->mm->mmap_sem);
 
-       err = get_user_pages(current,
-                            current->mm,
-                            (unsigned long int)(oper.indata + prev_ix),
+       err = get_user_pages((unsigned long int)(oper.indata + prev_ix),
                             noinpages,
                             0,  /* read access only for in data */
                             0, /* no force */
@@ -2736,9 +2734,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
        }
        noinpages = err;
        if (oper.do_cipher){
-               err = get_user_pages(current,
-                                    current->mm,
-                                    (unsigned long int)oper.cipher_outdata,
+               err = get_user_pages((unsigned long int)oper.cipher_outdata,
                                     nooutpages,
                                     1, /* write access for out data */
                                     0, /* no force */
index 0c161ed6d18e6d77433c8bafabfdd48f904a077d..09f845793d12c1147bc767885673545a3bef88f3 100644 (file)
@@ -142,8 +142,7 @@ store_virtual_to_phys(struct device *dev, struct device_attribute *attr,
        u64 virt_addr=simple_strtoull(buf, NULL, 16);
        int ret;
 
-        ret = get_user_pages(current, current->mm, virt_addr,
-                        1, VM_READ, 0, NULL, NULL);
+       ret = get_user_pages(virt_addr, 1, VM_READ, 0, NULL, NULL);
        if (ret<=0) {
 #ifdef ERR_INJ_DEBUG
                printk("Virtual address %lx is not existing.\n",virt_addr);
index 1afd87c999b0c22f1ab08508a233126b5d6d9f2b..982e83f9d11f288bdb24860e0fe8edcf72d68c5a 100644 (file)
@@ -286,8 +286,7 @@ slow_irqon:
        start += nr << PAGE_SHIFT;
        pages += nr;
 
-       ret = get_user_pages_unlocked(current, mm, start,
-                                     (end - start) >> PAGE_SHIFT,
+       ret = get_user_pages_unlocked(start, (end - start) >> PAGE_SHIFT,
                                      write, 0, pages);
 
        /* Have to be a bit careful with return values */
index 13dab0c1645c12de6b284b1b948758a524154441..49a1c84ed2663fadeadb2bc1b8548814d9cab012 100644 (file)
@@ -210,7 +210,6 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
 int get_user_pages_fast(unsigned long start, int nr_pages, int write,
                        struct page **pages)
 {
-       struct mm_struct *mm = current->mm;
        int nr, ret;
 
        might_sleep();
@@ -222,8 +221,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
        /* Try to get the remaining pages with get_user_pages */
        start += nr << PAGE_SHIFT;
        pages += nr;
-       ret = get_user_pages_unlocked(current, mm, start,
-                            nr_pages - nr, write, 0, pages);
+       ret = get_user_pages_unlocked(start, nr_pages - nr, write, 0, pages);
        /* Have to be a bit careful with return values */
        if (nr > 0)
                ret = (ret < 0) ? nr : ret + nr;
index e7af6a65baab915552ae405a16d3bd405b84f763..40fa6c8adc43a361c60ffee8929aa39d2449e926 100644 (file)
@@ -257,7 +257,7 @@ slow_irqon:
                start += nr << PAGE_SHIFT;
                pages += nr;
 
-               ret = get_user_pages_unlocked(current, mm, start,
+               ret = get_user_pages_unlocked(start,
                        (end - start) >> PAGE_SHIFT, write, 0, pages);
 
                /* Have to be a bit careful with return values */
index eb3d8e8ebc6b064febae847c92ef5329a02b8ae4..4e06750a5d295649660ff4ca0998eb03b00da9e9 100644 (file)
@@ -237,7 +237,7 @@ slow:
                start += nr << PAGE_SHIFT;
                pages += nr;
 
-               ret = get_user_pages_unlocked(current, mm, start,
+               ret = get_user_pages_unlocked(start,
                        (end - start) >> PAGE_SHIFT, write, 0, pages);
 
                /* Have to be a bit careful with return values */
index 6d5eb59003721b79213a7661994be1a339bc5590..ce5e4545203b8054179d5a9604f2f719c8cc922e 100644 (file)
@@ -422,7 +422,7 @@ slow_irqon:
                start += nr << PAGE_SHIFT;
                pages += nr;
 
-               ret = get_user_pages_unlocked(current, mm, start,
+               ret = get_user_pages_unlocked(start,
                                              (end - start) >> PAGE_SHIFT,
                                              write, 0, pages);
 
index b2fd67da1701433d9168ebf1d0a908330544bd7d..84fa4a482c781e1ea7922fb0db65b640b78fa076 100644 (file)
@@ -546,8 +546,8 @@ static int mpx_resolve_fault(long __user *addr, int write)
        int nr_pages = 1;
        int force = 0;
 
-       gup_ret = get_user_pages(current, current->mm, (unsigned long)addr,
-                                nr_pages, write, force, NULL, NULL);
+       gup_ret = get_user_pages((unsigned long)addr, nr_pages, write,
+                       force, NULL, NULL);
        /*
         * get_user_pages() returns number of pages gotten.
         * 0 means we failed to fault in and get anything,
index 6442a06d6fdc1ce9115d280cc916b4e55923f2fa..5fedfb68d7ca86dbb2894b2802ef5dd90f7711aa 100644 (file)
@@ -518,8 +518,7 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_tt *ttm)
                uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE;
                struct page **pages = ttm->pages + pinned;
 
-               r = get_user_pages(current, current->mm, userptr, num_pages,
-                                  write, 0, pages, NULL);
+               r = get_user_pages(userptr, num_pages, write, 0, pages, NULL);
                if (r < 0)
                        goto release_pages;
 
index e34307459e501f60895ca4a0abe156995706f921..927a9f2d65701f6f60f943686245eff9714cf281 100644 (file)
@@ -554,8 +554,7 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_tt *ttm)
                uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE;
                struct page **pages = ttm->pages + pinned;
 
-               r = get_user_pages(current, current->mm, userptr, num_pages,
-                                  write, 0, pages, NULL);
+               r = get_user_pages(userptr, num_pages, write, 0, pages, NULL);
                if (r < 0)
                        goto release_pages;
 
index d0cbd5ecd7f0fa4893ff7e775613f3f7e55090f0..e797dfc07ae3fb3ffe5ec036eb6e2d78f09a7cbb 100644 (file)
@@ -239,8 +239,7 @@ via_lock_all_dma_pages(drm_via_sg_info_t *vsg,  drm_via_dmablit_t *xfer)
        if (NULL == vsg->pages)
                return -ENOMEM;
        down_read(&current->mm->mmap_sem);
-       ret = get_user_pages(current, current->mm,
-                            (unsigned long)xfer->mem_addr,
+       ret = get_user_pages((unsigned long)xfer->mem_addr,
                             vsg->num_pages,
                             (vsg->direction == DMA_FROM_DEVICE),
                             0, vsg->pages, NULL);
index 38acb3cfc545f91658f0d465b69914de99f281b2..fe4d2e1a8b58750f961839a53c045d9f72ae1590 100644 (file)
@@ -188,7 +188,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
        sg_list_start = umem->sg_head.sgl;
 
        while (npages) {
-               ret = get_user_pages(current, current->mm, cur_base,
+               ret = get_user_pages(cur_base,
                                     min_t(unsigned long, npages,
                                           PAGE_SIZE / sizeof (struct page *)),
                                     1, !umem->writable, page_list, vma_list);
index 7d2e42dd692657319f94e1ce950545f2638d2380..6c00d04b8b2852369f4f43d78c39c68898ff4640 100644 (file)
@@ -472,8 +472,7 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
                goto out;
        }
 
-       ret = get_user_pages(current, current->mm, uaddr & PAGE_MASK, 1, 1, 0,
-                            pages, NULL);
+       ret = get_user_pages(uaddr & PAGE_MASK, 1, 1, 0, pages, NULL);
        if (ret < 0)
                goto out;
 
index 74f90b2619f6f5169cc4c326e94ba5343b067753..2d2b94fd3633bff1ddbed16d077ee436bbe0ae58 100644 (file)
@@ -66,8 +66,7 @@ static int __qib_get_user_pages(unsigned long start_page, size_t num_pages,
        }
 
        for (got = 0; got < num_pages; got += ret) {
-               ret = get_user_pages(current, current->mm,
-                                    start_page + got * PAGE_SIZE,
+               ret = get_user_pages(start_page + got * PAGE_SIZE,
                                     num_pages - got, 1, 1,
                                     p + got, NULL);
                if (ret < 0)
index 645a5f6e6c88f0a4166bf0647d26d3b7bf082670..7209fbc03ccb90a7360f403fe99303b58c7932ee 100644 (file)
@@ -144,7 +144,7 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable,
        ret = 0;
 
        while (npages) {
-               ret = get_user_pages(current, current->mm, cur_base,
+               ret = get_user_pages(cur_base,
                                        min_t(unsigned long, npages,
                                        PAGE_SIZE / sizeof(struct page *)),
                                        1, !writable, page_list, NULL);
index 24152accc66c75e9efa20cf1257030d94b6a920a..4769469fe842964574eae3a72b812f579ab5f63f 100644 (file)
@@ -124,8 +124,8 @@ int ivtv_udma_setup(struct ivtv *itv, unsigned long ivtv_dest_addr,
        }
 
        /* Get user pages for DMA Xfer */
-       err = get_user_pages_unlocked(current, current->mm,
-                       user_dma.uaddr, user_dma.page_count, 0, 1, dma->map);
+       err = get_user_pages_unlocked(user_dma.uaddr, user_dma.page_count, 0,
+                       1, dma->map);
 
        if (user_dma.page_count != err) {
                IVTV_DEBUG_WARN("failed to map user pages, returned %d instead of %d\n",
index 2b8e7b2f2b865fdd616356fa764a2d3fbe8e901f..b094054cda6e55b64852598d6d22dd6d57e6cdaa 100644 (file)
@@ -75,14 +75,12 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
        ivtv_udma_get_page_info (&uv_dma, (unsigned long)args->uv_source, 360 * uv_decode_height);
 
        /* Get user pages for DMA Xfer */
-       y_pages = get_user_pages_unlocked(current, current->mm,
-                               y_dma.uaddr, y_dma.page_count, 0, 1,
-                               &dma->map[0]);
+       y_pages = get_user_pages_unlocked(y_dma.uaddr,
+                       y_dma.page_count, 0, 1, &dma->map[0]);
        uv_pages = 0; /* silence gcc. value is set and consumed only if: */
        if (y_pages == y_dma.page_count) {
-               uv_pages = get_user_pages_unlocked(current, current->mm,
-                                       uv_dma.uaddr, uv_dma.page_count, 0, 1,
-                                       &dma->map[y_pages]);
+               uv_pages = get_user_pages_unlocked(uv_dma.uaddr,
+                               uv_dma.page_count, 0, 1, &dma->map[y_pages]);
        }
 
        if (y_pages != y_dma.page_count || uv_pages != uv_dma.page_count) {
index f669cedca8bd16cf2c2642ee99ae3643202234e2..df4c052c6bd6111803ab6dfad5edebcb814f3025 100644 (file)
@@ -181,8 +181,7 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
        dprintk(1, "init user [0x%lx+0x%lx => %d pages]\n",
                data, size, dma->nr_pages);
 
-       err = get_user_pages(current, current->mm,
-                            data & PAGE_MASK, dma->nr_pages,
+       err = get_user_pages(data & PAGE_MASK, dma->nr_pages,
                             rw == READ, 1, /* force */
                             dma->pages, NULL);
 
index 8310b4dbff0602ea5f4bd50f3ce87a9e58e854a7..0fa0d242b29589474f0abb081f8c439a117615ec 100644 (file)
@@ -1394,8 +1394,6 @@ retry:
                }
 
                pinned_pages->nr_pages = get_user_pages(
-                               current,
-                               mm,
                                (u64)addr,
                                nr_pages,
                                !!(prot & SCIF_PROT_WRITE),
index f74fc0ca2ef9b86fbb85807ebcc9a9e3bae433fb..a2d97b9b17e3463cebea03c70ec062cafcdac08c 100644 (file)
@@ -198,8 +198,7 @@ static int non_atomic_pte_lookup(struct vm_area_struct *vma,
 #else
        *pageshift = PAGE_SHIFT;
 #endif
-       if (get_user_pages
-           (current, current->mm, vaddr, 1, write, 0, &page, NULL) <= 0)
+       if (get_user_pages(vaddr, 1, write, 0, &page, NULL) <= 0)
                return -EFAULT;
        *paddr = page_to_phys(page);
        put_page(page);
index 2e522951b619740b08a712695dfca31962b16de0..664852af4417dbd591dde2e5074a911221693009 100644 (file)
@@ -4817,8 +4817,6 @@ static int sgl_map_user_pages(struct st_buffer *STbp,
         /* Try to fault in all of the necessary pages */
         /* rw==READ means read from drive, write into memory area */
        res = get_user_pages_unlocked(
-               current,
-               current->mm,
                uaddr,
                nr_pages,
                rw == READ,
index 0e24eb9c219c04953c4eb5c434b1ee5c3d28fe31..71a923e53f93d62e0b6f3dd213077ddf15b5e799 100644 (file)
@@ -686,8 +686,8 @@ static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,
        if (!pages)
                return -ENOMEM;
 
-       ret = get_user_pages_unlocked(current, current->mm, (unsigned long)buf,
-                                     nr_pages, WRITE, 0, pages);
+       ret = get_user_pages_unlocked((unsigned long)buf, nr_pages, WRITE,
+                       0, pages);
 
        if (ret < nr_pages) {
                nr_pages = ret;
index 32c8fc5f7a5c3762f7fc6486f34c7b061b26f1b1..60bdad3a689b8280b373164f7a13fdcb2a5a1cc2 100644 (file)
@@ -244,9 +244,8 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)
 
        /* Get the physical addresses of the source buffer */
        down_read(&current->mm->mmap_sem);
-       num_pinned = get_user_pages(current, current->mm,
-               param.local_vaddr - lb_offset, num_pages,
-               (param.source == -1) ? READ : WRITE,
+       num_pinned = get_user_pages(param.local_vaddr - lb_offset,
+               num_pages, (param.source == -1) ? READ : WRITE,
                0, pages, NULL);
        up_read(&current->mm->mmap_sem);
 
index 7cf2b7163222b1d304ba1a4dde0604c5f29a3bbd..381bb07ed14f2271e487fb98d0e95f6ff5470750 100644 (file)
@@ -58,7 +58,7 @@ int get_vaddr_frames(unsigned long start, unsigned int nr_frames,
        if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) {
                vec->got_ref = true;
                vec->is_pfns = false;
-               ret = get_user_pages_locked(current, mm, start, nr_frames,
+               ret = get_user_pages_locked(start, nr_frames,
                        write, force, (struct page **)(vec->ptrs), &locked);
                goto out;
        }
index 8a035e042b350e19d3dc871990a5be586eb90f31..de24ef4cd1af84c592ec0cfd641e11f983eacf08 100644 (file)
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -936,8 +936,10 @@ long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
 EXPORT_SYMBOL(get_user_pages_remote);
 
 /*
- * This is the same as get_user_pages_remote() for the time
- * being.
+ * This is the same as get_user_pages_remote(), just with a
+ * less-flexible calling convention where we assume that the task
+ * and mm being operated on are the current task's.  We also
+ * obviously don't pass FOLL_REMOTE in here.
  */
 long get_user_pages6(unsigned long start, unsigned long nr_pages,
                int write, int force, struct page **pages,
index ca6d2a06a6157fabdc01aafa06b797320364a87c..c2013f638d113d073d0ca2814420619472c63915 100644 (file)
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -352,7 +352,7 @@ static inline bool ksm_test_exit(struct mm_struct *mm)
 /*
  * We use break_ksm to break COW on a ksm page: it's a stripped down
  *
- *     if (get_user_pages(current, mm, addr, 1, 1, 1, &page, NULL) == 1)
+ *     if (get_user_pages(addr, 1, 1, 1, &page, NULL) == 1)
  *             put_page(page);
  *
  * but taking great care only to touch a ksm page, in a VM_MERGEABLE vma,
index 4c4187c0e1deeb25bdbf5eb383132d27feb9be90..dd0ce7fbd47b7b2b2fffa1fd3db350da1bad1ba8 100644 (file)
@@ -844,12 +844,12 @@ static void get_policy_nodemask(struct mempolicy *p, nodemask_t *nodes)
        }
 }
 
-static int lookup_node(struct mm_struct *mm, unsigned long addr)
+static int lookup_node(unsigned long addr)
 {
        struct page *p;
        int err;
 
-       err = get_user_pages(current, mm, addr & PAGE_MASK, 1, 0, 0, &p, NULL);
+       err = get_user_pages(addr & PAGE_MASK, 1, 0, 0, &p, NULL);
        if (err >= 0) {
                err = page_to_nid(p);
                put_page(p);
@@ -904,7 +904,7 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask,
 
        if (flags & MPOL_F_NODE) {
                if (flags & MPOL_F_ADDR) {
-                       err = lookup_node(mm, addr);
+                       err = lookup_node(addr);
                        if (err < 0)
                                goto out;
                        *policy = err;
index d4f5f220a8e55e063db6d3f3923a32be1ac33223..10297f7a89babc58541d0ee11b016e2531fa3a1e 100644 (file)
@@ -24,7 +24,7 @@ struct page **ceph_get_direct_page_vector(const void __user *data,
                return ERR_PTR(-ENOMEM);
 
        while (got < num_pages) {
-               rc = get_user_pages_unlocked(current, current->mm,
+               rc = get_user_pages_unlocked(
                    (unsigned long)data + ((unsigned long)got * PAGE_SIZE),
                    num_pages - got, write_page, 0, pages + got);
                if (rc < 0)
index a11cfd20a6a0d2aa86b1d06b8552bc41a8bfd8c9..0253ad900ec345593f1e1d346e93ef2ee39cd27a 100644 (file)
@@ -1264,15 +1264,16 @@ unsigned long kvm_vcpu_gfn_to_hva_prot(struct kvm_vcpu *vcpu, gfn_t gfn, bool *w
        return gfn_to_hva_memslot_prot(slot, gfn, writable);
 }
 
-static int get_user_page_nowait(struct task_struct *tsk, struct mm_struct *mm,
-       unsigned long start, int write, struct page **page)
+static int get_user_page_nowait(unsigned long start, int write,
+               struct page **page)
 {
        int flags = FOLL_TOUCH | FOLL_NOWAIT | FOLL_HWPOISON | FOLL_GET;
 
        if (write)
                flags |= FOLL_WRITE;
 
-       return __get_user_pages(tsk, mm, start, 1, flags, page, NULL, NULL);
+       return __get_user_pages(current, current->mm, start, 1, flags, page,
+                       NULL, NULL);
 }
 
 static inline int check_user_page_hwpoison(unsigned long addr)
@@ -1334,8 +1335,7 @@ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault,
 
        if (async) {
                down_read(&current->mm->mmap_sem);
-               npages = get_user_page_nowait(current, current->mm,
-                                             addr, write_fault, page);
+               npages = get_user_page_nowait(addr, write_fault, page);
                up_read(&current->mm->mmap_sem);
        } else
                npages = __get_user_pages_unlocked(current, current->mm, addr, 1,