1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/kernel.h>
3 #include <linux/errno.h>
5 #include <linux/spinlock.h>
8 #include <linux/memremap.h>
9 #include <linux/pagemap.h>
10 #include <linux/rmap.h>
11 #include <linux/swap.h>
12 #include <linux/swapops.h>
14 #include <linux/sched/signal.h>
15 #include <linux/rwsem.h>
16 #include <linux/hugetlb.h>
17 #include <linux/migrate.h>
18 #include <linux/mm_inline.h>
19 #include <linux/sched/mm.h>
21 #include <asm/mmu_context.h>
22 #include <asm/pgtable.h>
23 #include <asm/tlbflush.h>
27 struct follow_page_context
{
28 struct dev_pagemap
*pgmap
;
29 unsigned int page_mask
;
33 * put_user_pages_dirty_lock() - release and optionally dirty gup-pinned pages
34 * @pages: array of pages to be maybe marked dirty, and definitely released.
35 * @npages: number of pages in the @pages array.
36 * @make_dirty: whether to mark the pages dirty
38 * "gup-pinned page" refers to a page that has had one of the get_user_pages()
39 * variants called on that page.
41 * For each page in the @pages array, make that page (or its head page, if a
42 * compound page) dirty, if @make_dirty is true, and if the page was previously
43 * listed as clean. In any case, releases all pages using put_user_page(),
44 * possibly via put_user_pages(), for the non-dirty case.
46 * Please see the put_user_page() documentation for details.
48 * set_page_dirty_lock() is used internally. If instead, set_page_dirty() is
49 * required, then the caller should a) verify that this is really correct,
50 * because _lock() is usually required, and b) hand code it:
51 * set_page_dirty_lock(), put_user_page().
54 void put_user_pages_dirty_lock(struct page
**pages
, unsigned long npages
,
60 * TODO: this can be optimized for huge pages: if a series of pages is
61 * physically contiguous and part of the same compound page, then a
62 * single operation to the head page should suffice.
66 put_user_pages(pages
, npages
);
70 for (index
= 0; index
< npages
; index
++) {
71 struct page
*page
= compound_head(pages
[index
]);
73 * Checking PageDirty at this point may race with
74 * clear_page_dirty_for_io(), but that's OK. Two key
77 * 1) This code sees the page as already dirty, so it
78 * skips the call to set_page_dirty(). That could happen
79 * because clear_page_dirty_for_io() called
80 * page_mkclean(), followed by set_page_dirty().
81 * However, now the page is going to get written back,
82 * which meets the original intention of setting it
83 * dirty, so all is well: clear_page_dirty_for_io() goes
84 * on to call TestClearPageDirty(), and write the page
87 * 2) This code sees the page as clean, so it calls
88 * set_page_dirty(). The page stays dirty, despite being
89 * written back, so it gets written back again in the
90 * next writeback cycle. This is harmless.
93 set_page_dirty_lock(page
);
97 EXPORT_SYMBOL(put_user_pages_dirty_lock
);
100 * put_user_pages() - release an array of gup-pinned pages.
101 * @pages: array of pages to be marked dirty and released.
102 * @npages: number of pages in the @pages array.
104 * For each page in the @pages array, release the page using put_user_page().
106 * Please see the put_user_page() documentation for details.
108 void put_user_pages(struct page
**pages
, unsigned long npages
)
113 * TODO: this can be optimized for huge pages: if a series of pages is
114 * physically contiguous and part of the same compound page, then a
115 * single operation to the head page should suffice.
117 for (index
= 0; index
< npages
; index
++)
118 put_user_page(pages
[index
]);
120 EXPORT_SYMBOL(put_user_pages
);
123 static struct page
*no_page_table(struct vm_area_struct
*vma
,
127 * When core dumping an enormous anonymous area that nobody
128 * has touched so far, we don't want to allocate unnecessary pages or
129 * page tables. Return error instead of NULL to skip handle_mm_fault,
130 * then get_dump_page() will return NULL to leave a hole in the dump.
131 * But we can only make this optimization where a hole would surely
132 * be zero-filled if handle_mm_fault() actually did handle it.
134 if ((flags
& FOLL_DUMP
) && (!vma
->vm_ops
|| !vma
->vm_ops
->fault
))
135 return ERR_PTR(-EFAULT
);
139 static int follow_pfn_pte(struct vm_area_struct
*vma
, unsigned long address
,
140 pte_t
*pte
, unsigned int flags
)
142 /* No page to get reference */
143 if (flags
& FOLL_GET
)
146 if (flags
& FOLL_TOUCH
) {
149 if (flags
& FOLL_WRITE
)
150 entry
= pte_mkdirty(entry
);
151 entry
= pte_mkyoung(entry
);
153 if (!pte_same(*pte
, entry
)) {
154 set_pte_at(vma
->vm_mm
, address
, pte
, entry
);
155 update_mmu_cache(vma
, address
, pte
);
159 /* Proper page table entry exists, but no corresponding struct page */
164 * FOLL_FORCE or a forced COW break can write even to unwritable pte's,
165 * but only after we've gone through a COW cycle and they are dirty.
167 static inline bool can_follow_write_pte(pte_t pte
, unsigned int flags
)
169 return pte_write(pte
) || ((flags
& FOLL_COW
) && pte_dirty(pte
));
173 * A (separate) COW fault might break the page the other way and
174 * get_user_pages() would return the page from what is now the wrong
175 * VM. So we need to force a COW break at GUP time even for reads.
177 static inline bool should_force_cow_break(struct vm_area_struct
*vma
, unsigned int flags
)
179 return is_cow_mapping(vma
->vm_flags
) && (flags
& FOLL_GET
);
182 static struct page
*follow_page_pte(struct vm_area_struct
*vma
,
183 unsigned long address
, pmd_t
*pmd
, unsigned int flags
,
184 struct dev_pagemap
**pgmap
)
186 struct mm_struct
*mm
= vma
->vm_mm
;
192 if (unlikely(pmd_bad(*pmd
)))
193 return no_page_table(vma
, flags
);
195 ptep
= pte_offset_map_lock(mm
, pmd
, address
, &ptl
);
197 if (!pte_present(pte
)) {
200 * KSM's break_ksm() relies upon recognizing a ksm page
201 * even while it is being migrated, so for that case we
202 * need migration_entry_wait().
204 if (likely(!(flags
& FOLL_MIGRATION
)))
208 entry
= pte_to_swp_entry(pte
);
209 if (!is_migration_entry(entry
))
211 pte_unmap_unlock(ptep
, ptl
);
212 migration_entry_wait(mm
, pmd
, address
);
215 if ((flags
& FOLL_NUMA
) && pte_protnone(pte
))
217 if ((flags
& FOLL_WRITE
) && !can_follow_write_pte(pte
, flags
)) {
218 pte_unmap_unlock(ptep
, ptl
);
222 page
= vm_normal_page(vma
, address
, pte
);
223 if (!page
&& pte_devmap(pte
) && (flags
& FOLL_GET
)) {
225 * Only return device mapping pages in the FOLL_GET case since
226 * they are only valid while holding the pgmap reference.
228 *pgmap
= get_dev_pagemap(pte_pfn(pte
), *pgmap
);
230 page
= pte_page(pte
);
233 } else if (unlikely(!page
)) {
234 if (flags
& FOLL_DUMP
) {
235 /* Avoid special (like zero) pages in core dumps */
236 page
= ERR_PTR(-EFAULT
);
240 if (is_zero_pfn(pte_pfn(pte
))) {
241 page
= pte_page(pte
);
245 ret
= follow_pfn_pte(vma
, address
, ptep
, flags
);
251 if (flags
& FOLL_SPLIT
&& PageTransCompound(page
)) {
254 pte_unmap_unlock(ptep
, ptl
);
256 ret
= split_huge_page(page
);
264 if (flags
& FOLL_GET
) {
265 if (unlikely(!try_get_page(page
))) {
266 page
= ERR_PTR(-ENOMEM
);
270 if (flags
& FOLL_TOUCH
) {
271 if ((flags
& FOLL_WRITE
) &&
272 !pte_dirty(pte
) && !PageDirty(page
))
273 set_page_dirty(page
);
275 * pte_mkyoung() would be more correct here, but atomic care
276 * is needed to avoid losing the dirty bit: it is easier to use
277 * mark_page_accessed().
279 mark_page_accessed(page
);
281 if ((flags
& FOLL_MLOCK
) && (vma
->vm_flags
& VM_LOCKED
)) {
282 /* Do not mlock pte-mapped THP */
283 if (PageTransCompound(page
))
287 * The preliminary mapping check is mainly to avoid the
288 * pointless overhead of lock_page on the ZERO_PAGE
289 * which might bounce very badly if there is contention.
291 * If the page is already locked, we don't need to
292 * handle it now - vmscan will handle it later if and
293 * when it attempts to reclaim the page.
295 if (page
->mapping
&& trylock_page(page
)) {
296 lru_add_drain(); /* push cached pages to LRU */
298 * Because we lock page here, and migration is
299 * blocked by the pte's page reference, and we
300 * know the page is still mapped, we don't even
301 * need to check for file-cache page truncation.
303 mlock_vma_page(page
);
308 pte_unmap_unlock(ptep
, ptl
);
311 pte_unmap_unlock(ptep
, ptl
);
314 return no_page_table(vma
, flags
);
317 static struct page
*follow_pmd_mask(struct vm_area_struct
*vma
,
318 unsigned long address
, pud_t
*pudp
,
320 struct follow_page_context
*ctx
)
325 struct mm_struct
*mm
= vma
->vm_mm
;
327 pmd
= pmd_offset(pudp
, address
);
329 * The READ_ONCE() will stabilize the pmdval in a register or
330 * on the stack so that it will stop changing under the code.
332 pmdval
= READ_ONCE(*pmd
);
333 if (pmd_none(pmdval
))
334 return no_page_table(vma
, flags
);
335 if (pmd_huge(pmdval
) && vma
->vm_flags
& VM_HUGETLB
) {
336 page
= follow_huge_pmd(mm
, address
, pmd
, flags
);
339 return no_page_table(vma
, flags
);
341 if (is_hugepd(__hugepd(pmd_val(pmdval
)))) {
342 page
= follow_huge_pd(vma
, address
,
343 __hugepd(pmd_val(pmdval
)), flags
,
347 return no_page_table(vma
, flags
);
350 if (!pmd_present(pmdval
)) {
351 if (likely(!(flags
& FOLL_MIGRATION
)))
352 return no_page_table(vma
, flags
);
353 VM_BUG_ON(thp_migration_supported() &&
354 !is_pmd_migration_entry(pmdval
));
355 if (is_pmd_migration_entry(pmdval
))
356 pmd_migration_entry_wait(mm
, pmd
);
357 pmdval
= READ_ONCE(*pmd
);
359 * MADV_DONTNEED may convert the pmd to null because
360 * mmap_sem is held in read mode
362 if (pmd_none(pmdval
))
363 return no_page_table(vma
, flags
);
366 if (pmd_devmap(pmdval
)) {
367 ptl
= pmd_lock(mm
, pmd
);
368 page
= follow_devmap_pmd(vma
, address
, pmd
, flags
, &ctx
->pgmap
);
373 if (likely(!pmd_trans_huge(pmdval
)))
374 return follow_page_pte(vma
, address
, pmd
, flags
, &ctx
->pgmap
);
376 if ((flags
& FOLL_NUMA
) && pmd_protnone(pmdval
))
377 return no_page_table(vma
, flags
);
380 ptl
= pmd_lock(mm
, pmd
);
381 if (unlikely(pmd_none(*pmd
))) {
383 return no_page_table(vma
, flags
);
385 if (unlikely(!pmd_present(*pmd
))) {
387 if (likely(!(flags
& FOLL_MIGRATION
)))
388 return no_page_table(vma
, flags
);
389 pmd_migration_entry_wait(mm
, pmd
);
392 if (unlikely(!pmd_trans_huge(*pmd
))) {
394 return follow_page_pte(vma
, address
, pmd
, flags
, &ctx
->pgmap
);
396 if (flags
& (FOLL_SPLIT
| FOLL_SPLIT_PMD
)) {
398 page
= pmd_page(*pmd
);
399 if (is_huge_zero_page(page
)) {
402 split_huge_pmd(vma
, pmd
, address
);
403 if (pmd_trans_unstable(pmd
))
405 } else if (flags
& FOLL_SPLIT
) {
406 if (unlikely(!try_get_page(page
))) {
408 return ERR_PTR(-ENOMEM
);
412 ret
= split_huge_page(page
);
416 return no_page_table(vma
, flags
);
417 } else { /* flags & FOLL_SPLIT_PMD */
419 split_huge_pmd(vma
, pmd
, address
);
420 ret
= pte_alloc(mm
, pmd
) ? -ENOMEM
: 0;
423 return ret
? ERR_PTR(ret
) :
424 follow_page_pte(vma
, address
, pmd
, flags
, &ctx
->pgmap
);
426 page
= follow_trans_huge_pmd(vma
, address
, pmd
, flags
);
428 ctx
->page_mask
= HPAGE_PMD_NR
- 1;
432 static struct page
*follow_pud_mask(struct vm_area_struct
*vma
,
433 unsigned long address
, p4d_t
*p4dp
,
435 struct follow_page_context
*ctx
)
440 struct mm_struct
*mm
= vma
->vm_mm
;
442 pud
= pud_offset(p4dp
, address
);
444 return no_page_table(vma
, flags
);
445 if (pud_huge(*pud
) && vma
->vm_flags
& VM_HUGETLB
) {
446 page
= follow_huge_pud(mm
, address
, pud
, flags
);
449 return no_page_table(vma
, flags
);
451 if (is_hugepd(__hugepd(pud_val(*pud
)))) {
452 page
= follow_huge_pd(vma
, address
,
453 __hugepd(pud_val(*pud
)), flags
,
457 return no_page_table(vma
, flags
);
459 if (pud_devmap(*pud
)) {
460 ptl
= pud_lock(mm
, pud
);
461 page
= follow_devmap_pud(vma
, address
, pud
, flags
, &ctx
->pgmap
);
466 if (unlikely(pud_bad(*pud
)))
467 return no_page_table(vma
, flags
);
469 return follow_pmd_mask(vma
, address
, pud
, flags
, ctx
);
472 static struct page
*follow_p4d_mask(struct vm_area_struct
*vma
,
473 unsigned long address
, pgd_t
*pgdp
,
475 struct follow_page_context
*ctx
)
480 p4d
= p4d_offset(pgdp
, address
);
482 return no_page_table(vma
, flags
);
483 BUILD_BUG_ON(p4d_huge(*p4d
));
484 if (unlikely(p4d_bad(*p4d
)))
485 return no_page_table(vma
, flags
);
487 if (is_hugepd(__hugepd(p4d_val(*p4d
)))) {
488 page
= follow_huge_pd(vma
, address
,
489 __hugepd(p4d_val(*p4d
)), flags
,
493 return no_page_table(vma
, flags
);
495 return follow_pud_mask(vma
, address
, p4d
, flags
, ctx
);
499 * follow_page_mask - look up a page descriptor from a user-virtual address
500 * @vma: vm_area_struct mapping @address
501 * @address: virtual address to look up
502 * @flags: flags modifying lookup behaviour
503 * @ctx: contains dev_pagemap for %ZONE_DEVICE memory pinning and a
504 * pointer to output page_mask
506 * @flags can have FOLL_ flags set, defined in <linux/mm.h>
508 * When getting pages from ZONE_DEVICE memory, the @ctx->pgmap caches
509 * the device's dev_pagemap metadata to avoid repeating expensive lookups.
511 * On output, the @ctx->page_mask is set according to the size of the page.
513 * Return: the mapped (struct page *), %NULL if no mapping exists, or
514 * an error pointer if there is a mapping to something not represented
515 * by a page descriptor (see also vm_normal_page()).
517 static struct page
*follow_page_mask(struct vm_area_struct
*vma
,
518 unsigned long address
, unsigned int flags
,
519 struct follow_page_context
*ctx
)
523 struct mm_struct
*mm
= vma
->vm_mm
;
527 /* make this handle hugepd */
528 page
= follow_huge_addr(mm
, address
, flags
& FOLL_WRITE
);
530 BUG_ON(flags
& FOLL_GET
);
534 pgd
= pgd_offset(mm
, address
);
536 if (pgd_none(*pgd
) || unlikely(pgd_bad(*pgd
)))
537 return no_page_table(vma
, flags
);
539 if (pgd_huge(*pgd
)) {
540 page
= follow_huge_pgd(mm
, address
, pgd
, flags
);
543 return no_page_table(vma
, flags
);
545 if (is_hugepd(__hugepd(pgd_val(*pgd
)))) {
546 page
= follow_huge_pd(vma
, address
,
547 __hugepd(pgd_val(*pgd
)), flags
,
551 return no_page_table(vma
, flags
);
554 return follow_p4d_mask(vma
, address
, pgd
, flags
, ctx
);
557 struct page
*follow_page(struct vm_area_struct
*vma
, unsigned long address
,
558 unsigned int foll_flags
)
560 struct follow_page_context ctx
= { NULL
};
563 page
= follow_page_mask(vma
, address
, foll_flags
, &ctx
);
565 put_dev_pagemap(ctx
.pgmap
);
569 static int get_gate_page(struct mm_struct
*mm
, unsigned long address
,
570 unsigned int gup_flags
, struct vm_area_struct
**vma
,
580 /* user gate pages are read-only */
581 if (gup_flags
& FOLL_WRITE
)
583 if (address
> TASK_SIZE
)
584 pgd
= pgd_offset_k(address
);
586 pgd
= pgd_offset_gate(mm
, address
);
589 p4d
= p4d_offset(pgd
, address
);
592 pud
= pud_offset(p4d
, address
);
595 pmd
= pmd_offset(pud
, address
);
596 if (!pmd_present(*pmd
))
598 VM_BUG_ON(pmd_trans_huge(*pmd
));
599 pte
= pte_offset_map(pmd
, address
);
602 *vma
= get_gate_vma(mm
);
605 *page
= vm_normal_page(*vma
, address
, *pte
);
607 if ((gup_flags
& FOLL_DUMP
) || !is_zero_pfn(pte_pfn(*pte
)))
609 *page
= pte_page(*pte
);
611 if (unlikely(!try_get_page(*page
))) {
623 * mmap_sem must be held on entry. If @nonblocking != NULL and
624 * *@flags does not include FOLL_NOWAIT, the mmap_sem may be released.
625 * If it is, *@nonblocking will be set to 0 and -EBUSY returned.
627 static int faultin_page(struct task_struct
*tsk
, struct vm_area_struct
*vma
,
628 unsigned long address
, unsigned int *flags
, int *nonblocking
)
630 unsigned int fault_flags
= 0;
633 /* mlock all present pages, but do not fault in new pages */
634 if ((*flags
& (FOLL_POPULATE
| FOLL_MLOCK
)) == FOLL_MLOCK
)
636 if (*flags
& FOLL_WRITE
)
637 fault_flags
|= FAULT_FLAG_WRITE
;
638 if (*flags
& FOLL_REMOTE
)
639 fault_flags
|= FAULT_FLAG_REMOTE
;
641 fault_flags
|= FAULT_FLAG_ALLOW_RETRY
;
642 if (*flags
& FOLL_NOWAIT
)
643 fault_flags
|= FAULT_FLAG_ALLOW_RETRY
| FAULT_FLAG_RETRY_NOWAIT
;
644 if (*flags
& FOLL_TRIED
) {
645 VM_WARN_ON_ONCE(fault_flags
& FAULT_FLAG_ALLOW_RETRY
);
646 fault_flags
|= FAULT_FLAG_TRIED
;
649 ret
= handle_mm_fault(vma
, address
, fault_flags
);
650 if (ret
& VM_FAULT_ERROR
) {
651 int err
= vm_fault_to_errno(ret
, *flags
);
659 if (ret
& VM_FAULT_MAJOR
)
665 if (ret
& VM_FAULT_RETRY
) {
666 if (nonblocking
&& !(fault_flags
& FAULT_FLAG_RETRY_NOWAIT
))
672 * The VM_FAULT_WRITE bit tells us that do_wp_page has broken COW when
673 * necessary, even if maybe_mkwrite decided not to set pte_write. We
674 * can thus safely do subsequent page lookups as if they were reads.
675 * But only do so when looping for pte_write is futile: in some cases
676 * userspace may also be wanting to write to the gotten user page,
677 * which a read fault here might prevent (a readonly page might get
678 * reCOWed by userspace write).
680 if ((ret
& VM_FAULT_WRITE
) && !(vma
->vm_flags
& VM_WRITE
))
685 static int check_vma_flags(struct vm_area_struct
*vma
, unsigned long gup_flags
)
687 vm_flags_t vm_flags
= vma
->vm_flags
;
688 int write
= (gup_flags
& FOLL_WRITE
);
689 int foreign
= (gup_flags
& FOLL_REMOTE
);
691 if (vm_flags
& (VM_IO
| VM_PFNMAP
))
694 if (gup_flags
& FOLL_ANON
&& !vma_is_anonymous(vma
))
698 if (!(vm_flags
& VM_WRITE
)) {
699 if (!(gup_flags
& FOLL_FORCE
))
702 * We used to let the write,force case do COW in a
703 * VM_MAYWRITE VM_SHARED !VM_WRITE vma, so ptrace could
704 * set a breakpoint in a read-only mapping of an
705 * executable, without corrupting the file (yet only
706 * when that file had been opened for writing!).
707 * Anon pages in shared mappings are surprising: now
710 if (!is_cow_mapping(vm_flags
))
713 } else if (!(vm_flags
& VM_READ
)) {
714 if (!(gup_flags
& FOLL_FORCE
))
717 * Is there actually any vma we can reach here which does not
718 * have VM_MAYREAD set?
720 if (!(vm_flags
& VM_MAYREAD
))
724 * gups are always data accesses, not instruction
725 * fetches, so execute=false here
727 if (!arch_vma_access_permitted(vma
, write
, false, foreign
))
733 * __get_user_pages() - pin user pages in memory
734 * @tsk: task_struct of target task
735 * @mm: mm_struct of target mm
736 * @start: starting user address
737 * @nr_pages: number of pages from start to pin
738 * @gup_flags: flags modifying pin behaviour
739 * @pages: array that receives pointers to the pages pinned.
740 * Should be at least nr_pages long. Or NULL, if caller
741 * only intends to ensure the pages are faulted in.
742 * @vmas: array of pointers to vmas corresponding to each page.
743 * Or NULL if the caller does not require them.
744 * @nonblocking: whether waiting for disk IO or mmap_sem contention
746 * Returns number of pages pinned. This may be fewer than the number
747 * requested. If nr_pages is 0 or negative, returns 0. If no pages
748 * were pinned, returns -errno. Each page returned must be released
749 * with a put_page() call when it is finished with. vmas will only
750 * remain valid while mmap_sem is held.
752 * Must be called with mmap_sem held. It may be released. See below.
754 * __get_user_pages walks a process's page tables and takes a reference to
755 * each struct page that each user address corresponds to at a given
756 * instant. That is, it takes the page that would be accessed if a user
757 * thread accesses the given user virtual address at that instant.
759 * This does not guarantee that the page exists in the user mappings when
760 * __get_user_pages returns, and there may even be a completely different
761 * page there in some cases (eg. if mmapped pagecache has been invalidated
762 * and subsequently re faulted). However it does guarantee that the page
763 * won't be freed completely. And mostly callers simply care that the page
764 * contains data that was valid *at some point in time*. Typically, an IO
765 * or similar operation cannot guarantee anything stronger anyway because
766 * locks can't be held over the syscall boundary.
768 * If @gup_flags & FOLL_WRITE == 0, the page must not be written to. If
769 * the page is written to, set_page_dirty (or set_page_dirty_lock, as
770 * appropriate) must be called after the page is finished with, and
771 * before put_page is called.
773 * If @nonblocking != NULL, __get_user_pages will not wait for disk IO
774 * or mmap_sem contention, and if waiting is needed to pin all pages,
775 * *@nonblocking will be set to 0. Further, if @gup_flags does not
776 * include FOLL_NOWAIT, the mmap_sem will be released via up_read() in
779 * A caller using such a combination of @nonblocking and @gup_flags
780 * must therefore hold the mmap_sem for reading only, and recognize
781 * when it's been released. Otherwise, it must be held for either
782 * reading or writing and will not be released.
784 * In most cases, get_user_pages or get_user_pages_fast should be used
785 * instead of __get_user_pages. __get_user_pages should be used only if
786 * you need some special @gup_flags.
788 static long __get_user_pages(struct task_struct
*tsk
, struct mm_struct
*mm
,
789 unsigned long start
, unsigned long nr_pages
,
790 unsigned int gup_flags
, struct page
**pages
,
791 struct vm_area_struct
**vmas
, int *nonblocking
)
794 struct vm_area_struct
*vma
= NULL
;
795 struct follow_page_context ctx
= { NULL
};
800 start
= untagged_addr(start
);
802 VM_BUG_ON(!!pages
!= !!(gup_flags
& FOLL_GET
));
805 * If FOLL_FORCE is set then do not force a full fault as the hinting
806 * fault information is unrelated to the reference behaviour of a task
807 * using the address space
809 if (!(gup_flags
& FOLL_FORCE
))
810 gup_flags
|= FOLL_NUMA
;
814 unsigned int foll_flags
= gup_flags
;
815 unsigned int page_increm
;
817 /* first iteration or cross vma bound */
818 if (!vma
|| start
>= vma
->vm_end
) {
819 vma
= find_extend_vma(mm
, start
);
820 if (!vma
&& in_gate_area(mm
, start
)) {
821 ret
= get_gate_page(mm
, start
& PAGE_MASK
,
823 pages
? &pages
[i
] : NULL
);
830 if (!vma
|| check_vma_flags(vma
, gup_flags
)) {
834 if (is_vm_hugetlb_page(vma
)) {
835 if (should_force_cow_break(vma
, foll_flags
))
836 foll_flags
|= FOLL_WRITE
;
837 i
= follow_hugetlb_page(mm
, vma
, pages
, vmas
,
838 &start
, &nr_pages
, i
,
839 foll_flags
, nonblocking
);
844 if (should_force_cow_break(vma
, foll_flags
))
845 foll_flags
|= FOLL_WRITE
;
849 * If we have a pending SIGKILL, don't keep faulting pages and
850 * potentially allocating memory.
852 if (fatal_signal_pending(current
)) {
858 page
= follow_page_mask(vma
, start
, foll_flags
, &ctx
);
860 ret
= faultin_page(tsk
, vma
, start
, &foll_flags
,
876 } else if (PTR_ERR(page
) == -EEXIST
) {
878 * Proper page table entry exists, but no corresponding
882 } else if (IS_ERR(page
)) {
888 flush_anon_page(vma
, page
, start
);
889 flush_dcache_page(page
);
897 page_increm
= 1 + (~(start
>> PAGE_SHIFT
) & ctx
.page_mask
);
898 if (page_increm
> nr_pages
)
899 page_increm
= nr_pages
;
901 start
+= page_increm
* PAGE_SIZE
;
902 nr_pages
-= page_increm
;
906 put_dev_pagemap(ctx
.pgmap
);
910 static bool vma_permits_fault(struct vm_area_struct
*vma
,
911 unsigned int fault_flags
)
913 bool write
= !!(fault_flags
& FAULT_FLAG_WRITE
);
914 bool foreign
= !!(fault_flags
& FAULT_FLAG_REMOTE
);
915 vm_flags_t vm_flags
= write
? VM_WRITE
: VM_READ
;
917 if (!(vm_flags
& vma
->vm_flags
))
921 * The architecture might have a hardware protection
922 * mechanism other than read/write that can deny access.
924 * gup always represents data access, not instruction
925 * fetches, so execute=false here:
927 if (!arch_vma_access_permitted(vma
, write
, false, foreign
))
934 * fixup_user_fault() - manually resolve a user page fault
935 * @tsk: the task_struct to use for page fault accounting, or
936 * NULL if faults are not to be recorded.
937 * @mm: mm_struct of target mm
938 * @address: user address
939 * @fault_flags:flags to pass down to handle_mm_fault()
940 * @unlocked: did we unlock the mmap_sem while retrying, maybe NULL if caller
941 * does not allow retry
943 * This is meant to be called in the specific scenario where for locking reasons
944 * we try to access user memory in atomic context (within a pagefault_disable()
945 * section), this returns -EFAULT, and we want to resolve the user fault before
948 * Typically this is meant to be used by the futex code.
950 * The main difference with get_user_pages() is that this function will
951 * unconditionally call handle_mm_fault() which will in turn perform all the
952 * necessary SW fixup of the dirty and young bits in the PTE, while
953 * get_user_pages() only guarantees to update these in the struct page.
955 * This is important for some architectures where those bits also gate the
956 * access permission to the page because they are maintained in software. On
957 * such architectures, gup() will not be enough to make a subsequent access
960 * This function will not return with an unlocked mmap_sem. So it has not the
961 * same semantics wrt the @mm->mmap_sem as does filemap_fault().
963 int fixup_user_fault(struct task_struct
*tsk
, struct mm_struct
*mm
,
964 unsigned long address
, unsigned int fault_flags
,
967 struct vm_area_struct
*vma
;
968 vm_fault_t ret
, major
= 0;
970 address
= untagged_addr(address
);
973 fault_flags
|= FAULT_FLAG_ALLOW_RETRY
;
976 vma
= find_extend_vma(mm
, address
);
977 if (!vma
|| address
< vma
->vm_start
)
980 if (!vma_permits_fault(vma
, fault_flags
))
983 ret
= handle_mm_fault(vma
, address
, fault_flags
);
984 major
|= ret
& VM_FAULT_MAJOR
;
985 if (ret
& VM_FAULT_ERROR
) {
986 int err
= vm_fault_to_errno(ret
, 0);
993 if (ret
& VM_FAULT_RETRY
) {
994 down_read(&mm
->mmap_sem
);
995 if (!(fault_flags
& FAULT_FLAG_TRIED
)) {
997 fault_flags
&= ~FAULT_FLAG_ALLOW_RETRY
;
998 fault_flags
|= FAULT_FLAG_TRIED
;
1011 EXPORT_SYMBOL_GPL(fixup_user_fault
);
1013 static __always_inline
long __get_user_pages_locked(struct task_struct
*tsk
,
1014 struct mm_struct
*mm
,
1015 unsigned long start
,
1016 unsigned long nr_pages
,
1017 struct page
**pages
,
1018 struct vm_area_struct
**vmas
,
1022 long ret
, pages_done
;
1026 /* if VM_FAULT_RETRY can be returned, vmas become invalid */
1028 /* check caller initialized locked */
1029 BUG_ON(*locked
!= 1);
1036 lock_dropped
= false;
1038 ret
= __get_user_pages(tsk
, mm
, start
, nr_pages
, flags
, pages
,
1041 /* VM_FAULT_RETRY couldn't trigger, bypass */
1044 /* VM_FAULT_RETRY cannot return errors */
1047 BUG_ON(ret
>= nr_pages
);
1058 * VM_FAULT_RETRY didn't trigger or it was a
1066 * VM_FAULT_RETRY triggered, so seek to the faulting offset.
1067 * For the prefault case (!pages) we only update counts.
1071 start
+= ret
<< PAGE_SHIFT
;
1074 * Repeat on the address that fired VM_FAULT_RETRY
1075 * without FAULT_FLAG_ALLOW_RETRY but with
1079 lock_dropped
= true;
1080 down_read(&mm
->mmap_sem
);
1081 ret
= __get_user_pages(tsk
, mm
, start
, 1, flags
| FOLL_TRIED
,
1097 if (lock_dropped
&& *locked
) {
1099 * We must let the caller know we temporarily dropped the lock
1100 * and so the critical section protected by it was lost.
1102 up_read(&mm
->mmap_sem
);
1109 * get_user_pages_remote() - pin user pages in memory
1110 * @tsk: the task_struct to use for page fault accounting, or
1111 * NULL if faults are not to be recorded.
1112 * @mm: mm_struct of target mm
1113 * @start: starting user address
1114 * @nr_pages: number of pages from start to pin
1115 * @gup_flags: flags modifying lookup behaviour
1116 * @pages: array that receives pointers to the pages pinned.
1117 * Should be at least nr_pages long. Or NULL, if caller
1118 * only intends to ensure the pages are faulted in.
1119 * @vmas: array of pointers to vmas corresponding to each page.
1120 * Or NULL if the caller does not require them.
1121 * @locked: pointer to lock flag indicating whether lock is held and
1122 * subsequently whether VM_FAULT_RETRY functionality can be
1123 * utilised. Lock must initially be held.
1125 * Returns number of pages pinned. This may be fewer than the number
1126 * requested. If nr_pages is 0 or negative, returns 0. If no pages
1127 * were pinned, returns -errno. Each page returned must be released
1128 * with a put_page() call when it is finished with. vmas will only
1129 * remain valid while mmap_sem is held.
1131 * Must be called with mmap_sem held for read or write.
1133 * get_user_pages walks a process's page tables and takes a reference to
1134 * each struct page that each user address corresponds to at a given
1135 * instant. That is, it takes the page that would be accessed if a user
1136 * thread accesses the given user virtual address at that instant.
1138 * This does not guarantee that the page exists in the user mappings when
1139 * get_user_pages returns, and there may even be a completely different
1140 * page there in some cases (eg. if mmapped pagecache has been invalidated
1141 * and subsequently re faulted). However it does guarantee that the page
1142 * won't be freed completely. And mostly callers simply care that the page
1143 * contains data that was valid *at some point in time*. Typically, an IO
1144 * or similar operation cannot guarantee anything stronger anyway because
1145 * locks can't be held over the syscall boundary.
1147 * If gup_flags & FOLL_WRITE == 0, the page must not be written to. If the page
1148 * is written to, set_page_dirty (or set_page_dirty_lock, as appropriate) must
1149 * be called after the page is finished with, and before put_page is called.
1151 * get_user_pages is typically used for fewer-copy IO operations, to get a
1152 * handle on the memory by some means other than accesses via the user virtual
1153 * addresses. The pages may be submitted for DMA to devices or accessed via
1154 * their kernel linear mapping (via the kmap APIs). Care should be taken to
1155 * use the correct cache flushing APIs.
1157 * See also get_user_pages_fast, for performance critical applications.
1159 * get_user_pages should be phased out in favor of
1160 * get_user_pages_locked|unlocked or get_user_pages_fast. Nothing
1161 * should use get_user_pages because it cannot pass
1162 * FAULT_FLAG_ALLOW_RETRY to handle_mm_fault.
1164 long get_user_pages_remote(struct task_struct
*tsk
, struct mm_struct
*mm
,
1165 unsigned long start
, unsigned long nr_pages
,
1166 unsigned int gup_flags
, struct page
**pages
,
1167 struct vm_area_struct
**vmas
, int *locked
)
1170 * FIXME: Current FOLL_LONGTERM behavior is incompatible with
1171 * FAULT_FLAG_ALLOW_RETRY because of the FS DAX check requirement on
1172 * vmas. As there are no users of this flag in this call we simply
1173 * disallow this option for now.
1175 if (WARN_ON_ONCE(gup_flags
& FOLL_LONGTERM
))
1178 return __get_user_pages_locked(tsk
, mm
, start
, nr_pages
, pages
, vmas
,
1180 gup_flags
| FOLL_TOUCH
| FOLL_REMOTE
);
1182 EXPORT_SYMBOL(get_user_pages_remote
);
1185 * populate_vma_page_range() - populate a range of pages in the vma.
1187 * @start: start address
1191 * This takes care of mlocking the pages too if VM_LOCKED is set.
1193 * return 0 on success, negative error code on error.
1195 * vma->vm_mm->mmap_sem must be held.
1197 * If @nonblocking is NULL, it may be held for read or write and will
1200 * If @nonblocking is non-NULL, it must held for read only and may be
1201 * released. If it's released, *@nonblocking will be set to 0.
1203 long populate_vma_page_range(struct vm_area_struct
*vma
,
1204 unsigned long start
, unsigned long end
, int *nonblocking
)
1206 struct mm_struct
*mm
= vma
->vm_mm
;
1207 unsigned long nr_pages
= (end
- start
) / PAGE_SIZE
;
1210 VM_BUG_ON(start
& ~PAGE_MASK
);
1211 VM_BUG_ON(end
& ~PAGE_MASK
);
1212 VM_BUG_ON_VMA(start
< vma
->vm_start
, vma
);
1213 VM_BUG_ON_VMA(end
> vma
->vm_end
, vma
);
1214 VM_BUG_ON_MM(!rwsem_is_locked(&mm
->mmap_sem
), mm
);
1216 gup_flags
= FOLL_TOUCH
| FOLL_POPULATE
| FOLL_MLOCK
;
1217 if (vma
->vm_flags
& VM_LOCKONFAULT
)
1218 gup_flags
&= ~FOLL_POPULATE
;
1220 * We want to touch writable mappings with a write fault in order
1221 * to break COW, except for shared mappings because these don't COW
1222 * and we would not want to dirty them for nothing.
1224 if ((vma
->vm_flags
& (VM_WRITE
| VM_SHARED
)) == VM_WRITE
)
1225 gup_flags
|= FOLL_WRITE
;
1228 * We want mlock to succeed for regions that have any permissions
1229 * other than PROT_NONE.
1231 if (vma
->vm_flags
& (VM_READ
| VM_WRITE
| VM_EXEC
))
1232 gup_flags
|= FOLL_FORCE
;
1235 * We made sure addr is within a VMA, so the following will
1236 * not result in a stack expansion that recurses back here.
1238 return __get_user_pages(current
, mm
, start
, nr_pages
, gup_flags
,
1239 NULL
, NULL
, nonblocking
);
1243 * __mm_populate - populate and/or mlock pages within a range of address space.
1245 * This is used to implement mlock() and the MAP_POPULATE / MAP_LOCKED mmap
1246 * flags. VMAs must be already marked with the desired vm_flags, and
1247 * mmap_sem must not be held.
1249 int __mm_populate(unsigned long start
, unsigned long len
, int ignore_errors
)
1251 struct mm_struct
*mm
= current
->mm
;
1252 unsigned long end
, nstart
, nend
;
1253 struct vm_area_struct
*vma
= NULL
;
1259 for (nstart
= start
; nstart
< end
; nstart
= nend
) {
1261 * We want to fault in pages for [nstart; end) address range.
1262 * Find first corresponding VMA.
1266 down_read(&mm
->mmap_sem
);
1267 vma
= find_vma(mm
, nstart
);
1268 } else if (nstart
>= vma
->vm_end
)
1270 if (!vma
|| vma
->vm_start
>= end
)
1273 * Set [nstart; nend) to intersection of desired address
1274 * range with the first VMA. Also, skip undesirable VMA types.
1276 nend
= min(end
, vma
->vm_end
);
1277 if (vma
->vm_flags
& (VM_IO
| VM_PFNMAP
))
1279 if (nstart
< vma
->vm_start
)
1280 nstart
= vma
->vm_start
;
1282 * Now fault in a range of pages. populate_vma_page_range()
1283 * double checks the vma flags, so that it won't mlock pages
1284 * if the vma was already munlocked.
1286 ret
= populate_vma_page_range(vma
, nstart
, nend
, &locked
);
1288 if (ignore_errors
) {
1290 continue; /* continue at next VMA */
1294 nend
= nstart
+ ret
* PAGE_SIZE
;
1298 up_read(&mm
->mmap_sem
);
1299 return ret
; /* 0 or negative error code */
1303 * get_dump_page() - pin user page in memory while writing it to core dump
1304 * @addr: user address
1306 * Returns struct page pointer of user page pinned for dump,
1307 * to be freed afterwards by put_page().
1309 * Returns NULL on any kind of failure - a hole must then be inserted into
1310 * the corefile, to preserve alignment with its headers; and also returns
1311 * NULL wherever the ZERO_PAGE, or an anonymous pte_none, has been found -
1312 * allowing a hole to be left in the corefile to save diskspace.
1314 * Called without mmap_sem, but after all other threads have been killed.
1316 #ifdef CONFIG_ELF_CORE
1317 struct page
*get_dump_page(unsigned long addr
)
1319 struct vm_area_struct
*vma
;
1322 if (__get_user_pages(current
, current
->mm
, addr
, 1,
1323 FOLL_FORCE
| FOLL_DUMP
| FOLL_GET
, &page
, &vma
,
1326 flush_cache_page(vma
, addr
, page_to_pfn(page
));
1329 #endif /* CONFIG_ELF_CORE */
1330 #else /* CONFIG_MMU */
1331 static long __get_user_pages_locked(struct task_struct
*tsk
,
1332 struct mm_struct
*mm
, unsigned long start
,
1333 unsigned long nr_pages
, struct page
**pages
,
1334 struct vm_area_struct
**vmas
, int *locked
,
1335 unsigned int foll_flags
)
1337 struct vm_area_struct
*vma
;
1338 unsigned long vm_flags
;
1341 /* calculate required read or write permissions.
1342 * If FOLL_FORCE is set, we only require the "MAY" flags.
1344 vm_flags
= (foll_flags
& FOLL_WRITE
) ?
1345 (VM_WRITE
| VM_MAYWRITE
) : (VM_READ
| VM_MAYREAD
);
1346 vm_flags
&= (foll_flags
& FOLL_FORCE
) ?
1347 (VM_MAYREAD
| VM_MAYWRITE
) : (VM_READ
| VM_WRITE
);
1349 for (i
= 0; i
< nr_pages
; i
++) {
1350 vma
= find_vma(mm
, start
);
1352 goto finish_or_fault
;
1354 /* protect what we can, including chardevs */
1355 if ((vma
->vm_flags
& (VM_IO
| VM_PFNMAP
)) ||
1356 !(vm_flags
& vma
->vm_flags
))
1357 goto finish_or_fault
;
1360 pages
[i
] = virt_to_page(start
);
1366 start
= (start
+ PAGE_SIZE
) & PAGE_MASK
;
1372 return i
? : -EFAULT
;
1374 #endif /* !CONFIG_MMU */
1376 #if defined(CONFIG_FS_DAX) || defined (CONFIG_CMA)
1377 static bool check_dax_vmas(struct vm_area_struct
**vmas
, long nr_pages
)
1380 struct vm_area_struct
*vma_prev
= NULL
;
1382 for (i
= 0; i
< nr_pages
; i
++) {
1383 struct vm_area_struct
*vma
= vmas
[i
];
1385 if (vma
== vma_prev
)
1390 if (vma_is_fsdax(vma
))
1397 static struct page
*new_non_cma_page(struct page
*page
, unsigned long private)
1400 * We want to make sure we allocate the new page from the same node
1401 * as the source page.
1403 int nid
= page_to_nid(page
);
1405 * Trying to allocate a page for migration. Ignore allocation
1406 * failure warnings. We don't force __GFP_THISNODE here because
1407 * this node here is the node where we have CMA reservation and
1408 * in some case these nodes will have really less non movable
1409 * allocation memory.
1411 gfp_t gfp_mask
= GFP_USER
| __GFP_NOWARN
;
1413 if (PageHighMem(page
))
1414 gfp_mask
|= __GFP_HIGHMEM
;
1416 #ifdef CONFIG_HUGETLB_PAGE
1417 if (PageHuge(page
)) {
1418 struct hstate
*h
= page_hstate(page
);
1420 * We don't want to dequeue from the pool because pool pages will
1421 * mostly be from the CMA region.
1423 return alloc_migrate_huge_page(h
, gfp_mask
, nid
, NULL
);
1426 if (PageTransHuge(page
)) {
1429 * ignore allocation failure warnings
1431 gfp_t thp_gfpmask
= GFP_TRANSHUGE
| __GFP_NOWARN
;
1434 * Remove the movable mask so that we don't allocate from
1437 thp_gfpmask
&= ~__GFP_MOVABLE
;
1438 thp
= __alloc_pages_node(nid
, thp_gfpmask
, HPAGE_PMD_ORDER
);
1441 prep_transhuge_page(thp
);
1445 return __alloc_pages_node(nid
, gfp_mask
, 0);
1448 static long check_and_migrate_cma_pages(struct task_struct
*tsk
,
1449 struct mm_struct
*mm
,
1450 unsigned long start
,
1451 unsigned long nr_pages
,
1452 struct page
**pages
,
1453 struct vm_area_struct
**vmas
,
1454 unsigned int gup_flags
)
1458 bool drain_allow
= true;
1459 bool migrate_allow
= true;
1460 LIST_HEAD(cma_page_list
);
1463 for (i
= 0; i
< nr_pages
;) {
1465 struct page
*head
= compound_head(pages
[i
]);
1468 * gup may start from a tail page. Advance step by the left
1471 step
= compound_nr(head
) - (pages
[i
] - head
);
1473 * If we get a page from the CMA zone, since we are going to
1474 * be pinning these entries, we might as well move them out
1475 * of the CMA zone if possible.
1477 if (is_migrate_cma_page(head
)) {
1479 isolate_huge_page(head
, &cma_page_list
);
1481 if (!PageLRU(head
) && drain_allow
) {
1482 lru_add_drain_all();
1483 drain_allow
= false;
1486 if (!isolate_lru_page(head
)) {
1487 list_add_tail(&head
->lru
, &cma_page_list
);
1488 mod_node_page_state(page_pgdat(head
),
1490 page_is_file_cache(head
),
1491 hpage_nr_pages(head
));
1499 if (!list_empty(&cma_page_list
)) {
1501 * drop the above get_user_pages reference.
1503 for (i
= 0; i
< nr_pages
; i
++)
1506 if (migrate_pages(&cma_page_list
, new_non_cma_page
,
1507 NULL
, 0, MIGRATE_SYNC
, MR_CONTIG_RANGE
)) {
1509 * some of the pages failed migration. Do get_user_pages
1510 * without migration.
1512 migrate_allow
= false;
1514 if (!list_empty(&cma_page_list
))
1515 putback_movable_pages(&cma_page_list
);
1518 * We did migrate all the pages, Try to get the page references
1519 * again migrating any new CMA pages which we failed to isolate
1522 nr_pages
= __get_user_pages_locked(tsk
, mm
, start
, nr_pages
,
1526 if ((nr_pages
> 0) && migrate_allow
) {
1535 static long check_and_migrate_cma_pages(struct task_struct
*tsk
,
1536 struct mm_struct
*mm
,
1537 unsigned long start
,
1538 unsigned long nr_pages
,
1539 struct page
**pages
,
1540 struct vm_area_struct
**vmas
,
1541 unsigned int gup_flags
)
1545 #endif /* CONFIG_CMA */
1548 * __gup_longterm_locked() is a wrapper for __get_user_pages_locked which
1549 * allows us to process the FOLL_LONGTERM flag.
1551 static long __gup_longterm_locked(struct task_struct
*tsk
,
1552 struct mm_struct
*mm
,
1553 unsigned long start
,
1554 unsigned long nr_pages
,
1555 struct page
**pages
,
1556 struct vm_area_struct
**vmas
,
1557 unsigned int gup_flags
)
1559 struct vm_area_struct
**vmas_tmp
= vmas
;
1560 unsigned long flags
= 0;
1563 if (gup_flags
& FOLL_LONGTERM
) {
1568 vmas_tmp
= kcalloc(nr_pages
,
1569 sizeof(struct vm_area_struct
*),
1574 flags
= memalloc_nocma_save();
1577 rc
= __get_user_pages_locked(tsk
, mm
, start
, nr_pages
, pages
,
1578 vmas_tmp
, NULL
, gup_flags
);
1580 if (gup_flags
& FOLL_LONGTERM
) {
1581 memalloc_nocma_restore(flags
);
1585 if (check_dax_vmas(vmas_tmp
, rc
)) {
1586 for (i
= 0; i
< rc
; i
++)
1592 rc
= check_and_migrate_cma_pages(tsk
, mm
, start
, rc
, pages
,
1593 vmas_tmp
, gup_flags
);
1597 if (vmas_tmp
!= vmas
)
1601 #else /* !CONFIG_FS_DAX && !CONFIG_CMA */
1602 static __always_inline
long __gup_longterm_locked(struct task_struct
*tsk
,
1603 struct mm_struct
*mm
,
1604 unsigned long start
,
1605 unsigned long nr_pages
,
1606 struct page
**pages
,
1607 struct vm_area_struct
**vmas
,
1610 return __get_user_pages_locked(tsk
, mm
, start
, nr_pages
, pages
, vmas
,
1613 #endif /* CONFIG_FS_DAX || CONFIG_CMA */
1616 * This is the same as get_user_pages_remote(), just with a
1617 * less-flexible calling convention where we assume that the task
1618 * and mm being operated on are the current task's and don't allow
1619 * passing of a locked parameter. We also obviously don't pass
1620 * FOLL_REMOTE in here.
1622 long get_user_pages(unsigned long start
, unsigned long nr_pages
,
1623 unsigned int gup_flags
, struct page
**pages
,
1624 struct vm_area_struct
**vmas
)
1626 return __gup_longterm_locked(current
, current
->mm
, start
, nr_pages
,
1627 pages
, vmas
, gup_flags
| FOLL_TOUCH
);
1629 EXPORT_SYMBOL(get_user_pages
);
1632 * We can leverage the VM_FAULT_RETRY functionality in the page fault
1633 * paths better by using either get_user_pages_locked() or
1634 * get_user_pages_unlocked().
1636 * get_user_pages_locked() is suitable to replace the form:
1638 * down_read(&mm->mmap_sem);
1640 * get_user_pages(tsk, mm, ..., pages, NULL);
1641 * up_read(&mm->mmap_sem);
1646 * down_read(&mm->mmap_sem);
1648 * get_user_pages_locked(tsk, mm, ..., pages, &locked);
1650 * up_read(&mm->mmap_sem);
1652 long get_user_pages_locked(unsigned long start
, unsigned long nr_pages
,
1653 unsigned int gup_flags
, struct page
**pages
,
1657 * FIXME: Current FOLL_LONGTERM behavior is incompatible with
1658 * FAULT_FLAG_ALLOW_RETRY because of the FS DAX check requirement on
1659 * vmas. As there are no users of this flag in this call we simply
1660 * disallow this option for now.
1662 if (WARN_ON_ONCE(gup_flags
& FOLL_LONGTERM
))
1665 return __get_user_pages_locked(current
, current
->mm
, start
, nr_pages
,
1666 pages
, NULL
, locked
,
1667 gup_flags
| FOLL_TOUCH
);
1669 EXPORT_SYMBOL(get_user_pages_locked
);
1672 * get_user_pages_unlocked() is suitable to replace the form:
1674 * down_read(&mm->mmap_sem);
1675 * get_user_pages(tsk, mm, ..., pages, NULL);
1676 * up_read(&mm->mmap_sem);
1680 * get_user_pages_unlocked(tsk, mm, ..., pages);
1682 * It is functionally equivalent to get_user_pages_fast so
1683 * get_user_pages_fast should be used instead if specific gup_flags
1684 * (e.g. FOLL_FORCE) are not required.
1686 long get_user_pages_unlocked(unsigned long start
, unsigned long nr_pages
,
1687 struct page
**pages
, unsigned int gup_flags
)
1689 struct mm_struct
*mm
= current
->mm
;
1694 * FIXME: Current FOLL_LONGTERM behavior is incompatible with
1695 * FAULT_FLAG_ALLOW_RETRY because of the FS DAX check requirement on
1696 * vmas. As there are no users of this flag in this call we simply
1697 * disallow this option for now.
1699 if (WARN_ON_ONCE(gup_flags
& FOLL_LONGTERM
))
1702 down_read(&mm
->mmap_sem
);
1703 ret
= __get_user_pages_locked(current
, mm
, start
, nr_pages
, pages
, NULL
,
1704 &locked
, gup_flags
| FOLL_TOUCH
);
1706 up_read(&mm
->mmap_sem
);
1709 EXPORT_SYMBOL(get_user_pages_unlocked
);
1714 * get_user_pages_fast attempts to pin user pages by walking the page
1715 * tables directly and avoids taking locks. Thus the walker needs to be
1716 * protected from page table pages being freed from under it, and should
1717 * block any THP splits.
1719 * One way to achieve this is to have the walker disable interrupts, and
1720 * rely on IPIs from the TLB flushing code blocking before the page table
1721 * pages are freed. This is unsuitable for architectures that do not need
1722 * to broadcast an IPI when invalidating TLBs.
1724 * Another way to achieve this is to batch up page table containing pages
1725 * belonging to more than one mm_user, then rcu_sched a callback to free those
1726 * pages. Disabling interrupts will allow the fast_gup walker to both block
1727 * the rcu_sched callback, and an IPI that we broadcast for splitting THPs
1728 * (which is a relatively rare event). The code below adopts this strategy.
1730 * Before activating this code, please be aware that the following assumptions
1731 * are currently made:
1733 * *) Either HAVE_RCU_TABLE_FREE is enabled, and tlb_remove_table() is used to
1734 * free pages containing page tables or TLB flushing requires IPI broadcast.
1736 * *) ptes can be read atomically by the architecture.
1738 * *) access_ok is sufficient to validate userspace address ranges.
1740 * The last two assumptions can be relaxed by the addition of helper functions.
1742 * This code is based heavily on the PowerPC implementation by Nick Piggin.
1744 #ifdef CONFIG_HAVE_FAST_GUP
1745 #ifdef CONFIG_GUP_GET_PTE_LOW_HIGH
1747 * WARNING: only to be used in the get_user_pages_fast() implementation.
1749 * With get_user_pages_fast(), we walk down the pagetables without taking any
1750 * locks. For this we would like to load the pointers atomically, but sometimes
1751 * that is not possible (e.g. without expensive cmpxchg8b on x86_32 PAE). What
1752 * we do have is the guarantee that a PTE will only either go from not present
1753 * to present, or present to not present or both -- it will not switch to a
1754 * completely different present page without a TLB flush in between; something
1755 * that we are blocking by holding interrupts off.
1757 * Setting ptes from not present to present goes:
1759 * ptep->pte_high = h;
1761 * ptep->pte_low = l;
1763 * And present to not present goes:
1765 * ptep->pte_low = 0;
1767 * ptep->pte_high = 0;
1769 * We must ensure here that the load of pte_low sees 'l' IFF pte_high sees 'h'.
1770 * We load pte_high *after* loading pte_low, which ensures we don't see an older
1771 * value of pte_high. *Then* we recheck pte_low, which ensures that we haven't
1772 * picked up a changed pte high. We might have gotten rubbish values from
1773 * pte_low and pte_high, but we are guaranteed that pte_low will not have the
1774 * present bit set *unless* it is 'l'. Because get_user_pages_fast() only
1775 * operates on present ptes we're safe.
1777 static inline pte_t
gup_get_pte(pte_t
*ptep
)
1782 pte
.pte_low
= ptep
->pte_low
;
1784 pte
.pte_high
= ptep
->pte_high
;
1786 } while (unlikely(pte
.pte_low
!= ptep
->pte_low
));
1790 #else /* CONFIG_GUP_GET_PTE_LOW_HIGH */
1792 * We require that the PTE can be read atomically.
1794 static inline pte_t
gup_get_pte(pte_t
*ptep
)
1796 return READ_ONCE(*ptep
);
1798 #endif /* CONFIG_GUP_GET_PTE_LOW_HIGH */
1800 static void __maybe_unused
undo_dev_pagemap(int *nr
, int nr_start
,
1801 struct page
**pages
)
1803 while ((*nr
) - nr_start
) {
1804 struct page
*page
= pages
[--(*nr
)];
1806 ClearPageReferenced(page
);
1812 * Return the compund head page with ref appropriately incremented,
1813 * or NULL if that failed.
1815 static inline struct page
*try_get_compound_head(struct page
*page
, int refs
)
1817 struct page
*head
= compound_head(page
);
1818 if (WARN_ON_ONCE(page_ref_count(head
) < 0))
1820 if (unlikely(!page_cache_add_speculative(head
, refs
)))
1825 #ifdef CONFIG_ARCH_HAS_PTE_SPECIAL
1826 static int gup_pte_range(pmd_t pmd
, unsigned long addr
, unsigned long end
,
1827 unsigned int flags
, struct page
**pages
, int *nr
)
1829 struct dev_pagemap
*pgmap
= NULL
;
1830 int nr_start
= *nr
, ret
= 0;
1833 ptem
= ptep
= pte_offset_map(&pmd
, addr
);
1835 pte_t pte
= gup_get_pte(ptep
);
1836 struct page
*head
, *page
;
1839 * Similar to the PMD case below, NUMA hinting must take slow
1840 * path using the pte_protnone check.
1842 if (pte_protnone(pte
))
1845 if (!pte_access_permitted(pte
, flags
& FOLL_WRITE
))
1848 if (pte_devmap(pte
)) {
1849 if (unlikely(flags
& FOLL_LONGTERM
))
1852 pgmap
= get_dev_pagemap(pte_pfn(pte
), pgmap
);
1853 if (unlikely(!pgmap
)) {
1854 undo_dev_pagemap(nr
, nr_start
, pages
);
1857 } else if (pte_special(pte
))
1860 VM_BUG_ON(!pfn_valid(pte_pfn(pte
)));
1861 page
= pte_page(pte
);
1863 head
= try_get_compound_head(page
, 1);
1867 if (unlikely(pte_val(pte
) != pte_val(*ptep
))) {
1872 VM_BUG_ON_PAGE(compound_head(page
) != head
, page
);
1874 SetPageReferenced(page
);
1878 } while (ptep
++, addr
+= PAGE_SIZE
, addr
!= end
);
1884 put_dev_pagemap(pgmap
);
1891 * If we can't determine whether or not a pte is special, then fail immediately
1892 * for ptes. Note, we can still pin HugeTLB and THP as these are guaranteed not
1895 * For a futex to be placed on a THP tail page, get_futex_key requires a
1896 * __get_user_pages_fast implementation that can pin pages. Thus it's still
1897 * useful to have gup_huge_pmd even if we can't operate on ptes.
1899 static int gup_pte_range(pmd_t pmd
, unsigned long addr
, unsigned long end
,
1900 unsigned int flags
, struct page
**pages
, int *nr
)
1904 #endif /* CONFIG_ARCH_HAS_PTE_SPECIAL */
1906 #if defined(CONFIG_ARCH_HAS_PTE_DEVMAP) && defined(CONFIG_TRANSPARENT_HUGEPAGE)
1907 static int __gup_device_huge(unsigned long pfn
, unsigned long addr
,
1908 unsigned long end
, struct page
**pages
, int *nr
)
1911 struct dev_pagemap
*pgmap
= NULL
;
1914 struct page
*page
= pfn_to_page(pfn
);
1916 pgmap
= get_dev_pagemap(pfn
, pgmap
);
1917 if (unlikely(!pgmap
)) {
1918 undo_dev_pagemap(nr
, nr_start
, pages
);
1921 SetPageReferenced(page
);
1926 } while (addr
+= PAGE_SIZE
, addr
!= end
);
1929 put_dev_pagemap(pgmap
);
1933 static int __gup_device_huge_pmd(pmd_t orig
, pmd_t
*pmdp
, unsigned long addr
,
1934 unsigned long end
, struct page
**pages
, int *nr
)
1936 unsigned long fault_pfn
;
1939 fault_pfn
= pmd_pfn(orig
) + ((addr
& ~PMD_MASK
) >> PAGE_SHIFT
);
1940 if (!__gup_device_huge(fault_pfn
, addr
, end
, pages
, nr
))
1943 if (unlikely(pmd_val(orig
) != pmd_val(*pmdp
))) {
1944 undo_dev_pagemap(nr
, nr_start
, pages
);
1950 static int __gup_device_huge_pud(pud_t orig
, pud_t
*pudp
, unsigned long addr
,
1951 unsigned long end
, struct page
**pages
, int *nr
)
1953 unsigned long fault_pfn
;
1956 fault_pfn
= pud_pfn(orig
) + ((addr
& ~PUD_MASK
) >> PAGE_SHIFT
);
1957 if (!__gup_device_huge(fault_pfn
, addr
, end
, pages
, nr
))
1960 if (unlikely(pud_val(orig
) != pud_val(*pudp
))) {
1961 undo_dev_pagemap(nr
, nr_start
, pages
);
1967 static int __gup_device_huge_pmd(pmd_t orig
, pmd_t
*pmdp
, unsigned long addr
,
1968 unsigned long end
, struct page
**pages
, int *nr
)
1974 static int __gup_device_huge_pud(pud_t pud
, pud_t
*pudp
, unsigned long addr
,
1975 unsigned long end
, struct page
**pages
, int *nr
)
1982 #ifdef CONFIG_ARCH_HAS_HUGEPD
1983 static unsigned long hugepte_addr_end(unsigned long addr
, unsigned long end
,
1986 unsigned long __boundary
= (addr
+ sz
) & ~(sz
-1);
1987 return (__boundary
- 1 < end
- 1) ? __boundary
: end
;
1990 static int gup_hugepte(pte_t
*ptep
, unsigned long sz
, unsigned long addr
,
1991 unsigned long end
, unsigned int flags
,
1992 struct page
**pages
, int *nr
)
1994 unsigned long pte_end
;
1995 struct page
*head
, *page
;
1999 pte_end
= (addr
+ sz
) & ~(sz
-1);
2003 pte
= READ_ONCE(*ptep
);
2005 if (!pte_access_permitted(pte
, flags
& FOLL_WRITE
))
2008 /* hugepages are never "special" */
2009 VM_BUG_ON(!pfn_valid(pte_pfn(pte
)));
2012 head
= pte_page(pte
);
2014 page
= head
+ ((addr
& (sz
-1)) >> PAGE_SHIFT
);
2016 VM_BUG_ON(compound_head(page
) != head
);
2021 } while (addr
+= PAGE_SIZE
, addr
!= end
);
2023 head
= try_get_compound_head(head
, refs
);
2029 if (unlikely(pte_val(pte
) != pte_val(*ptep
))) {
2030 /* Could be optimized better */
2037 SetPageReferenced(head
);
2041 static int gup_huge_pd(hugepd_t hugepd
, unsigned long addr
,
2042 unsigned int pdshift
, unsigned long end
, unsigned int flags
,
2043 struct page
**pages
, int *nr
)
2046 unsigned long sz
= 1UL << hugepd_shift(hugepd
);
2049 ptep
= hugepte_offset(hugepd
, addr
, pdshift
);
2051 next
= hugepte_addr_end(addr
, end
, sz
);
2052 if (!gup_hugepte(ptep
, sz
, addr
, end
, flags
, pages
, nr
))
2054 } while (ptep
++, addr
= next
, addr
!= end
);
2059 static inline int gup_huge_pd(hugepd_t hugepd
, unsigned long addr
,
2060 unsigned int pdshift
, unsigned long end
, unsigned int flags
,
2061 struct page
**pages
, int *nr
)
2065 #endif /* CONFIG_ARCH_HAS_HUGEPD */
2067 static int gup_huge_pmd(pmd_t orig
, pmd_t
*pmdp
, unsigned long addr
,
2068 unsigned long end
, unsigned int flags
,
2069 struct page
**pages
, int *nr
)
2071 struct page
*head
, *page
;
2074 if (!pmd_access_permitted(orig
, flags
& FOLL_WRITE
))
2077 if (pmd_devmap(orig
)) {
2078 if (unlikely(flags
& FOLL_LONGTERM
))
2080 return __gup_device_huge_pmd(orig
, pmdp
, addr
, end
, pages
, nr
);
2084 page
= pmd_page(orig
) + ((addr
& ~PMD_MASK
) >> PAGE_SHIFT
);
2090 } while (addr
+= PAGE_SIZE
, addr
!= end
);
2092 head
= try_get_compound_head(pmd_page(orig
), refs
);
2098 if (unlikely(pmd_val(orig
) != pmd_val(*pmdp
))) {
2105 SetPageReferenced(head
);
2109 static int gup_huge_pud(pud_t orig
, pud_t
*pudp
, unsigned long addr
,
2110 unsigned long end
, unsigned int flags
, struct page
**pages
, int *nr
)
2112 struct page
*head
, *page
;
2115 if (!pud_access_permitted(orig
, flags
& FOLL_WRITE
))
2118 if (pud_devmap(orig
)) {
2119 if (unlikely(flags
& FOLL_LONGTERM
))
2121 return __gup_device_huge_pud(orig
, pudp
, addr
, end
, pages
, nr
);
2125 page
= pud_page(orig
) + ((addr
& ~PUD_MASK
) >> PAGE_SHIFT
);
2131 } while (addr
+= PAGE_SIZE
, addr
!= end
);
2133 head
= try_get_compound_head(pud_page(orig
), refs
);
2139 if (unlikely(pud_val(orig
) != pud_val(*pudp
))) {
2146 SetPageReferenced(head
);
2150 static int gup_huge_pgd(pgd_t orig
, pgd_t
*pgdp
, unsigned long addr
,
2151 unsigned long end
, unsigned int flags
,
2152 struct page
**pages
, int *nr
)
2155 struct page
*head
, *page
;
2157 if (!pgd_access_permitted(orig
, flags
& FOLL_WRITE
))
2160 BUILD_BUG_ON(pgd_devmap(orig
));
2162 page
= pgd_page(orig
) + ((addr
& ~PGDIR_MASK
) >> PAGE_SHIFT
);
2168 } while (addr
+= PAGE_SIZE
, addr
!= end
);
2170 head
= try_get_compound_head(pgd_page(orig
), refs
);
2176 if (unlikely(pgd_val(orig
) != pgd_val(*pgdp
))) {
2183 SetPageReferenced(head
);
2187 static int gup_pmd_range(pud_t pud
, unsigned long addr
, unsigned long end
,
2188 unsigned int flags
, struct page
**pages
, int *nr
)
2193 pmdp
= pmd_offset(&pud
, addr
);
2195 pmd_t pmd
= READ_ONCE(*pmdp
);
2197 next
= pmd_addr_end(addr
, end
);
2198 if (!pmd_present(pmd
))
2201 if (unlikely(pmd_trans_huge(pmd
) || pmd_huge(pmd
) ||
2204 * NUMA hinting faults need to be handled in the GUP
2205 * slowpath for accounting purposes and so that they
2206 * can be serialised against THP migration.
2208 if (pmd_protnone(pmd
))
2211 if (!gup_huge_pmd(pmd
, pmdp
, addr
, next
, flags
,
2215 } else if (unlikely(is_hugepd(__hugepd(pmd_val(pmd
))))) {
2217 * architecture have different format for hugetlbfs
2218 * pmd format and THP pmd format
2220 if (!gup_huge_pd(__hugepd(pmd_val(pmd
)), addr
,
2221 PMD_SHIFT
, next
, flags
, pages
, nr
))
2223 } else if (!gup_pte_range(pmd
, addr
, next
, flags
, pages
, nr
))
2225 } while (pmdp
++, addr
= next
, addr
!= end
);
2230 static int gup_pud_range(p4d_t p4d
, unsigned long addr
, unsigned long end
,
2231 unsigned int flags
, struct page
**pages
, int *nr
)
2236 pudp
= pud_offset(&p4d
, addr
);
2238 pud_t pud
= READ_ONCE(*pudp
);
2240 next
= pud_addr_end(addr
, end
);
2243 if (unlikely(pud_huge(pud
))) {
2244 if (!gup_huge_pud(pud
, pudp
, addr
, next
, flags
,
2247 } else if (unlikely(is_hugepd(__hugepd(pud_val(pud
))))) {
2248 if (!gup_huge_pd(__hugepd(pud_val(pud
)), addr
,
2249 PUD_SHIFT
, next
, flags
, pages
, nr
))
2251 } else if (!gup_pmd_range(pud
, addr
, next
, flags
, pages
, nr
))
2253 } while (pudp
++, addr
= next
, addr
!= end
);
2258 static int gup_p4d_range(pgd_t pgd
, unsigned long addr
, unsigned long end
,
2259 unsigned int flags
, struct page
**pages
, int *nr
)
2264 p4dp
= p4d_offset(&pgd
, addr
);
2266 p4d_t p4d
= READ_ONCE(*p4dp
);
2268 next
= p4d_addr_end(addr
, end
);
2271 BUILD_BUG_ON(p4d_huge(p4d
));
2272 if (unlikely(is_hugepd(__hugepd(p4d_val(p4d
))))) {
2273 if (!gup_huge_pd(__hugepd(p4d_val(p4d
)), addr
,
2274 P4D_SHIFT
, next
, flags
, pages
, nr
))
2276 } else if (!gup_pud_range(p4d
, addr
, next
, flags
, pages
, nr
))
2278 } while (p4dp
++, addr
= next
, addr
!= end
);
2283 static void gup_pgd_range(unsigned long addr
, unsigned long end
,
2284 unsigned int flags
, struct page
**pages
, int *nr
)
2289 pgdp
= pgd_offset(current
->mm
, addr
);
2291 pgd_t pgd
= READ_ONCE(*pgdp
);
2293 next
= pgd_addr_end(addr
, end
);
2296 if (unlikely(pgd_huge(pgd
))) {
2297 if (!gup_huge_pgd(pgd
, pgdp
, addr
, next
, flags
,
2300 } else if (unlikely(is_hugepd(__hugepd(pgd_val(pgd
))))) {
2301 if (!gup_huge_pd(__hugepd(pgd_val(pgd
)), addr
,
2302 PGDIR_SHIFT
, next
, flags
, pages
, nr
))
2304 } else if (!gup_p4d_range(pgd
, addr
, next
, flags
, pages
, nr
))
2306 } while (pgdp
++, addr
= next
, addr
!= end
);
2309 static inline void gup_pgd_range(unsigned long addr
, unsigned long end
,
2310 unsigned int flags
, struct page
**pages
, int *nr
)
2313 #endif /* CONFIG_HAVE_FAST_GUP */
2315 #ifndef gup_fast_permitted
2317 * Check if it's allowed to use __get_user_pages_fast() for the range, or
2318 * we need to fall back to the slow version:
2320 static bool gup_fast_permitted(unsigned long start
, unsigned long end
)
2327 * Like get_user_pages_fast() except it's IRQ-safe in that it won't fall back to
2329 * Note a difference with get_user_pages_fast: this always returns the
2330 * number of pages pinned, 0 if no pages were pinned.
2332 * If the architecture does not support this function, simply return with no
2335 * Careful, careful! COW breaking can go either way, so a non-write
2336 * access can get ambiguous page results. If you call this function without
2337 * 'write' set, you'd better be sure that you're ok with that ambiguity.
2339 int __get_user_pages_fast(unsigned long start
, int nr_pages
, int write
,
2340 struct page
**pages
)
2342 unsigned long len
, end
;
2343 unsigned long flags
;
2346 start
= untagged_addr(start
) & PAGE_MASK
;
2347 len
= (unsigned long) nr_pages
<< PAGE_SHIFT
;
2352 if (unlikely(!access_ok((void __user
*)start
, len
)))
2356 * Disable interrupts. We use the nested form as we can already have
2357 * interrupts disabled by get_futex_key.
2359 * With interrupts disabled, we block page table pages from being
2360 * freed from under us. See struct mmu_table_batch comments in
2361 * include/asm-generic/tlb.h for more details.
2363 * We do not adopt an rcu_read_lock(.) here as we also want to
2364 * block IPIs that come from THPs splitting.
2366 * NOTE! We allow read-only gup_fast() here, but you'd better be
2367 * careful about possible COW pages. You'll get _a_ COW page, but
2368 * not necessarily the one you intended to get depending on what
2369 * COW event happens after this. COW may break the page copy in a
2373 if (IS_ENABLED(CONFIG_HAVE_FAST_GUP
) &&
2374 gup_fast_permitted(start
, end
)) {
2375 local_irq_save(flags
);
2376 gup_pgd_range(start
, end
, write
? FOLL_WRITE
: 0, pages
, &nr
);
2377 local_irq_restore(flags
);
2382 EXPORT_SYMBOL_GPL(__get_user_pages_fast
);
2384 static int __gup_longterm_unlocked(unsigned long start
, int nr_pages
,
2385 unsigned int gup_flags
, struct page
**pages
)
2390 * FIXME: FOLL_LONGTERM does not work with
2391 * get_user_pages_unlocked() (see comments in that function)
2393 if (gup_flags
& FOLL_LONGTERM
) {
2394 down_read(¤t
->mm
->mmap_sem
);
2395 ret
= __gup_longterm_locked(current
, current
->mm
,
2397 pages
, NULL
, gup_flags
);
2398 up_read(¤t
->mm
->mmap_sem
);
2400 ret
= get_user_pages_unlocked(start
, nr_pages
,
2408 * get_user_pages_fast() - pin user pages in memory
2409 * @start: starting user address
2410 * @nr_pages: number of pages from start to pin
2411 * @gup_flags: flags modifying pin behaviour
2412 * @pages: array that receives pointers to the pages pinned.
2413 * Should be at least nr_pages long.
2415 * Attempt to pin user pages in memory without taking mm->mmap_sem.
2416 * If not successful, it will fall back to taking the lock and
2417 * calling get_user_pages().
2419 * Returns number of pages pinned. This may be fewer than the number
2420 * requested. If nr_pages is 0 or negative, returns 0. If no pages
2421 * were pinned, returns -errno.
2423 int get_user_pages_fast(unsigned long start
, int nr_pages
,
2424 unsigned int gup_flags
, struct page
**pages
)
2426 unsigned long addr
, len
, end
;
2427 int nr
= 0, ret
= 0;
2429 if (WARN_ON_ONCE(gup_flags
& ~(FOLL_WRITE
| FOLL_LONGTERM
|
2433 start
= untagged_addr(start
) & PAGE_MASK
;
2435 len
= (unsigned long) nr_pages
<< PAGE_SHIFT
;
2440 if (unlikely(!access_ok((void __user
*)start
, len
)))
2444 * The FAST_GUP case requires FOLL_WRITE even for pure reads,
2445 * because get_user_pages() may need to cause an early COW in
2446 * order to avoid confusing the normal COW routines. So only
2447 * targets that are already writable are safe to do by just
2448 * looking at the page tables.
2450 if (IS_ENABLED(CONFIG_HAVE_FAST_GUP
) &&
2451 gup_fast_permitted(start
, end
)) {
2452 local_irq_disable();
2453 gup_pgd_range(addr
, end
, gup_flags
| FOLL_WRITE
, pages
, &nr
);
2458 if (nr
< nr_pages
) {
2459 /* Try to get the remaining pages with get_user_pages */
2460 start
+= nr
<< PAGE_SHIFT
;
2463 ret
= __gup_longterm_unlocked(start
, nr_pages
- nr
,
2466 /* Have to be a bit careful with return values */
2477 EXPORT_SYMBOL_GPL(get_user_pages_fast
);