44 #include <linux/mman.h>
50 #include <linux/export.h>
58 #include <linux/elf.h>
62 #include <asm/pgalloc.h>
63 #include <asm/uaccess.h>
65 #include <asm/tlbflush.h>
66 #include <asm/pgtable.h>
70 #ifndef CONFIG_NEED_MULTIPLE_NODES
99 #ifdef CONFIG_COMPAT_BRK
105 static int __init disable_randmaps(
char *
s)
107 randomize_va_space = 0;
110 __setup(
"norandmaps", disable_randmaps);
118 static int __init init_zero_pfn(
void)
126 #if defined(SPLIT_RSS_COUNTING)
133 if (
current->rss_stat.count[i]) {
134 add_mm_counter(mm, i,
current->rss_stat.count[i]);
141 static void add_mm_counter_fast(
struct mm_struct *mm,
int member,
int val)
146 task->rss_stat.count[member] +=
val;
148 add_mm_counter(mm, member, val);
150 #define inc_mm_counter_fast(mm, member) add_mm_counter_fast(mm, member, 1)
151 #define dec_mm_counter_fast(mm, member) add_mm_counter_fast(mm, member, -1)
154 #define TASK_RSS_EVENTS_THRESH (64)
155 static void check_sync_rss_stat(
struct task_struct *task)
159 if (
unlikely(task->rss_stat.events++ > TASK_RSS_EVENTS_THRESH))
160 sync_mm_rss(task->
mm);
164 #define inc_mm_counter_fast(mm, member) inc_mm_counter(mm, member)
165 #define dec_mm_counter_fast(mm, member) dec_mm_counter(mm, member)
167 static void check_sync_rss_stat(
struct task_struct *task)
173 #ifdef HAVE_GENERIC_MMU_GATHER
175 static int tlb_next_batch(
struct mmu_gather *tlb)
193 tlb->
active->next = batch;
218 #ifdef CONFIG_HAVE_RCU_TABLE_FREE
231 #ifdef CONFIG_HAVE_RCU_TABLE_FREE
238 for (batch = &tlb->
local; batch; batch = batch->
next) {
260 for (batch = tlb->
local.next; batch; batch = next) {
286 if (batch->
nr == batch->
max) {
287 if (!tlb_next_batch(tlb))
293 return batch->
max - batch->
nr;
298 #ifdef CONFIG_HAVE_RCU_TABLE_FREE
304 static void tlb_remove_table_smp_sync(
void *
arg)
309 static void tlb_remove_table_one(
void *
table)
329 for (i = 0; i < batch->
nr; i++)
360 if (*batch ==
NULL) {
362 if (*batch ==
NULL) {
363 tlb_remove_table_one(table);
368 (*batch)->tables[(*batch)->nr++] =
table;
413 unsigned long addr,
unsigned long end,
414 unsigned long floor,
unsigned long ceiling)
424 if (pmd_none_or_clear_bad(pmd))
426 free_pte_range(tlb, pmd, addr);
427 }
while (pmd++, addr = next, addr != end);
437 if (end - 1 > ceiling - 1)
446 unsigned long addr,
unsigned long end,
447 unsigned long floor,
unsigned long ceiling)
457 if (pud_none_or_clear_bad(pud))
459 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
460 }
while (pud++, addr = next, addr != end);
470 if (end - 1 > ceiling - 1)
484 unsigned long addr,
unsigned long end,
485 unsigned long floor,
unsigned long ceiling)
527 if (end - 1 > ceiling - 1)
534 next = pgd_addr_end(addr, end);
535 if (pgd_none_or_clear_bad(pgd))
537 free_pud_range(tlb, pgd, addr, next, floor, ceiling);
538 }
while (pgd++, addr = next, addr != end);
542 unsigned long floor,
unsigned long ceiling)
555 if (is_vm_hugetlb_page(vma)) {
557 floor, next? next->
vm_start: ceiling);
563 && !is_vm_hugetlb_page(next)) {
570 floor, next? next->
vm_start: ceiling);
600 wait_split_huge_page = 0;
605 }
else if (
unlikely(pmd_trans_splitting(*pmd)))
606 wait_split_huge_page = 1;
610 if (wait_split_huge_page)
623 spin_lock(&
init_mm.page_table_lock);
629 spin_unlock(&
init_mm.page_table_lock);
635 static inline void init_rss_vec(
int *rss)
637 memset(rss, 0,
sizeof(
int) * NR_MM_COUNTERS);
640 static inline void add_mm_rss_vec(
struct mm_struct *mm,
int *rss)
648 add_mm_counter(mm, i, rss[i]);
658 static void print_bad_pte(
struct vm_area_struct *vma,
unsigned long addr,
666 static unsigned long resume;
667 static unsigned long nr_shown;
668 static unsigned long nr_unshown;
674 if (nr_shown == 60) {
681 "BUG: Bad page map: %lu messages suppressed\n",
691 index = linear_page_index(vma, addr);
694 "BUG: Bad page map in process %s pte:%08llx pmd:%08llx\n",
700 "addr:%p vm_flags:%08lx anon_vma:%p mapping:%p index:%lx\n",
706 print_symbol(
KERN_ALERT "vma->vm_ops->fault: %s\n",
707 (
unsigned long)vma->
vm_ops->fault);
709 print_symbol(
KERN_ALERT "vma->vm_file->f_op->mmap: %s\n",
710 (
unsigned long)vma->
vm_file->f_op->mmap);
717 return (flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
723 return pfn == zero_pfn;
728 static inline unsigned long my_zero_pfn(
unsigned long addr)
776 #ifdef __HAVE_ARCH_PTE_SPECIAL
777 # define HAVE_PTE_SPECIAL 1
779 # define HAVE_PTE_SPECIAL 0
784 unsigned long pfn =
pte_pfn(pte);
789 if (vma->
vm_flags & (VM_PFNMAP | VM_MIXEDMAP))
792 print_bad_pte(vma, addr, pte,
NULL);
817 print_bad_pte(vma, addr, pte,
NULL);
835 static inline unsigned long
838 unsigned long addr,
int *rss)
841 pte_t pte = *src_pte;
854 spin_lock(&mmlist_lock);
855 if (list_empty(&dst_mm->
mmlist))
858 spin_unlock(&mmlist_lock);
860 if (
likely(!non_swap_entry(entry)))
862 else if (is_migration_entry(entry)) {
870 if (is_write_migration_entry(entry) &&
871 is_cow_mapping(vm_flags)) {
876 make_migration_entry_read(&entry);
877 pte = swp_entry_to_pte(entry);
889 if (is_cow_mapping(vm_flags)) {
898 if (vm_flags & VM_SHARED)
919 unsigned long addr,
unsigned long end)
921 pte_t *orig_src_pte, *orig_dst_pte;
922 pte_t *src_pte, *dst_pte;
931 dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
935 src_ptl = pte_lockptr(src_mm, src_pmd);
937 orig_src_pte = src_pte;
938 orig_dst_pte = dst_pte;
946 if (progress >= 32) {
948 if (need_resched() ||
949 spin_needbreak(src_ptl) || spin_needbreak(dst_ptl))
956 entry.
val = copy_one_pte(dst_mm, src_mm, dst_pte, src_pte,
961 }
while (dst_pte++, src_pte++, addr +=
PAGE_SIZE, addr != end);
964 spin_unlock(src_ptl);
966 add_mm_rss_vec(dst_mm, rss);
967 pte_unmap_unlock(orig_dst_pte, dst_ptl);
982 unsigned long addr,
unsigned long end)
984 pmd_t *src_pmd, *dst_pmd;
987 dst_pmd =
pmd_alloc(dst_mm, dst_pud, addr);
993 if (pmd_trans_huge(*src_pmd)) {
997 dst_pmd, src_pmd, addr, vma);
1004 if (pmd_none_or_clear_bad(src_pmd))
1009 }
while (dst_pmd++, src_pmd++, addr = next, addr != end);
1015 unsigned long addr,
unsigned long end)
1017 pud_t *src_pud, *dst_pud;
1020 dst_pud =
pud_alloc(dst_mm, dst_pgd, addr);
1026 if (pud_none_or_clear_bad(src_pud))
1028 if (copy_pmd_range(dst_mm, src_mm, dst_pud, src_pud,
1031 }
while (dst_pud++, src_pud++, addr = next, addr != end);
1038 pgd_t *src_pgd, *dst_pgd;
1040 unsigned long addr = vma->
vm_start;
1041 unsigned long end = vma->
vm_end;
1042 unsigned long mmun_start;
1043 unsigned long mmun_end;
1053 if (!(vma->
vm_flags & (VM_HUGETLB | VM_NONLINEAR |
1054 VM_PFNMAP | VM_MIXEDMAP))) {
1059 if (is_vm_hugetlb_page(vma))
1078 is_cow = is_cow_mapping(vma->
vm_flags);
1082 mmu_notifier_invalidate_range_start(src_mm, mmun_start,
1089 next = pgd_addr_end(addr, end);
1090 if (pgd_none_or_clear_bad(src_pgd))
1092 if (
unlikely(copy_pud_range(dst_mm, src_mm, dst_pgd, src_pgd,
1093 vma, addr, next))) {
1097 }
while (dst_pgd++, src_pgd++, addr = next, addr != end);
1100 mmu_notifier_invalidate_range_end(src_mm, mmun_start, mmun_end);
1104 static unsigned long zap_pte_range(
struct mmu_gather *tlb,
1106 unsigned long addr,
unsigned long end,
1107 struct zap_details *details)
1110 int force_flush = 0;
1118 start_pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
1137 if (details->check_mapping &&
1138 details->check_mapping != page->
mapping)
1144 if (details->nonlinear_vma &&
1145 (page->
index < details->first_index ||
1146 page->
index > details->last_index))
1149 ptent = ptep_get_and_clear_full(mm, addr, pte,
1154 if (
unlikely(details) && details->nonlinear_vma
1155 && linear_page_index(details->nonlinear_vma,
1156 addr) != page->
index)
1165 likely(!VM_SequentialReadHint(vma)))
1170 if (
unlikely(page_mapcount(page) < 0))
1171 print_bad_pte(vma, addr, ptent, page);
1185 print_bad_pte(vma, addr, ptent,
NULL);
1189 if (!non_swap_entry(entry))
1191 else if (is_migration_entry(entry)) {
1202 print_bad_pte(vma, addr, ptent,
NULL);
1205 }
while (pte++, addr +=
PAGE_SIZE, addr != end);
1207 add_mm_rss_vec(mm, rss);
1209 pte_unmap_unlock(start_pte, ptl);
1219 #ifdef HAVE_GENERIC_MMU_GATHER
1231 static inline unsigned long zap_pmd_range(
struct mmu_gather *tlb,
1233 unsigned long addr,
unsigned long end,
1234 struct zap_details *details)
1242 if (pmd_trans_huge(*pmd)) {
1244 #ifdef CONFIG_DEBUG_VM
1246 pr_err(
"%s: mmap_sem is unlocked! addr=0x%lx end=0x%lx vma->vm_start=0x%lx vma->vm_end=0x%lx\n",
1247 __func__, addr, end,
1265 if (pmd_none_or_trans_huge_or_clear_bad(pmd))
1267 next = zap_pte_range(tlb, vma, pmd, addr, next, details);
1270 }
while (pmd++, addr = next, addr != end);
1275 static inline unsigned long zap_pud_range(
struct mmu_gather *tlb,
1277 unsigned long addr,
unsigned long end,
1278 struct zap_details *details)
1286 if (pud_none_or_clear_bad(pud))
1288 next = zap_pmd_range(tlb, vma, pud, addr, next, details);
1289 }
while (pud++, addr = next, addr != end);
1294 static void unmap_page_range(
struct mmu_gather *tlb,
1296 unsigned long addr,
unsigned long end,
1297 struct zap_details *details)
1302 if (details && !details->check_mapping && !details->nonlinear_vma)
1310 next = pgd_addr_end(addr, end);
1311 if (pgd_none_or_clear_bad(pgd))
1313 next = zap_pud_range(tlb, vma, pgd, addr, next, details);
1314 }
while (pgd++, addr = next, addr != end);
1320 static void unmap_single_vma(
struct mmu_gather *tlb,
1322 unsigned long end_addr,
1323 struct zap_details *details)
1325 unsigned long start =
max(vma->
vm_start, start_addr);
1328 if (start >= vma->
vm_end)
1331 if (end <= vma->vm_start)
1341 if (
unlikely(is_vm_hugetlb_page(vma))) {
1359 unmap_page_range(tlb, vma, start, end, details);
1383 unsigned long end_addr)
1387 mmu_notifier_invalidate_range_start(mm, start_addr, end_addr);
1389 unmap_single_vma(tlb, vma, start_addr, end_addr,
NULL);
1390 mmu_notifier_invalidate_range_end(mm, start_addr, end_addr);
1403 unsigned long size,
struct zap_details *details)
1407 unsigned long end = start +
size;
1411 update_hiwater_rss(mm);
1412 mmu_notifier_invalidate_range_start(mm, start, end);
1414 unmap_single_vma(&tlb, vma, start, end, details);
1415 mmu_notifier_invalidate_range_end(mm, start, end);
1429 unsigned long size,
struct zap_details *details)
1433 unsigned long end = address +
size;
1437 update_hiwater_rss(mm);
1438 mmu_notifier_invalidate_range_start(mm, address, end);
1439 unmap_single_vma(&tlb, vma, address, end, details);
1440 mmu_notifier_invalidate_range_end(mm, address, end);
1462 zap_page_range_single(vma, address, size,
NULL);
1491 if (!IS_ERR(page)) {
1492 BUG_ON(flags & FOLL_GET);
1505 BUG_ON(flags & FOLL_GET);
1516 BUG_ON(flags & FOLL_GET);
1520 if (pmd_trans_huge(*pmd)) {
1521 if (flags & FOLL_SPLIT) {
1523 goto split_fallthrough;
1526 if (
likely(pmd_trans_huge(*pmd))) {
1527 if (
unlikely(pmd_trans_splitting(*pmd))) {
1544 ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
1549 if ((flags & FOLL_WRITE) && !
pte_write(pte))
1554 if ((flags & FOLL_DUMP) ||
1560 if (flags & FOLL_GET)
1561 get_page_foll(page);
1562 if (flags & FOLL_TOUCH) {
1563 if ((flags & FOLL_WRITE) &&
1573 if ((flags & FOLL_MLOCK) && (vma->
vm_flags & VM_LOCKED)) {
1583 if (page->
mapping && trylock_page(page)) {
1596 pte_unmap_unlock(ptep, ptl);
1601 pte_unmap_unlock(ptep, ptl);
1605 pte_unmap_unlock(ptep, ptl);
1618 if ((flags & FOLL_DUMP) &&
1624 static inline int stack_guard_page(
struct vm_area_struct *vma,
unsigned long addr)
1626 return stack_guard_page_start(vma, addr) ||
1627 stack_guard_page_end(vma, addr+
PAGE_SIZE);
1680 unsigned long start,
int nr_pages,
unsigned int gup_flags,
1690 VM_BUG_ON(!!pages != !!(gup_flags & FOLL_GET));
1696 vm_flags = (gup_flags & FOLL_WRITE) ?
1697 (VM_WRITE | VM_MAYWRITE) : (VM_READ | VM_MAYREAD);
1698 vm_flags &= (gup_flags & FOLL_FORCE) ?
1699 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
1714 if (gup_flags & FOLL_WRITE)
1738 if (!(gup_flags & FOLL_DUMP) &&
1754 (vma->
vm_flags & (VM_IO | VM_PFNMAP)) ||
1758 if (is_vm_hugetlb_page(vma)) {
1760 &start, &nr_pages, i, gup_flags);
1766 unsigned int foll_flags = gup_flags;
1776 while (!(page =
follow_page(vma, start, foll_flags))) {
1778 unsigned int fault_flags = 0;
1781 if (foll_flags & FOLL_MLOCK) {
1782 if (stack_guard_page(vma, start))
1785 if (foll_flags & FOLL_WRITE)
1786 fault_flags |= FAULT_FLAG_WRITE;
1788 fault_flags |= FAULT_FLAG_ALLOW_RETRY;
1789 if (foll_flags & FOLL_NOWAIT)
1790 fault_flags |= (FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT);
1795 if (ret & VM_FAULT_ERROR) {
1796 if (ret & VM_FAULT_OOM)
1798 if (ret & (VM_FAULT_HWPOISON |
1799 VM_FAULT_HWPOISON_LARGE)) {
1802 else if (gup_flags & FOLL_HWPOISON)
1807 if (ret & VM_FAULT_SIGBUS)
1813 if (ret & VM_FAULT_MAJOR)
1819 if (ret & VM_FAULT_RETRY) {
1837 if ((ret & VM_FAULT_WRITE) &&
1839 foll_flags &= ~FOLL_WRITE;
1844 return i ? i : PTR_ERR(page);
1848 flush_anon_page(vma, page, start);
1857 }
while (nr_pages && start < vma->vm_end);
1891 unsigned long address,
unsigned int fault_flags)
1901 if (ret & VM_FAULT_ERROR) {
1902 if (ret & VM_FAULT_OOM)
1904 if (ret & (VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE))
1906 if (ret & VM_FAULT_SIGBUS)
1911 if (ret & VM_FAULT_MAJOR)
1971 unsigned long start,
int nr_pages,
int write,
int force,
1974 int flags = FOLL_TOUCH;
1979 flags |= FOLL_WRITE;
1981 flags |= FOLL_FORCE;
2002 #ifdef CONFIG_ELF_CORE
2003 struct page *get_dump_page(
unsigned long addr)
2009 FOLL_FORCE | FOLL_DUMP | FOLL_GET, &page, &vma,
2026 return pte_alloc_map_lock(mm, pmd, addr, ptl);
2039 static int insert_page(
struct vm_area_struct *vma,
unsigned long addr,
2052 pte = get_locked_pte(mm, addr, &ptl);
2066 pte_unmap_unlock(pte, ptl);
2069 pte_unmap_unlock(pte, ptl);
2104 if (addr < vma->vm_start || addr >= vma->
vm_end)
2106 if (!page_count(page))
2108 if (!(vma->
vm_flags & VM_MIXEDMAP)) {
2113 return insert_page(vma, addr, page, vma->
vm_page_prot);
2117 static int insert_pfn(
struct vm_area_struct *vma,
unsigned long addr,
2126 pte = get_locked_pte(mm, addr, &ptl);
2140 pte_unmap_unlock(pte, ptl);
2175 (VM_PFNMAP|VM_MIXEDMAP));
2179 if (addr < vma->vm_start || addr >= vma->
vm_end)
2184 ret = insert_pfn(vma, addr, pfn, pgprot);
2195 if (addr < vma->vm_start || addr >= vma->
vm_end)
2209 return insert_page(vma, addr, page, vma->
vm_page_prot);
2221 unsigned long addr,
unsigned long end,
2227 pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
2235 }
while (pte++, addr +=
PAGE_SIZE, addr != end);
2237 pte_unmap_unlock(pte - 1, ptl);
2241 static inline int remap_pmd_range(
struct mm_struct *mm,
pud_t *pud,
2242 unsigned long addr,
unsigned long end,
2255 if (remap_pte_range(mm, pmd, addr, next,
2256 pfn + (addr >> PAGE_SHIFT), prot))
2258 }
while (pmd++, addr = next, addr != end);
2262 static inline int remap_pud_range(
struct mm_struct *mm,
pgd_t *pgd,
2263 unsigned long addr,
unsigned long end,
2275 if (remap_pmd_range(mm, pud, addr, next,
2276 pfn + (addr >> PAGE_SHIFT), prot))
2278 }
while (pud++, addr = next, addr != end);
2319 if (is_cow_mapping(vma->
vm_flags)) {
2329 vma->
vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP;
2336 next = pgd_addr_end(addr, end);
2337 err = remap_pud_range(mm, pgd, addr, next,
2338 pfn + (addr >> PAGE_SHIFT), prot);
2341 }
while (pgd++, addr = next, addr != end);
2351 unsigned long addr,
unsigned long end,
2360 pte_alloc_kernel(pmd, addr) :
2361 pte_alloc_map_lock(mm, pmd, addr, &ptl);
2372 err =
fn(pte++, token, addr, data);
2375 }
while (addr +=
PAGE_SIZE, addr != end);
2380 pte_unmap_unlock(pte-1, ptl);
2385 unsigned long addr,
unsigned long end,
2386 pte_fn_t fn,
void *data)
2399 err = apply_to_pte_range(mm, pmd, addr, next, fn, data);
2402 }
while (pmd++, addr = next, addr != end);
2407 unsigned long addr,
unsigned long end,
2408 pte_fn_t fn,
void *data)
2419 err = apply_to_pmd_range(mm, pud, addr, next, fn, data);
2422 }
while (pud++, addr = next, addr != end);
2431 unsigned long size, pte_fn_t fn,
void *data)
2435 unsigned long end = addr +
size;
2441 next = pgd_addr_end(addr, end);
2442 err = apply_to_pud_range(mm, pgd, addr, next, fn, data);
2445 }
while (pgd++, addr = next, addr != end);
2460 static inline int pte_unmap_same(
struct mm_struct *mm,
pmd_t *pmd,
2464 #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
2465 if (
sizeof(
pte_t) >
sizeof(
unsigned long)) {
2468 same =
pte_same(*page_table, orig_pte);
2476 static inline void cow_user_page(
struct page *
dst,
struct page *
src,
unsigned long va,
struct vm_area_struct *vma)
2525 struct page *old_page, *new_page =
NULL;
2528 int page_mkwrite = 0;
2529 struct page *dirty_page =
NULL;
2530 unsigned long mmun_start = 0;
2531 unsigned long mmun_end = 0;
2542 if ((vma->
vm_flags & (VM_WRITE|VM_SHARED)) ==
2543 (VM_WRITE|VM_SHARED))
2552 if (PageAnon(old_page) && !PageKsm(old_page)) {
2553 if (!trylock_page(old_page)) {
2555 pte_unmap_unlock(page_table, ptl);
2556 lock_page(old_page);
2557 page_table = pte_offset_map_lock(mm, pmd,
address,
2559 if (!
pte_same(*page_table, orig_pte)) {
2577 (VM_WRITE|VM_SHARED))) {
2584 struct vm_fault vmf;
2589 vmf.pgoff = old_page->
index;
2590 vmf.flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE;
2591 vmf.page = old_page;
2602 pte_unmap_unlock(page_table, ptl);
2604 tmp = vma->
vm_ops->page_mkwrite(vma, &vmf);
2606 (VM_FAULT_ERROR | VM_FAULT_NOPAGE))) {
2608 goto unwritable_page;
2610 if (
unlikely(!(tmp & VM_FAULT_LOCKED))) {
2611 lock_page(old_page);
2615 goto unwritable_page;
2626 page_table = pte_offset_map_lock(mm, pmd,
address,
2628 if (!
pte_same(*page_table, orig_pte)) {
2635 dirty_page = old_page;
2636 get_page(dirty_page);
2644 pte_unmap_unlock(page_table, ptl);
2645 ret |= VM_FAULT_WRITE;
2658 if (!page_mkwrite) {
2659 wait_on_page_locked(dirty_page);
2677 balance_dirty_pages_ratelimited(mapping);
2689 pte_unmap_unlock(page_table, ptl);
2695 new_page = alloc_zeroed_user_highpage_movable(vma,
address);
2702 cow_user_page(new_page, old_page,
address, vma);
2704 __SetPageUptodate(new_page);
2711 mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end);
2716 page_table = pte_offset_map_lock(mm, pmd,
address, &ptl);
2719 if (!PageAnon(old_page)) {
2770 new_page = old_page;
2771 ret |= VM_FAULT_WRITE;
2778 pte_unmap_unlock(page_table, ptl);
2779 if (mmun_end > mmun_start)
2780 mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end);
2786 if ((ret & VM_FAULT_WRITE) && (vma->
vm_flags & VM_LOCKED)) {
2787 lock_page(old_page);
2804 return VM_FAULT_OOM;
2812 unsigned long start_addr,
unsigned long end_addr,
2813 struct zap_details *details)
2815 zap_page_range_single(vma, start_addr, end_addr - start_addr, details);
2818 static inline void unmap_mapping_range_tree(
struct rb_root *root,
2819 struct zap_details *details)
2824 vma_interval_tree_foreach(vma, root,
2825 details->first_index, details->last_index) {
2830 zba = details->first_index;
2833 zea = details->last_index;
2837 unmap_mapping_range_vma(vma,
2838 ((zba - vba) << PAGE_SHIFT) + vma->
vm_start,
2839 ((zea - vba + 1) << PAGE_SHIFT) + vma->
vm_start,
2844 static inline void unmap_mapping_range_list(
struct list_head *head,
2845 struct zap_details *details)
2856 details->nonlinear_vma = vma;
2857 unmap_mapping_range_vma(vma, vma->
vm_start, vma->
vm_end, details);
2876 loff_t
const holebegin, loff_t
const holelen,
int even_cows)
2878 struct zap_details details;
2880 pgoff_t hlen = (holelen + PAGE_SIZE - 1) >> PAGE_SHIFT;
2883 if (
sizeof(holelen) >
sizeof(hlen)) {
2885 (holebegin + holelen + PAGE_SIZE - 1) >> PAGE_SHIFT;
2891 details.nonlinear_vma =
NULL;
2892 details.first_index = hba;
2893 details.last_index = hba + hlen - 1;
2894 if (details.last_index < details.first_index)
2900 unmap_mapping_range_tree(&mapping->
i_mmap, &details);
2914 unsigned int flags,
pte_t orig_pte)
2917 struct page *
page, *swapcache =
NULL;
2925 if (!pte_unmap_same(mm, pmd, page_table, orig_pte))
2928 entry = pte_to_swp_entry(orig_pte);
2929 if (
unlikely(non_swap_entry(entry))) {
2930 if (is_migration_entry(entry)) {
2932 }
else if (is_hwpoison_entry(entry)) {
2933 ret = VM_FAULT_HWPOISON;
2935 print_bad_pte(vma, address, orig_pte,
NULL);
2936 ret = VM_FAULT_SIGBUS;
2950 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
2958 ret = VM_FAULT_MAJOR;
2961 }
else if (PageHWPoison(page)) {
2966 ret = VM_FAULT_HWPOISON;
2971 locked = lock_page_or_retry(page, mm, flags);
2975 ret |= VM_FAULT_RETRY;
2985 if (
unlikely(!PageSwapCache(page) || page_private(page) != entry.
val))
2988 if (ksm_might_need_to_copy(page, vma, address)) {
3008 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
3012 if (
unlikely(!PageUptodate(page))) {
3013 ret = VM_FAULT_SIGBUS;
3036 flags &= ~FAULT_FLAG_WRITE;
3037 ret |= VM_FAULT_WRITE;
3047 if (vm_swap_full() || (vma->
vm_flags & VM_LOCKED) || PageMlocked(page))
3063 if (flags & FAULT_FLAG_WRITE) {
3064 ret |= do_wp_page(mm, vma, address, page_table, pmd, ptl, pte);
3065 if (ret & VM_FAULT_ERROR)
3066 ret &= VM_FAULT_ERROR;
3073 pte_unmap_unlock(page_table, ptl);
3078 pte_unmap_unlock(page_table, ptl);
3095 static inline int check_stack_guard_page(
struct vm_area_struct *vma,
unsigned long address)
3107 if (prev && prev->
vm_end == address)
3112 if ((vma->
vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->
vm_end) {
3116 if (next && next->
vm_start == address + PAGE_SIZE)
3119 expand_upwards(vma, address + PAGE_SIZE);
3130 unsigned long address,
pte_t *page_table,
pmd_t *pmd,
3140 if (check_stack_guard_page(vma, address) < 0)
3141 return VM_FAULT_SIGBUS;
3144 if (!(flags & FAULT_FLAG_WRITE)) {
3147 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
3156 page = alloc_zeroed_user_highpage_movable(vma, address);
3159 __SetPageUptodate(page);
3168 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
3180 pte_unmap_unlock(page_table, ptl);
3189 return VM_FAULT_OOM;
3206 unsigned long address,
pmd_t *pmd,
3212 struct page *cow_page;
3215 struct page *dirty_page =
NULL;
3216 struct vm_fault vmf;
3218 int page_mkwrite = 0;
3224 if ((flags & FAULT_FLAG_WRITE) && !(vma->
vm_flags & VM_SHARED)) {
3227 return VM_FAULT_OOM;
3231 return VM_FAULT_OOM;
3235 return VM_FAULT_OOM;
3240 vmf.virtual_address = (
void __user *)(address & PAGE_MASK);
3245 ret = vma->
vm_ops->fault(vma, &vmf);
3246 if (
unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE |
3250 if (
unlikely(PageHWPoison(vmf.page))) {
3251 if (ret & VM_FAULT_LOCKED)
3253 ret = VM_FAULT_HWPOISON;
3261 if (
unlikely(!(ret & VM_FAULT_LOCKED)))
3262 lock_page(vmf.page);
3270 if (flags & FAULT_FLAG_WRITE) {
3271 if (!(vma->
vm_flags & VM_SHARED)) {
3275 __SetPageUptodate(page);
3282 if (vma->
vm_ops->page_mkwrite) {
3286 vmf.flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE;
3287 tmp = vma->
vm_ops->page_mkwrite(vma, &vmf);
3289 (VM_FAULT_ERROR | VM_FAULT_NOPAGE))) {
3291 goto unwritable_page;
3293 if (
unlikely(!(tmp & VM_FAULT_LOCKED))) {
3298 goto unwritable_page;
3308 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
3324 if (flags & FAULT_FLAG_WRITE)
3332 if (flags & FAULT_FLAG_WRITE) {
3334 get_page(dirty_page);
3350 pte_unmap_unlock(page_table, ptl);
3360 if ((dirtied || page_mkwrite) && mapping) {
3365 balance_dirty_pages_ratelimited(mapping);
3369 if (vma->
vm_file && !page_mkwrite)
3392 unsigned long address,
pte_t *page_table,
pmd_t *pmd,
3393 unsigned int flags,
pte_t orig_pte)
3399 return __do_fault(mm, vma, address, pmd, pgoff, flags, orig_pte);
3412 unsigned long address,
pte_t *page_table,
pmd_t *pmd,
3413 unsigned int flags,
pte_t orig_pte)
3417 flags |= FAULT_FLAG_NONLINEAR;
3419 if (!pte_unmap_same(mm, pmd, page_table, orig_pte))
3426 print_bad_pte(vma, address, orig_pte,
NULL);
3427 return VM_FAULT_SIGBUS;
3431 return __do_fault(mm, vma, address, pmd, pgoff, flags, orig_pte);
3459 return do_linear_fault(mm, vma, address,
3460 pte, pmd, flags, entry);
3462 return do_anonymous_page(mm, vma, address,
3466 return do_nonlinear_fault(mm, vma, address,
3467 pte, pmd, flags, entry);
3468 return do_swap_page(mm, vma, address,
3469 pte, pmd, flags, entry);
3472 ptl = pte_lockptr(mm, pmd);
3476 if (flags & FAULT_FLAG_WRITE) {
3478 return do_wp_page(mm, vma, address,
3479 pte, pmd, ptl, entry);
3492 if (flags & FAULT_FLAG_WRITE)
3496 pte_unmap_unlock(pte, ptl);
3504 unsigned long address,
unsigned int flags)
3519 if (
unlikely(is_vm_hugetlb_page(vma)))
3526 return VM_FAULT_OOM;
3529 return VM_FAULT_OOM;
3539 if (pmd_trans_huge(orig_pmd)) {
3540 if (flags & FAULT_FLAG_WRITE &&
3542 !pmd_trans_splitting(orig_pmd)) {
3564 return VM_FAULT_OOM;
3566 if (
unlikely(pmd_trans_huge(*pmd)))
3579 #ifndef __PAGETABLE_PUD_FOLDED
3602 #ifndef __PAGETABLE_PMD_FOLDED
3616 #ifndef __ARCH_HAS_4LEVEL_HACK
3645 write = (vma->
vm_flags & (VM_WRITE | VM_SHARED)) == VM_WRITE;
3653 return ret == len ? 0 : -
EFAULT;
3656 #if !defined(__HAVE_ARCH_GATE_AREA)
3658 #if defined(AT_SYSINFO_EHDR)
3661 static int __init gate_vma_init(
void)
3663 gate_vma.vm_mm =
NULL;
3666 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
3667 gate_vma.vm_page_prot =
__P101;
3676 #ifdef AT_SYSINFO_EHDR
3685 #ifdef AT_SYSINFO_EHDR
3694 static int __follow_pte(
struct mm_struct *mm,
unsigned long address,
3719 ptep = pte_offset_map_lock(mm, pmd, address, ptlp);
3727 pte_unmap_unlock(ptep, *ptlp);
3732 static inline int follow_pte(
struct mm_struct *mm,
unsigned long address,
3739 !(res = __follow_pte(mm, address, ptepp, ptlp)));
3760 if (!(vma->
vm_flags & (VM_IO | VM_PFNMAP)))
3763 ret = follow_pte(vma->
vm_mm, address, &ptep, &ptl);
3767 pte_unmap_unlock(ptep, ptl);
3772 #ifdef CONFIG_HAVE_IOREMAP_PROT
3774 unsigned long address,
unsigned int flags,
3781 if (!(vma->
vm_flags & (VM_IO | VM_PFNMAP)))
3784 if (follow_pte(vma->
vm_mm, address, &ptep, &ptl))
3788 if ((flags & FOLL_WRITE) && !
pte_write(pte))
3796 pte_unmap_unlock(ptep, ptl);
3801 int generic_access_phys(
struct vm_area_struct *vma,
unsigned long addr,
3805 unsigned long prot = 0;
3807 int offset = addr & (PAGE_SIZE-1);
3809 if (follow_phys(vma, addr, write, &prot, &phys_addr))
3828 unsigned long addr,
void *buf,
int len,
int write)
3831 void *old_buf =
buf;
3838 struct page *page =
NULL;
3841 write, 1, &page, &vma);
3847 #ifdef CONFIG_HAVE_IOREMAP_PROT
3852 ret = vma->
vm_ops->access(vma, addr, buf,
3860 offset = addr & (PAGE_SIZE-1);
3861 if (bytes > PAGE_SIZE-offset)
3862 bytes = PAGE_SIZE-
offset;
3867 maddr + offset, buf, bytes);
3871 buf, maddr + offset, bytes);
3882 return buf - old_buf;
3896 void *buf,
int len,
int write)
3898 return __access_remote_vm(
NULL, mm, addr, buf, len, write);
3907 void *buf,
int len,
int write)
3916 ret = __access_remote_vm(tsk, mm, addr, buf, len, write);
3951 printk(
"%s%s[%lx+%lx]", prefix, p,
3960 #ifdef CONFIG_PROVE_LOCKING
3961 void might_fault(
void)
3984 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
3985 static void clear_gigantic_page(
struct page *page,
3987 unsigned int pages_per_huge_page)
3990 struct page *
p =
page;
3993 for (i = 0; i < pages_per_huge_page;
3994 i++, p = mem_map_next(p, page, i)) {
3999 void clear_huge_page(
struct page *page,
4000 unsigned long addr,
unsigned int pages_per_huge_page)
4005 clear_gigantic_page(page, addr, pages_per_huge_page);
4010 for (i = 0; i < pages_per_huge_page; i++) {
4016 static void copy_user_gigantic_page(
struct page *dst,
struct page *src,
4019 unsigned int pages_per_huge_page)
4022 struct page *dst_base =
dst;
4023 struct page *src_base =
src;
4025 for (i = 0; i < pages_per_huge_page; ) {
4030 dst = mem_map_next(dst, dst_base, i);
4031 src = mem_map_next(src, src_base, i);
4035 void copy_user_huge_page(
struct page *dst,
struct page *src,
4037 unsigned int pages_per_huge_page)
4042 copy_user_gigantic_page(dst, src, addr, vma,
4043 pages_per_huge_page);
4048 for (i = 0; i < pages_per_huge_page; i++) {