Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[linux-2.6-microblaze.git] / mm / gup.c
index d8a33dd..ae096ea 100644 (file)
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -859,7 +859,7 @@ unmap:
  * does not include FOLL_NOWAIT, the mmap_lock may be released.  If it
  * is, *@locked will be set to 0 and -EBUSY returned.
  */
-static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
+static int faultin_page(struct vm_area_struct *vma,
                unsigned long address, unsigned int *flags, int *locked)
 {
        unsigned int fault_flags = 0;
@@ -884,7 +884,7 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
                fault_flags |= FAULT_FLAG_TRIED;
        }
 
-       ret = handle_mm_fault(vma, address, fault_flags);
+       ret = handle_mm_fault(vma, address, fault_flags, NULL);
        if (ret & VM_FAULT_ERROR) {
                int err = vm_fault_to_errno(ret, *flags);
 
@@ -893,13 +893,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
                BUG();
        }
 
-       if (tsk) {
-               if (ret & VM_FAULT_MAJOR)
-                       tsk->maj_flt++;
-               else
-                       tsk->min_flt++;
-       }
-
        if (ret & VM_FAULT_RETRY) {
                if (locked && !(fault_flags & FAULT_FLAG_RETRY_NOWAIT))
                        *locked = 0;
@@ -969,7 +962,6 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags)
 
 /**
  * __get_user_pages() - pin user pages in memory
- * @tsk:       task_struct of target task
  * @mm:                mm_struct of target mm
  * @start:     starting user address
  * @nr_pages:  number of pages from start to pin
@@ -1028,7 +1020,7 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags)
  * instead of __get_user_pages. __get_user_pages should be used only if
  * you need some special @gup_flags.
  */
-static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
+static long __get_user_pages(struct mm_struct *mm,
                unsigned long start, unsigned long nr_pages,
                unsigned int gup_flags, struct page **pages,
                struct vm_area_struct **vmas, int *locked)
@@ -1110,8 +1102,7 @@ retry:
 
                page = follow_page_mask(vma, start, foll_flags, &ctx);
                if (!page) {
-                       ret = faultin_page(tsk, vma, start, &foll_flags,
-                                          locked);
+                       ret = faultin_page(vma, start, &foll_flags, locked);
                        switch (ret) {
                        case 0:
                                goto retry;
@@ -1185,8 +1176,6 @@ static bool vma_permits_fault(struct vm_area_struct *vma,
 
 /**
  * fixup_user_fault() - manually resolve a user page fault
- * @tsk:       the task_struct to use for page fault accounting, or
- *             NULL if faults are not to be recorded.
  * @mm:                mm_struct of target mm
  * @address:   user address
  * @fault_flags:flags to pass down to handle_mm_fault()
@@ -1214,7 +1203,7 @@ static bool vma_permits_fault(struct vm_area_struct *vma,
  * This function will not return with an unlocked mmap_lock. So it has not the
  * same semantics wrt the @mm->mmap_lock as does filemap_fault().
  */
-int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
+int fixup_user_fault(struct mm_struct *mm,
                     unsigned long address, unsigned int fault_flags,
                     bool *unlocked)
 {
@@ -1238,7 +1227,7 @@ retry:
            fatal_signal_pending(current))
                return -EINTR;
 
-       ret = handle_mm_fault(vma, address, fault_flags);
+       ret = handle_mm_fault(vma, address, fault_flags, NULL);
        major |= ret & VM_FAULT_MAJOR;
        if (ret & VM_FAULT_ERROR) {
                int err = vm_fault_to_errno(ret, 0);
@@ -1255,12 +1244,6 @@ retry:
                goto retry;
        }
 
-       if (tsk) {
-               if (major)
-                       tsk->maj_flt++;
-               else
-                       tsk->min_flt++;
-       }
        return 0;
 }
 EXPORT_SYMBOL_GPL(fixup_user_fault);
@@ -1269,8 +1252,7 @@ EXPORT_SYMBOL_GPL(fixup_user_fault);
  * Please note that this function, unlike __get_user_pages will not
  * return 0 for nr_pages > 0 without FOLL_NOWAIT
  */
-static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
-                                               struct mm_struct *mm,
+static __always_inline long __get_user_pages_locked(struct mm_struct *mm,
                                                unsigned long start,
                                                unsigned long nr_pages,
                                                struct page **pages,
@@ -1303,7 +1285,7 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
        pages_done = 0;
        lock_dropped = false;
        for (;;) {
-               ret = __get_user_pages(tsk, mm, start, nr_pages, flags, pages,
+               ret = __get_user_pages(mm, start, nr_pages, flags, pages,
                                       vmas, locked);
                if (!locked)
                        /* VM_FAULT_RETRY couldn't trigger, bypass */
@@ -1363,7 +1345,7 @@ retry:
                }
 
                *locked = 1;
-               ret = __get_user_pages(tsk, mm, start, 1, flags | FOLL_TRIED,
+               ret = __get_user_pages(mm, start, 1, flags | FOLL_TRIED,
                                       pages, NULL, locked);
                if (!*locked) {
                        /* Continue to retry until we succeeded */
@@ -1450,7 +1432,7 @@ long populate_vma_page_range(struct vm_area_struct *vma,
         * We made sure addr is within a VMA, so the following will
         * not result in a stack expansion that recurses back here.
         */
-       return __get_user_pages(current, mm, start, nr_pages, gup_flags,
+       return __get_user_pages(mm, start, nr_pages, gup_flags,
                                NULL, NULL, locked);
 }
 
@@ -1534,7 +1516,7 @@ struct page *get_dump_page(unsigned long addr)
        struct vm_area_struct *vma;
        struct page *page;
 
-       if (__get_user_pages(current, current->mm, addr, 1,
+       if (__get_user_pages(current->mm, addr, 1,
                             FOLL_FORCE | FOLL_DUMP | FOLL_GET, &page, &vma,
                             NULL) < 1)
                return NULL;
@@ -1543,8 +1525,7 @@ struct page *get_dump_page(unsigned long addr)
 }
 #endif /* CONFIG_ELF_CORE */
 #else /* CONFIG_MMU */
-static long __get_user_pages_locked(struct task_struct *tsk,
-               struct mm_struct *mm, unsigned long start,
+static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start,
                unsigned long nr_pages, struct page **pages,
                struct vm_area_struct **vmas, int *locked,
                unsigned int foll_flags)
@@ -1609,59 +1590,7 @@ static bool check_dax_vmas(struct vm_area_struct **vmas, long nr_pages)
 }
 
 #ifdef CONFIG_CMA
-static struct page *new_non_cma_page(struct page *page, unsigned long private)
-{
-       /*
-        * We want to make sure we allocate the new page from the same node
-        * as the source page.
-        */
-       int nid = page_to_nid(page);
-       /*
-        * Trying to allocate a page for migration. Ignore allocation
-        * failure warnings. We don't force __GFP_THISNODE here because
-        * this node here is the node where we have CMA reservation and
-        * in some case these nodes will have really less non movable
-        * allocation memory.
-        */
-       gfp_t gfp_mask = GFP_USER | __GFP_NOWARN;
-
-       if (PageHighMem(page))
-               gfp_mask |= __GFP_HIGHMEM;
-
-#ifdef CONFIG_HUGETLB_PAGE
-       if (PageHuge(page)) {
-               struct hstate *h = page_hstate(page);
-               /*
-                * We don't want to dequeue from the pool because pool pages will
-                * mostly be from the CMA region.
-                */
-               return alloc_migrate_huge_page(h, gfp_mask, nid, NULL);
-       }
-#endif
-       if (PageTransHuge(page)) {
-               struct page *thp;
-               /*
-                * ignore allocation failure warnings
-                */
-               gfp_t thp_gfpmask = GFP_TRANSHUGE | __GFP_NOWARN;
-
-               /*
-                * Remove the movable mask so that we don't allocate from
-                * CMA area again.
-                */
-               thp_gfpmask &= ~__GFP_MOVABLE;
-               thp = __alloc_pages_node(nid, thp_gfpmask, HPAGE_PMD_ORDER);
-               if (!thp)
-                       return NULL;
-               prep_transhuge_page(thp);
-               return thp;
-       }
-
-       return __alloc_pages_node(nid, gfp_mask, 0);
-}
-
-static long check_and_migrate_cma_pages(struct task_struct *tsk,
-                                       struct mm_struct *mm,
+static long check_and_migrate_cma_pages(struct mm_struct *mm,
                                        unsigned long start,
                                        unsigned long nr_pages,
                                        struct page **pages,
@@ -1674,6 +1603,10 @@ static long check_and_migrate_cma_pages(struct task_struct *tsk,
        bool migrate_allow = true;
        LIST_HEAD(cma_page_list);
        long ret = nr_pages;
+       struct migration_target_control mtc = {
+               .nid = NUMA_NO_NODE,
+               .gfp_mask = GFP_USER | __GFP_MOVABLE | __GFP_NOWARN,
+       };
 
 check_again:
        for (i = 0; i < nr_pages;) {
@@ -1704,7 +1637,7 @@ check_again:
                                        mod_node_page_state(page_pgdat(head),
                                                            NR_ISOLATED_ANON +
                                                            page_is_file_lru(head),
-                                                           hpage_nr_pages(head));
+                                                           thp_nr_pages(head));
                                }
                        }
                }
@@ -1719,8 +1652,8 @@ check_again:
                for (i = 0; i < nr_pages; i++)
                        put_page(pages[i]);
 
-               if (migrate_pages(&cma_page_list, new_non_cma_page,
-                                 NULL, 0, MIGRATE_SYNC, MR_CONTIG_RANGE)) {
+               if (migrate_pages(&cma_page_list, alloc_migration_target, NULL,
+                       (unsigned long)&mtc, MIGRATE_SYNC, MR_CONTIG_RANGE)) {
                        /*
                         * some of the pages failed migration. Do get_user_pages
                         * without migration.
@@ -1735,7 +1668,7 @@ check_again:
                 * again migrating any new CMA pages which we failed to isolate
                 * earlier.
                 */
-               ret = __get_user_pages_locked(tsk, mm, start, nr_pages,
+               ret = __get_user_pages_locked(mm, start, nr_pages,
                                                   pages, vmas, NULL,
                                                   gup_flags);
 
@@ -1749,8 +1682,7 @@ check_again:
        return ret;
 }
 #else
-static long check_and_migrate_cma_pages(struct task_struct *tsk,
-                                       struct mm_struct *mm,
+static long check_and_migrate_cma_pages(struct mm_struct *mm,
                                        unsigned long start,
                                        unsigned long nr_pages,
                                        struct page **pages,
@@ -1765,8 +1697,7 @@ static long check_and_migrate_cma_pages(struct task_struct *tsk,
  * __gup_longterm_locked() is a wrapper for __get_user_pages_locked which
  * allows us to process the FOLL_LONGTERM flag.
  */
-static long __gup_longterm_locked(struct task_struct *tsk,
-                                 struct mm_struct *mm,
+static long __gup_longterm_locked(struct mm_struct *mm,
                                  unsigned long start,
                                  unsigned long nr_pages,
                                  struct page **pages,
@@ -1791,11 +1722,10 @@ static long __gup_longterm_locked(struct task_struct *tsk,
                flags = memalloc_nocma_save();
        }
 
-       rc = __get_user_pages_locked(tsk, mm, start, nr_pages, pages,
+       rc = __get_user_pages_locked(mm, start, nr_pages, pages,
                                     vmas_tmp, NULL, gup_flags);
 
        if (gup_flags & FOLL_LONGTERM) {
-               memalloc_nocma_restore(flags);
                if (rc < 0)
                        goto out;
 
@@ -1806,32 +1736,31 @@ static long __gup_longterm_locked(struct task_struct *tsk,
                        goto out;
                }
 
-               rc = check_and_migrate_cma_pages(tsk, mm, start, rc, pages,
+               rc = check_and_migrate_cma_pages(mm, start, rc, pages,
                                                 vmas_tmp, gup_flags);
+out:
+               memalloc_nocma_restore(flags);
        }
 
-out:
        if (vmas_tmp != vmas)
                kfree(vmas_tmp);
        return rc;
 }
 #else /* !CONFIG_FS_DAX && !CONFIG_CMA */
-static __always_inline long __gup_longterm_locked(struct task_struct *tsk,
-                                                 struct mm_struct *mm,
+static __always_inline long __gup_longterm_locked(struct mm_struct *mm,
                                                  unsigned long start,
                                                  unsigned long nr_pages,
                                                  struct page **pages,
                                                  struct vm_area_struct **vmas,
                                                  unsigned int flags)
 {
-       return __get_user_pages_locked(tsk, mm, start, nr_pages, pages, vmas,
+       return __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
                                       NULL, flags);
 }
 #endif /* CONFIG_FS_DAX || CONFIG_CMA */
 
 #ifdef CONFIG_MMU
-static long __get_user_pages_remote(struct task_struct *tsk,
-                                   struct mm_struct *mm,
+static long __get_user_pages_remote(struct mm_struct *mm,
                                    unsigned long start, unsigned long nr_pages,
                                    unsigned int gup_flags, struct page **pages,
                                    struct vm_area_struct **vmas, int *locked)
@@ -1850,20 +1779,18 @@ static long __get_user_pages_remote(struct task_struct *tsk,
                 * This will check the vmas (even if our vmas arg is NULL)
                 * and return -ENOTSUPP if DAX isn't allowed in this case:
                 */
-               return __gup_longterm_locked(tsk, mm, start, nr_pages, pages,
+               return __gup_longterm_locked(mm, start, nr_pages, pages,
                                             vmas, gup_flags | FOLL_TOUCH |
                                             FOLL_REMOTE);
        }
 
-       return __get_user_pages_locked(tsk, mm, start, nr_pages, pages, vmas,
+       return __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
                                       locked,
                                       gup_flags | FOLL_TOUCH | FOLL_REMOTE);
 }
 
 /**
  * get_user_pages_remote() - pin user pages in memory
- * @tsk:       the task_struct to use for page fault accounting, or
- *             NULL if faults are not to be recorded.
  * @mm:                mm_struct of target mm
  * @start:     starting user address
  * @nr_pages:  number of pages from start to pin
@@ -1922,7 +1849,7 @@ static long __get_user_pages_remote(struct task_struct *tsk,
  * should use get_user_pages_remote because it cannot pass
  * FAULT_FLAG_ALLOW_RETRY to handle_mm_fault.
  */
-long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
+long get_user_pages_remote(struct mm_struct *mm,
                unsigned long start, unsigned long nr_pages,
                unsigned int gup_flags, struct page **pages,
                struct vm_area_struct **vmas, int *locked)
@@ -1934,13 +1861,13 @@ long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
        if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
                return -EINVAL;
 
-       return __get_user_pages_remote(tsk, mm, start, nr_pages, gup_flags,
+       return __get_user_pages_remote(mm, start, nr_pages, gup_flags,
                                       pages, vmas, locked);
 }
 EXPORT_SYMBOL(get_user_pages_remote);
 
 #else /* CONFIG_MMU */
-long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
+long get_user_pages_remote(struct mm_struct *mm,
                           unsigned long start, unsigned long nr_pages,
                           unsigned int gup_flags, struct page **pages,
                           struct vm_area_struct **vmas, int *locked)
@@ -1948,8 +1875,7 @@ long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
        return 0;
 }
 
-static long __get_user_pages_remote(struct task_struct *tsk,
-                                   struct mm_struct *mm,
+static long __get_user_pages_remote(struct mm_struct *mm,
                                    unsigned long start, unsigned long nr_pages,
                                    unsigned int gup_flags, struct page **pages,
                                    struct vm_area_struct **vmas, int *locked)
@@ -1969,11 +1895,10 @@ static long __get_user_pages_remote(struct task_struct *tsk,
  * @vmas:       array of pointers to vmas corresponding to each page.
  *              Or NULL if the caller does not require them.
  *
- * 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 and don't allow
- * passing of a locked parameter.  We also obviously don't pass
- * FOLL_REMOTE in here.
+ * This is the same as get_user_pages_remote(), just with a less-flexible
+ * calling convention where we assume that the mm being operated on belongs to
+ * the current task, and doesn't allow passing of a locked parameter.  We also
+ * obviously don't pass FOLL_REMOTE in here.
  */
 long get_user_pages(unsigned long start, unsigned long nr_pages,
                unsigned int gup_flags, struct page **pages,
@@ -1986,7 +1911,7 @@ long get_user_pages(unsigned long start, unsigned long nr_pages,
        if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
                return -EINVAL;
 
-       return __gup_longterm_locked(current, current->mm, start, nr_pages,
+       return __gup_longterm_locked(current->mm, start, nr_pages,
                                     pages, vmas, gup_flags | FOLL_TOUCH);
 }
 EXPORT_SYMBOL(get_user_pages);
@@ -1996,7 +1921,7 @@ EXPORT_SYMBOL(get_user_pages);
  *
  *      mmap_read_lock(mm);
  *      do_something()
- *      get_user_pages(tsk, mm, ..., pages, NULL);
+ *      get_user_pages(mm, ..., pages, NULL);
  *      mmap_read_unlock(mm);
  *
  *  to:
@@ -2004,7 +1929,7 @@ EXPORT_SYMBOL(get_user_pages);
  *      int locked = 1;
  *      mmap_read_lock(mm);
  *      do_something()
- *      get_user_pages_locked(tsk, mm, ..., pages, &locked);
+ *      get_user_pages_locked(mm, ..., pages, &locked);
  *      if (locked)
  *          mmap_read_unlock(mm);
  *
@@ -2042,7 +1967,7 @@ long get_user_pages_locked(unsigned long start, unsigned long nr_pages,
        if (WARN_ON_ONCE(gup_flags & FOLL_PIN))
                return -EINVAL;
 
-       return __get_user_pages_locked(current, current->mm, start, nr_pages,
+       return __get_user_pages_locked(current->mm, start, nr_pages,
                                       pages, NULL, locked,
                                       gup_flags | FOLL_TOUCH);
 }
@@ -2052,12 +1977,12 @@ EXPORT_SYMBOL(get_user_pages_locked);
  * get_user_pages_unlocked() is suitable to replace the form:
  *
  *      mmap_read_lock(mm);
- *      get_user_pages(tsk, mm, ..., pages, NULL);
+ *      get_user_pages(mm, ..., pages, NULL);
  *      mmap_read_unlock(mm);
  *
  *  with:
  *
- *      get_user_pages_unlocked(tsk, mm, ..., pages);
+ *      get_user_pages_unlocked(mm, ..., pages);
  *
  * It is functionally equivalent to get_user_pages_fast so
  * get_user_pages_fast should be used instead if specific gup_flags
@@ -2080,7 +2005,7 @@ long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
                return -EINVAL;
 
        mmap_read_lock(mm);
-       ret = __get_user_pages_locked(current, mm, start, nr_pages, pages, NULL,
+       ret = __get_user_pages_locked(mm, start, nr_pages, pages, NULL,
                                      &locked, gup_flags | FOLL_TOUCH);
        if (locked)
                mmap_read_unlock(mm);
@@ -2725,7 +2650,7 @@ static int __gup_longterm_unlocked(unsigned long start, int nr_pages,
         */
        if (gup_flags & FOLL_LONGTERM) {
                mmap_read_lock(current->mm);
-               ret = __gup_longterm_locked(current, current->mm,
+               ret = __gup_longterm_locked(current->mm,
                                            start, nr_pages,
                                            pages, NULL, gup_flags);
                mmap_read_unlock(current->mm);
@@ -2968,10 +2893,8 @@ int pin_user_pages_fast_only(unsigned long start, int nr_pages,
 EXPORT_SYMBOL_GPL(pin_user_pages_fast_only);
 
 /**
- * pin_user_pages_remote() - pin pages of a remote process (task != current)
+ * pin_user_pages_remote() - pin pages of a remote process
  *
- * @tsk:       the task_struct to use for page fault accounting, or
- *             NULL if faults are not to be recorded.
  * @mm:                mm_struct of target mm
  * @start:     starting user address
  * @nr_pages:  number of pages from start to pin
@@ -2992,7 +2915,7 @@ EXPORT_SYMBOL_GPL(pin_user_pages_fast_only);
  * FOLL_PIN means that the pages must be released via unpin_user_page(). Please
  * see Documentation/core-api/pin_user_pages.rst for details.
  */
-long pin_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
+long pin_user_pages_remote(struct mm_struct *mm,
                           unsigned long start, unsigned long nr_pages,
                           unsigned int gup_flags, struct page **pages,
                           struct vm_area_struct **vmas, int *locked)
@@ -3002,7 +2925,7 @@ long pin_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
                return -EINVAL;
 
        gup_flags |= FOLL_PIN;
-       return __get_user_pages_remote(tsk, mm, start, nr_pages, gup_flags,
+       return __get_user_pages_remote(mm, start, nr_pages, gup_flags,
                                       pages, vmas, locked);
 }
 EXPORT_SYMBOL(pin_user_pages_remote);
@@ -3034,7 +2957,7 @@ long pin_user_pages(unsigned long start, unsigned long nr_pages,
                return -EINVAL;
 
        gup_flags |= FOLL_PIN;
-       return __gup_longterm_locked(current, current->mm, start, nr_pages,
+       return __gup_longterm_locked(current->mm, start, nr_pages,
                                     pages, vmas, gup_flags);
 }
 EXPORT_SYMBOL(pin_user_pages);
@@ -3079,7 +3002,7 @@ long pin_user_pages_locked(unsigned long start, unsigned long nr_pages,
                return -EINVAL;
 
        gup_flags |= FOLL_PIN;
-       return __get_user_pages_locked(current, current->mm, start, nr_pages,
+       return __get_user_pages_locked(current->mm, start, nr_pages,
                                       pages, NULL, locked,
                                       gup_flags | FOLL_TOUCH);
 }