Lines Matching refs:vma

401 void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *vma,  in free_pgtables()  argument
404 while (vma) { in free_pgtables()
405 struct vm_area_struct *next = vma->vm_next; in free_pgtables()
406 unsigned long addr = vma->vm_start; in free_pgtables()
412 unlink_anon_vmas(vma); in free_pgtables()
413 unlink_file_vma(vma); in free_pgtables()
415 if (is_vm_hugetlb_page(vma)) { in free_pgtables()
416 hugetlb_free_pgd_range(tlb, addr, vma->vm_end, in free_pgtables()
422 while (next && next->vm_start <= vma->vm_end + PMD_SIZE in free_pgtables()
424 vma = next; in free_pgtables()
425 next = vma->vm_next; in free_pgtables()
426 unlink_anon_vmas(vma); in free_pgtables()
427 unlink_file_vma(vma); in free_pgtables()
429 free_pgd_range(tlb, addr, vma->vm_end, in free_pgtables()
432 vma = next; in free_pgtables()
515 static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr, in print_bad_pte() argument
518 pgd_t *pgd = pgd_offset(vma->vm_mm, addr); in print_bad_pte()
547 mapping = vma->vm_file ? vma->vm_file->f_mapping : NULL; in print_bad_pte()
548 index = linear_page_index(vma, addr); in print_bad_pte()
556 (void *)addr, vma->vm_flags, vma->anon_vma, mapping, index); in print_bad_pte()
558 vma->vm_file, in print_bad_pte()
559 vma->vm_ops ? vma->vm_ops->fault : NULL, in print_bad_pte()
560 vma->vm_file ? vma->vm_file->f_op->mmap : NULL, in print_bad_pte()
608 struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, in vm_normal_page() argument
616 if (vma->vm_ops && vma->vm_ops->find_special_page) in vm_normal_page()
617 return vma->vm_ops->find_special_page(vma, addr); in vm_normal_page()
618 if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP)) in vm_normal_page()
625 print_bad_pte(vma, addr, pte, NULL); in vm_normal_page()
631 if (unlikely(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP))) { in vm_normal_page()
632 if (vma->vm_flags & VM_MIXEDMAP) { in vm_normal_page()
638 off = (addr - vma->vm_start) >> PAGE_SHIFT; in vm_normal_page()
639 if (pfn == vma->vm_pgoff + off) in vm_normal_page()
641 if (!is_cow_mapping(vma->vm_flags)) in vm_normal_page()
651 print_bad_pte(vma, addr, pte, NULL); in vm_normal_page()
664 struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr, in vm_normal_page_pmd() argument
674 if (unlikely(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP))) { in vm_normal_page_pmd()
675 if (vma->vm_flags & VM_MIXEDMAP) { in vm_normal_page_pmd()
681 off = (addr - vma->vm_start) >> PAGE_SHIFT; in vm_normal_page_pmd()
682 if (pfn == vma->vm_pgoff + off) in vm_normal_page_pmd()
684 if (!is_cow_mapping(vma->vm_flags)) in vm_normal_page_pmd()
705 static void restore_exclusive_pte(struct vm_area_struct *vma, in restore_exclusive_pte() argument
712 pte = pte_mkold(mk_pte(page, READ_ONCE(vma->vm_page_prot))); in restore_exclusive_pte()
720 pte = maybe_mkwrite(pte_mkdirty(pte), vma); in restore_exclusive_pte()
722 set_pte_at(vma->vm_mm, address, ptep, pte); in restore_exclusive_pte()
729 page_add_anon_rmap(page, vma, address, false); in restore_exclusive_pte()
737 if (vma->vm_flags & VM_LOCKED) in restore_exclusive_pte()
744 update_mmu_cache(vma, address, ptep); in restore_exclusive_pte()
752 try_restore_exclusive_pte(pte_t *src_pte, struct vm_area_struct *vma, in try_restore_exclusive_pte() argument
759 restore_exclusive_pte(vma, page, addr, src_pte); in try_restore_exclusive_pte()
987 page_copy_prealloc(struct mm_struct *src_mm, struct vm_area_struct *vma, in page_copy_prealloc() argument
992 new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, addr); in page_copy_prealloc()
1308 struct vm_area_struct *vma, pmd_t *pmd, in zap_pte_range() argument
1338 page = vm_normal_page(vma, addr, ptent); in zap_pte_range()
1353 likely(!(vma->vm_flags & VM_SEQ_READ))) in zap_pte_range()
1359 print_bad_pte(vma, addr, ptent, page); in zap_pte_range()
1398 print_bad_pte(vma, addr, ptent, NULL); in zap_pte_range()
1430 struct vm_area_struct *vma, pud_t *pud, in zap_pmd_range() argument
1442 __split_huge_pmd(vma, pmd, addr, false, NULL); in zap_pmd_range()
1443 else if (zap_huge_pmd(tlb, vma, pmd, addr)) in zap_pmd_range()
1467 next = zap_pte_range(tlb, vma, pmd, addr, next, details); in zap_pmd_range()
1476 struct vm_area_struct *vma, p4d_t *p4d, in zap_pud_range() argument
1489 split_huge_pud(vma, pud, addr); in zap_pud_range()
1490 } else if (zap_huge_pud(tlb, vma, pud, addr)) in zap_pud_range()
1496 next = zap_pmd_range(tlb, vma, pud, addr, next, details); in zap_pud_range()
1505 struct vm_area_struct *vma, pgd_t *pgd, in zap_p4d_range() argument
1517 next = zap_pud_range(tlb, vma, p4d, addr, next, details); in zap_p4d_range()
1524 struct vm_area_struct *vma, in unmap_page_range() argument
1532 tlb_start_vma(tlb, vma); in unmap_page_range()
1533 pgd = pgd_offset(vma->vm_mm, addr); in unmap_page_range()
1538 next = zap_p4d_range(tlb, vma, pgd, addr, next, details); in unmap_page_range()
1540 tlb_end_vma(tlb, vma); in unmap_page_range()
1545 struct vm_area_struct *vma, unsigned long start_addr, in unmap_single_vma() argument
1549 unsigned long start = max(vma->vm_start, start_addr); in unmap_single_vma()
1552 if (start >= vma->vm_end) in unmap_single_vma()
1554 end = min(vma->vm_end, end_addr); in unmap_single_vma()
1555 if (end <= vma->vm_start) in unmap_single_vma()
1558 if (vma->vm_file) in unmap_single_vma()
1559 uprobe_munmap(vma, start, end); in unmap_single_vma()
1561 if (unlikely(vma->vm_flags & VM_PFNMAP)) in unmap_single_vma()
1562 untrack_pfn(vma, 0, 0); in unmap_single_vma()
1565 if (unlikely(is_vm_hugetlb_page(vma))) { in unmap_single_vma()
1577 if (vma->vm_file) { in unmap_single_vma()
1578 i_mmap_lock_write(vma->vm_file->f_mapping); in unmap_single_vma()
1579 __unmap_hugepage_range_final(tlb, vma, start, end, NULL); in unmap_single_vma()
1580 i_mmap_unlock_write(vma->vm_file->f_mapping); in unmap_single_vma()
1583 unmap_page_range(tlb, vma, start, end, details); in unmap_single_vma()
1606 struct vm_area_struct *vma, unsigned long start_addr, in unmap_vmas() argument
1611 mmu_notifier_range_init(&range, MMU_NOTIFY_UNMAP, 0, vma, vma->vm_mm, in unmap_vmas()
1614 for ( ; vma && vma->vm_start < end_addr; vma = vma->vm_next) in unmap_vmas()
1615 unmap_single_vma(tlb, vma, start_addr, end_addr, NULL); in unmap_vmas()
1627 void zap_page_range(struct vm_area_struct *vma, unsigned long start, in zap_page_range() argument
1634 mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->vm_mm, in zap_page_range()
1636 tlb_gather_mmu(&tlb, vma->vm_mm); in zap_page_range()
1637 update_hiwater_rss(vma->vm_mm); in zap_page_range()
1639 for ( ; vma && vma->vm_start < range.end; vma = vma->vm_next) in zap_page_range()
1640 unmap_single_vma(&tlb, vma, start, range.end, NULL); in zap_page_range()
1654 static void zap_page_range_single(struct vm_area_struct *vma, unsigned long address, in zap_page_range_single() argument
1661 mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->vm_mm, in zap_page_range_single()
1663 tlb_gather_mmu(&tlb, vma->vm_mm); in zap_page_range_single()
1664 update_hiwater_rss(vma->vm_mm); in zap_page_range_single()
1666 unmap_single_vma(&tlb, vma, address, range.end, details); in zap_page_range_single()
1682 void zap_vma_ptes(struct vm_area_struct *vma, unsigned long address, in zap_vma_ptes() argument
1685 if (address < vma->vm_start || address + size > vma->vm_end || in zap_vma_ptes()
1686 !(vma->vm_flags & VM_PFNMAP)) in zap_vma_ptes()
1689 zap_page_range_single(vma, address, size, NULL); in zap_vma_ptes()
1753 static int insert_page(struct vm_area_struct *vma, unsigned long addr, in insert_page() argument
1756 struct mm_struct *mm = vma->vm_mm; in insert_page()
1791 static int insert_pages(struct vm_area_struct *vma, unsigned long addr, in insert_pages() argument
1797 struct mm_struct *const mm = vma->vm_mm; in insert_pages()
1861 int vm_insert_pages(struct vm_area_struct *vma, unsigned long addr, in vm_insert_pages() argument
1867 if (addr < vma->vm_start || end_addr >= vma->vm_end) in vm_insert_pages()
1869 if (!(vma->vm_flags & VM_MIXEDMAP)) { in vm_insert_pages()
1870 BUG_ON(mmap_read_trylock(vma->vm_mm)); in vm_insert_pages()
1871 BUG_ON(vma->vm_flags & VM_PFNMAP); in vm_insert_pages()
1872 vma->vm_flags |= VM_MIXEDMAP; in vm_insert_pages()
1875 return insert_pages(vma, addr, pages, num, vma->vm_page_prot); in vm_insert_pages()
1881 err = vm_insert_page(vma, addr + (PAGE_SIZE * idx), pages[idx]); in vm_insert_pages()
1920 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, in vm_insert_page() argument
1923 if (addr < vma->vm_start || addr >= vma->vm_end) in vm_insert_page()
1927 if (!(vma->vm_flags & VM_MIXEDMAP)) { in vm_insert_page()
1928 BUG_ON(mmap_read_trylock(vma->vm_mm)); in vm_insert_page()
1929 BUG_ON(vma->vm_flags & VM_PFNMAP); in vm_insert_page()
1930 vma->vm_flags |= VM_MIXEDMAP; in vm_insert_page()
1932 return insert_page(vma, addr, page, vma->vm_page_prot); in vm_insert_page()
1947 static int __vm_map_pages(struct vm_area_struct *vma, struct page **pages, in __vm_map_pages() argument
1950 unsigned long count = vma_pages(vma); in __vm_map_pages()
1951 unsigned long uaddr = vma->vm_start; in __vm_map_pages()
1963 ret = vm_insert_page(vma, uaddr, pages[offset + i]); in __vm_map_pages()
1990 int vm_map_pages(struct vm_area_struct *vma, struct page **pages, in vm_map_pages() argument
1993 return __vm_map_pages(vma, pages, num, vma->vm_pgoff); in vm_map_pages()
2010 int vm_map_pages_zero(struct vm_area_struct *vma, struct page **pages, in vm_map_pages_zero() argument
2013 return __vm_map_pages(vma, pages, num, 0); in vm_map_pages_zero()
2017 static vm_fault_t insert_pfn(struct vm_area_struct *vma, unsigned long addr, in insert_pfn() argument
2020 struct mm_struct *mm = vma->vm_mm; in insert_pfn()
2044 entry = maybe_mkwrite(pte_mkdirty(entry), vma); in insert_pfn()
2045 if (ptep_set_access_flags(vma, addr, pte, entry, 1)) in insert_pfn()
2046 update_mmu_cache(vma, addr, pte); in insert_pfn()
2059 entry = maybe_mkwrite(pte_mkdirty(entry), vma); in insert_pfn()
2063 update_mmu_cache(vma, addr, pte); /* XXX: why not for insert_page? */ in insert_pfn()
2091 vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr, in vmf_insert_pfn_prot() argument
2100 BUG_ON(!(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP))); in vmf_insert_pfn_prot()
2101 BUG_ON((vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) == in vmf_insert_pfn_prot()
2103 BUG_ON((vma->vm_flags & VM_PFNMAP) && is_cow_mapping(vma->vm_flags)); in vmf_insert_pfn_prot()
2104 BUG_ON((vma->vm_flags & VM_MIXEDMAP) && pfn_valid(pfn)); in vmf_insert_pfn_prot()
2106 if (addr < vma->vm_start || addr >= vma->vm_end) in vmf_insert_pfn_prot()
2112 track_pfn_insert(vma, &pgprot, __pfn_to_pfn_t(pfn, PFN_DEV)); in vmf_insert_pfn_prot()
2114 return insert_pfn(vma, addr, __pfn_to_pfn_t(pfn, PFN_DEV), pgprot, in vmf_insert_pfn_prot()
2139 vm_fault_t vmf_insert_pfn(struct vm_area_struct *vma, unsigned long addr, in vmf_insert_pfn() argument
2142 return vmf_insert_pfn_prot(vma, addr, pfn, vma->vm_page_prot); in vmf_insert_pfn()
2146 static bool vm_mixed_ok(struct vm_area_struct *vma, pfn_t pfn) in vm_mixed_ok() argument
2149 if (vma->vm_flags & VM_MIXEDMAP) in vm_mixed_ok()
2160 static vm_fault_t __vm_insert_mixed(struct vm_area_struct *vma, in __vm_insert_mixed() argument
2166 BUG_ON(!vm_mixed_ok(vma, pfn)); in __vm_insert_mixed()
2168 if (addr < vma->vm_start || addr >= vma->vm_end) in __vm_insert_mixed()
2171 track_pfn_insert(vma, &pgprot, pfn); in __vm_insert_mixed()
2193 err = insert_page(vma, addr, page, pgprot); in __vm_insert_mixed()
2195 return insert_pfn(vma, addr, pfn, pgprot, mkwrite); in __vm_insert_mixed()
2232 vm_fault_t vmf_insert_mixed_prot(struct vm_area_struct *vma, unsigned long addr, in vmf_insert_mixed_prot() argument
2235 return __vm_insert_mixed(vma, addr, pfn, pgprot, false); in vmf_insert_mixed_prot()
2239 vm_fault_t vmf_insert_mixed(struct vm_area_struct *vma, unsigned long addr, in vmf_insert_mixed() argument
2242 return __vm_insert_mixed(vma, addr, pfn, vma->vm_page_prot, false); in vmf_insert_mixed()
2251 vm_fault_t vmf_insert_mixed_mkwrite(struct vm_area_struct *vma, in vmf_insert_mixed_mkwrite() argument
2254 return __vm_insert_mixed(vma, addr, pfn, vma->vm_page_prot, true); in vmf_insert_mixed_mkwrite()
2360 int remap_pfn_range_notrack(struct vm_area_struct *vma, unsigned long addr, in remap_pfn_range_notrack() argument
2366 struct mm_struct *mm = vma->vm_mm; in remap_pfn_range_notrack()
2390 if (is_cow_mapping(vma->vm_flags)) { in remap_pfn_range_notrack()
2391 if (addr != vma->vm_start || end != vma->vm_end) in remap_pfn_range_notrack()
2393 vma->vm_pgoff = pfn; in remap_pfn_range_notrack()
2396 vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; in remap_pfn_range_notrack()
2401 flush_cache_range(vma, addr, end); in remap_pfn_range_notrack()
2425 int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr, in remap_pfn_range() argument
2430 err = track_pfn_remap(vma, &prot, pfn, addr, PAGE_ALIGN(size)); in remap_pfn_range()
2434 err = remap_pfn_range_notrack(vma, addr, pfn, size, prot); in remap_pfn_range()
2436 untrack_pfn(vma, pfn, PAGE_ALIGN(size)); in remap_pfn_range()
2456 int vm_iomap_memory(struct vm_area_struct *vma, phys_addr_t start, unsigned long len) in vm_iomap_memory() argument
2475 if (vma->vm_pgoff > pages) in vm_iomap_memory()
2477 pfn += vma->vm_pgoff; in vm_iomap_memory()
2478 pages -= vma->vm_pgoff; in vm_iomap_memory()
2481 vm_len = vma->vm_end - vma->vm_start; in vm_iomap_memory()
2486 return io_remap_pfn_range(vma, vma->vm_start, pfn, vm_len, vma->vm_page_prot); in vm_iomap_memory()
2718 spinlock_t *ptl = pte_lockptr(vmf->vma->vm_mm, vmf->pmd); in pte_unmap_same()
2736 struct vm_area_struct *vma = vmf->vma; in cow_user_page() local
2737 struct mm_struct *mm = vma->vm_mm; in cow_user_page()
2741 copy_user_highpage(dst, src, addr, vma); in cow_user_page()
2768 update_mmu_tlb(vma, addr, vmf->pte); in cow_user_page()
2774 if (ptep_set_access_flags(vma, addr, vmf->pte, entry, 0)) in cow_user_page()
2775 update_mmu_cache(vma, addr, vmf->pte); in cow_user_page()
2793 update_mmu_tlb(vma, addr, vmf->pte); in cow_user_page()
2824 static gfp_t __get_fault_gfp_mask(struct vm_area_struct *vma) in __get_fault_gfp_mask() argument
2826 struct file *vm_file = vma->vm_file; in __get_fault_gfp_mask()
2852 if (vmf->vma->vm_file && in do_page_mkwrite()
2853 IS_SWAPFILE(vmf->vma->vm_file->f_mapping->host)) in do_page_mkwrite()
2856 ret = vmf->vma->vm_ops->page_mkwrite(vmf); in do_page_mkwrite()
2880 struct vm_area_struct *vma = vmf->vma; in fault_dirty_shared_page() local
2884 bool page_mkwrite = vma->vm_ops && vma->vm_ops->page_mkwrite; in fault_dirty_shared_page()
2898 file_update_time(vma->vm_file); in fault_dirty_shared_page()
2934 struct vm_area_struct *vma = vmf->vma; in wp_page_reuse() local
2945 flush_cache_page(vma, vmf->address, pte_pfn(vmf->orig_pte)); in wp_page_reuse()
2947 entry = maybe_mkwrite(pte_mkdirty(entry), vma); in wp_page_reuse()
2948 if (ptep_set_access_flags(vma, vmf->address, vmf->pte, entry, 1)) in wp_page_reuse()
2949 update_mmu_cache(vma, vmf->address, vmf->pte); in wp_page_reuse()
2972 struct vm_area_struct *vma = vmf->vma; in wp_page_copy() local
2973 struct mm_struct *mm = vma->vm_mm; in wp_page_copy()
2980 if (unlikely(anon_vma_prepare(vma))) in wp_page_copy()
2984 new_page = alloc_zeroed_user_highpage_movable(vma, in wp_page_copy()
2989 new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, in wp_page_copy()
3014 mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, mm, in wp_page_copy()
3033 flush_cache_page(vma, vmf->address, pte_pfn(vmf->orig_pte)); in wp_page_copy()
3034 entry = mk_pte(new_page, vma->vm_page_prot); in wp_page_copy()
3036 entry = maybe_mkwrite(pte_mkdirty(entry), vma); in wp_page_copy()
3045 ptep_clear_flush_notify(vma, vmf->address, vmf->pte); in wp_page_copy()
3046 page_add_new_anon_rmap(new_page, vma, vmf->address, false); in wp_page_copy()
3047 lru_cache_add_inactive_or_unevictable(new_page, vma); in wp_page_copy()
3054 update_mmu_cache(vma, vmf->address, vmf->pte); in wp_page_copy()
3085 update_mmu_tlb(vma, vmf->address, vmf->pte); in wp_page_copy()
3102 if (page_copied && (vma->vm_flags & VM_LOCKED)) { in wp_page_copy()
3139 WARN_ON_ONCE(!(vmf->vma->vm_flags & VM_SHARED)); in finish_mkwrite_fault()
3140 vmf->pte = pte_offset_map_lock(vmf->vma->vm_mm, vmf->pmd, vmf->address, in finish_mkwrite_fault()
3147 update_mmu_tlb(vmf->vma, vmf->address, vmf->pte); in finish_mkwrite_fault()
3161 struct vm_area_struct *vma = vmf->vma; in wp_pfn_shared() local
3163 if (vma->vm_ops && vma->vm_ops->pfn_mkwrite) { in wp_pfn_shared()
3168 ret = vma->vm_ops->pfn_mkwrite(vmf); in wp_pfn_shared()
3180 struct vm_area_struct *vma = vmf->vma; in wp_page_shared() local
3185 if (vma->vm_ops && vma->vm_ops->page_mkwrite) { in wp_page_shared()
3232 struct vm_area_struct *vma = vmf->vma; in do_wp_page() local
3234 if (userfaultfd_pte_wp(vma, *vmf->pte)) { in do_wp_page()
3243 if (unlikely(userfaultfd_wp(vmf->vma) && in do_wp_page()
3244 mm_tlb_flush_pending(vmf->vma->vm_mm))) in do_wp_page()
3245 flush_tlb_page(vmf->vma, vmf->address); in do_wp_page()
3247 vmf->page = vm_normal_page(vma, vmf->address, vmf->orig_pte); in do_wp_page()
3256 if ((vma->vm_flags & (VM_WRITE|VM_SHARED)) == in do_wp_page()
3288 } else if (unlikely((vma->vm_flags & (VM_WRITE|VM_SHARED)) == in do_wp_page()
3302 static void unmap_mapping_range_vma(struct vm_area_struct *vma, in unmap_mapping_range_vma() argument
3306 zap_page_range_single(vma, start_addr, end_addr - start_addr, details); in unmap_mapping_range_vma()
3314 struct vm_area_struct *vma; in unmap_mapping_range_tree() local
3317 vma_interval_tree_foreach(vma, root, first_index, last_index) { in unmap_mapping_range_tree()
3318 vba = vma->vm_pgoff; in unmap_mapping_range_tree()
3319 vea = vba + vma_pages(vma) - 1; in unmap_mapping_range_tree()
3327 unmap_mapping_range_vma(vma, in unmap_mapping_range_tree()
3328 ((zba - vba) << PAGE_SHIFT) + vma->vm_start, in unmap_mapping_range_tree()
3329 ((zea - vba + 1) << PAGE_SHIFT) + vma->vm_start, in unmap_mapping_range_tree()
3440 struct vm_area_struct *vma = vmf->vma; in remove_device_exclusive_entry() local
3443 if (!lock_page_or_retry(page, vma->vm_mm, vmf->flags)) in remove_device_exclusive_entry()
3445 mmu_notifier_range_init_owner(&range, MMU_NOTIFY_EXCLUSIVE, 0, vma, in remove_device_exclusive_entry()
3446 vma->vm_mm, vmf->address & PAGE_MASK, in remove_device_exclusive_entry()
3450 vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, in remove_device_exclusive_entry()
3453 restore_exclusive_pte(vma, page, vmf->address, vmf->pte); in remove_device_exclusive_entry()
3472 struct vm_area_struct *vma = vmf->vma; in do_swap_page() local
3488 migration_entry_wait(vma->vm_mm, vmf->pmd, in do_swap_page()
3499 print_bad_pte(vma, vmf->address, vmf->orig_pte, NULL); in do_swap_page()
3511 page = lookup_swap_cache(entry, vma, vmf->address); in do_swap_page()
3518 page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, in do_swap_page()
3525 vma->vm_mm, GFP_KERNEL, entry)) { in do_swap_page()
3554 vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, in do_swap_page()
3565 count_memcg_event_mm(vma->vm_mm, PGMAJFAULT); in do_swap_page()
3576 locked = lock_page_or_retry(page, vma->vm_mm, vmf->flags); in do_swap_page()
3594 page = ksm_might_need_to_copy(page, vma, vmf->address); in do_swap_page()
3606 vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, in do_swap_page()
3626 inc_mm_counter_fast(vma->vm_mm, MM_ANONPAGES); in do_swap_page()
3627 dec_mm_counter_fast(vma->vm_mm, MM_SWAPENTS); in do_swap_page()
3628 pte = mk_pte(page, vma->vm_page_prot); in do_swap_page()
3630 pte = maybe_mkwrite(pte_mkdirty(pte), vma); in do_swap_page()
3635 flush_icache_page(vma, page); in do_swap_page()
3642 set_pte_at(vma->vm_mm, vmf->address, vmf->pte, pte); in do_swap_page()
3643 arch_do_swap_page(vma->vm_mm, vma, vmf->address, pte, vmf->orig_pte); in do_swap_page()
3648 page_add_new_anon_rmap(page, vma, vmf->address, false); in do_swap_page()
3649 lru_cache_add_inactive_or_unevictable(page, vma); in do_swap_page()
3651 do_page_add_anon_rmap(page, vma, vmf->address, exclusive); in do_swap_page()
3656 (vma->vm_flags & VM_LOCKED) || PageMlocked(page)) in do_swap_page()
3680 update_mmu_cache(vma, vmf->address, vmf->pte); in do_swap_page()
3709 struct vm_area_struct *vma = vmf->vma; in do_anonymous_page() local
3715 if (vma->vm_flags & VM_SHARED) in do_anonymous_page()
3728 if (pte_alloc(vma->vm_mm, vmf->pmd)) in do_anonymous_page()
3737 !mm_forbids_zeropage(vma->vm_mm)) { in do_anonymous_page()
3739 vma->vm_page_prot)); in do_anonymous_page()
3740 vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, in do_anonymous_page()
3743 update_mmu_tlb(vma, vmf->address, vmf->pte); in do_anonymous_page()
3746 ret = check_stable_address_space(vma->vm_mm); in do_anonymous_page()
3750 if (userfaultfd_missing(vma)) { in do_anonymous_page()
3758 if (unlikely(anon_vma_prepare(vma))) in do_anonymous_page()
3760 page = alloc_zeroed_user_highpage_movable(vma, vmf->address); in do_anonymous_page()
3764 if (mem_cgroup_charge(page_folio(page), vma->vm_mm, GFP_KERNEL)) in do_anonymous_page()
3775 entry = mk_pte(page, vma->vm_page_prot); in do_anonymous_page()
3777 if (vma->vm_flags & VM_WRITE) in do_anonymous_page()
3780 vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, in do_anonymous_page()
3783 update_mmu_cache(vma, vmf->address, vmf->pte); in do_anonymous_page()
3787 ret = check_stable_address_space(vma->vm_mm); in do_anonymous_page()
3792 if (userfaultfd_missing(vma)) { in do_anonymous_page()
3798 inc_mm_counter_fast(vma->vm_mm, MM_ANONPAGES); in do_anonymous_page()
3799 page_add_new_anon_rmap(page, vma, vmf->address, false); in do_anonymous_page()
3800 lru_cache_add_inactive_or_unevictable(page, vma); in do_anonymous_page()
3802 set_pte_at(vma->vm_mm, vmf->address, vmf->pte, entry); in do_anonymous_page()
3805 update_mmu_cache(vma, vmf->address, vmf->pte); in do_anonymous_page()
3825 struct vm_area_struct *vma = vmf->vma; in __do_fault() local
3844 vmf->prealloc_pte = pte_alloc_one(vma->vm_mm); in __do_fault()
3849 ret = vma->vm_ops->fault(vmf); in __do_fault()
3873 struct vm_area_struct *vma = vmf->vma; in deposit_prealloc_pte() local
3875 pgtable_trans_huge_deposit(vma->vm_mm, vmf->pmd, vmf->prealloc_pte); in deposit_prealloc_pte()
3880 mm_inc_nr_ptes(vma->vm_mm); in deposit_prealloc_pte()
3886 struct vm_area_struct *vma = vmf->vma; in do_set_pmd() local
3893 if (!transhuge_vma_suitable(vma, haddr)) in do_set_pmd()
3914 vmf->prealloc_pte = pte_alloc_one(vma->vm_mm); in do_set_pmd()
3919 vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); in do_set_pmd()
3924 flush_icache_page(vma, page + i); in do_set_pmd()
3926 entry = mk_huge_pmd(page, vma->vm_page_prot); in do_set_pmd()
3928 entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); in do_set_pmd()
3930 add_mm_counter(vma->vm_mm, mm_counter_file(page), HPAGE_PMD_NR); in do_set_pmd()
3938 set_pmd_at(vma->vm_mm, haddr, vmf->pmd, entry); in do_set_pmd()
3940 update_mmu_cache_pmd(vma, haddr, vmf->pmd); in do_set_pmd()
3958 struct vm_area_struct *vma = vmf->vma; in do_set_pte() local
3963 flush_icache_page(vma, page); in do_set_pte()
3964 entry = mk_pte(page, vma->vm_page_prot); in do_set_pte()
3972 entry = maybe_mkwrite(pte_mkdirty(entry), vma); in do_set_pte()
3974 if (write && !(vma->vm_flags & VM_SHARED)) { in do_set_pte()
3975 inc_mm_counter_fast(vma->vm_mm, MM_ANONPAGES); in do_set_pte()
3976 page_add_new_anon_rmap(page, vma, addr, false); in do_set_pte()
3977 lru_cache_add_inactive_or_unevictable(page, vma); in do_set_pte()
3979 inc_mm_counter_fast(vma->vm_mm, mm_counter_file(page)); in do_set_pte()
3982 set_pte_at(vma->vm_mm, addr, vmf->pte, entry); in do_set_pte()
4002 struct vm_area_struct *vma = vmf->vma; in finish_fault() local
4007 if ((vmf->flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) in finish_fault()
4016 if (!(vma->vm_flags & VM_SHARED)) { in finish_fault()
4017 ret = check_stable_address_space(vma->vm_mm); in finish_fault()
4030 pmd_install(vma->vm_mm, vmf->pmd, &vmf->prealloc_pte); in finish_fault()
4031 else if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd))) in finish_fault()
4039 vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, in finish_fault()
4048 update_mmu_tlb(vma, vmf->address, vmf->pte); in finish_fault()
4123 address = max(address & mask, vmf->vma->vm_start); in do_fault_around()
4134 end_pgoff = min3(end_pgoff, vma_pages(vmf->vma) + vmf->vma->vm_pgoff - 1, in do_fault_around()
4138 vmf->prealloc_pte = pte_alloc_one(vmf->vma->vm_mm); in do_fault_around()
4143 return vmf->vma->vm_ops->map_pages(vmf, start_pgoff, end_pgoff); in do_fault_around()
4148 struct vm_area_struct *vma = vmf->vma; in do_read_fault() local
4156 if (vma->vm_ops->map_pages && fault_around_bytes >> PAGE_SHIFT > 1) { in do_read_fault()
4157 if (likely(!userfaultfd_minor(vmf->vma))) { in do_read_fault()
4177 struct vm_area_struct *vma = vmf->vma; in do_cow_fault() local
4180 if (unlikely(anon_vma_prepare(vma))) in do_cow_fault()
4183 vmf->cow_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address); in do_cow_fault()
4187 if (mem_cgroup_charge(page_folio(vmf->cow_page), vma->vm_mm, in do_cow_fault()
4200 copy_user_highpage(vmf->cow_page, vmf->page, vmf->address, vma); in do_cow_fault()
4216 struct vm_area_struct *vma = vmf->vma; in do_shared_fault() local
4227 if (vma->vm_ops->page_mkwrite) { in do_shared_fault()
4259 struct vm_area_struct *vma = vmf->vma; in do_fault() local
4260 struct mm_struct *vm_mm = vma->vm_mm; in do_fault()
4266 if (!vma->vm_ops->fault) { in do_fault()
4274 vmf->pte = pte_offset_map_lock(vmf->vma->vm_mm, in do_fault()
4294 else if (!(vma->vm_flags & VM_SHARED)) in do_fault()
4307 int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, in numa_migrate_prep() argument
4318 return mpol_misplaced(page, vma, addr); in numa_migrate_prep()
4323 struct vm_area_struct *vma = vmf->vma; in do_numa_page() local
4337 vmf->ptl = pte_lockptr(vma->vm_mm, vmf->pmd); in do_numa_page()
4346 pte = pte_modify(old_pte, vma->vm_page_prot); in do_numa_page()
4348 page = vm_normal_page(vma, vmf->address, pte); in do_numa_page()
4371 if (page_mapcount(page) > 1 && (vma->vm_flags & VM_SHARED)) in do_numa_page()
4376 target_nid = numa_migrate_prep(page, vma, vmf->address, page_nid, in do_numa_page()
4385 if (migrate_misplaced_page(page, vma, target_nid)) { in do_numa_page()
4408 old_pte = ptep_modify_prot_start(vma, vmf->address, vmf->pte); in do_numa_page()
4409 pte = pte_modify(old_pte, vma->vm_page_prot); in do_numa_page()
4413 ptep_modify_prot_commit(vma, vmf->address, vmf->pte, old_pte, pte); in do_numa_page()
4414 update_mmu_cache(vma, vmf->address, vmf->pte); in do_numa_page()
4421 if (vma_is_anonymous(vmf->vma)) in create_huge_pmd()
4423 if (vmf->vma->vm_ops->huge_fault) in create_huge_pmd()
4424 return vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PMD); in create_huge_pmd()
4431 if (vma_is_anonymous(vmf->vma)) { in wp_huge_pmd()
4432 if (userfaultfd_huge_pmd_wp(vmf->vma, vmf->orig_pmd)) in wp_huge_pmd()
4436 if (vmf->vma->vm_ops->huge_fault) { in wp_huge_pmd()
4437 vm_fault_t ret = vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PMD); in wp_huge_pmd()
4444 __split_huge_pmd(vmf->vma, vmf->pmd, vmf->address, false, NULL); in wp_huge_pmd()
4454 if (vma_is_anonymous(vmf->vma)) in create_huge_pud()
4456 if (vmf->vma->vm_ops->huge_fault) { in create_huge_pud()
4457 vm_fault_t ret = vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PUD); in create_huge_pud()
4464 __split_huge_pud(vmf->vma, vmf->pud, vmf->address); in create_huge_pud()
4473 if (vma_is_anonymous(vmf->vma)) in wp_huge_pud()
4475 if (vmf->vma->vm_ops->huge_fault) in wp_huge_pud()
4476 return vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PUD); in wp_huge_pud()
4548 if (vma_is_anonymous(vmf->vma)) in handle_pte_fault()
4557 if (pte_protnone(vmf->orig_pte) && vma_is_accessible(vmf->vma)) in handle_pte_fault()
4560 vmf->ptl = pte_lockptr(vmf->vma->vm_mm, vmf->pmd); in handle_pte_fault()
4564 update_mmu_tlb(vmf->vma, vmf->address, vmf->pte); in handle_pte_fault()
4573 if (ptep_set_access_flags(vmf->vma, vmf->address, vmf->pte, entry, in handle_pte_fault()
4575 update_mmu_cache(vmf->vma, vmf->address, vmf->pte); in handle_pte_fault()
4587 flush_tlb_fix_spurious_fault(vmf->vma, vmf->address); in handle_pte_fault()
4600 static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, in __handle_mm_fault() argument
4604 .vma = vma, in __handle_mm_fault()
4607 .pgoff = linear_page_index(vma, address), in __handle_mm_fault()
4608 .gfp_mask = __get_fault_gfp_mask(vma), in __handle_mm_fault()
4611 struct mm_struct *mm = vma->vm_mm; in __handle_mm_fault()
4625 if (pud_none(*vmf.pud) && __transparent_hugepage_enabled(vma)) { in __handle_mm_fault()
4656 if (pmd_none(*vmf.pmd) && __transparent_hugepage_enabled(vma)) { in __handle_mm_fault()
4672 if (pmd_protnone(vmf.orig_pmd) && vma_is_accessible(vma)) in __handle_mm_fault()
4756 vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, in handle_mm_fault() argument
4764 count_memcg_event_mm(vma->vm_mm, PGFAULT); in handle_mm_fault()
4769 if (!arch_vma_access_permitted(vma, flags & FAULT_FLAG_WRITE, in handle_mm_fault()
4781 if (unlikely(is_vm_hugetlb_page(vma))) in handle_mm_fault()
4782 ret = hugetlb_fault(vma->vm_mm, vma, address, flags); in handle_mm_fault()
4784 ret = __handle_mm_fault(vma, address, flags); in handle_mm_fault()
4983 int follow_pfn(struct vm_area_struct *vma, unsigned long address, in follow_pfn() argument
4990 if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) in follow_pfn()
4993 ret = follow_pte(vma->vm_mm, address, &ptep, &ptl); in follow_pfn()
5003 int follow_phys(struct vm_area_struct *vma, in follow_phys() argument
5011 if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) in follow_phys()
5014 if (follow_pte(vma->vm_mm, address, &ptep, &ptl)) in follow_phys()
5043 int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, in generic_access_phys() argument
5054 if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) in generic_access_phys()
5058 if (follow_pte(vma->vm_mm, addr, &ptep, &ptl)) in generic_access_phys()
5073 if (follow_pte(vma->vm_mm, addr, &ptep, &ptl)) in generic_access_phys()
5103 struct vm_area_struct *vma; in __access_remote_vm() local
5117 gup_flags, &page, &vma, NULL); in __access_remote_vm()
5126 vma = vma_lookup(mm, addr); in __access_remote_vm()
5127 if (!vma) in __access_remote_vm()
5129 if (vma->vm_ops && vma->vm_ops->access) in __access_remote_vm()
5130 ret = vma->vm_ops->access(vma, addr, buf, in __access_remote_vm()
5144 copy_to_user_page(vma, page, addr, in __access_remote_vm()
5148 copy_from_user_page(vma, page, addr, in __access_remote_vm()
5210 struct vm_area_struct *vma; in print_vma_addr() local
5218 vma = find_vma(mm, ip); in print_vma_addr()
5219 if (vma && vma->vm_file) { in print_vma_addr()
5220 struct file *f = vma->vm_file; in print_vma_addr()
5229 vma->vm_start, in print_vma_addr()
5230 vma->vm_end - vma->vm_start); in print_vma_addr()
5349 struct vm_area_struct *vma, in copy_user_gigantic_page() argument
5358 copy_user_highpage(dst, src, addr + i*PAGE_SIZE, vma); in copy_user_gigantic_page()
5369 struct vm_area_struct *vma; member
5377 addr, copy_arg->vma); in copy_subpage()
5381 unsigned long addr_hint, struct vm_area_struct *vma, in copy_user_huge_page() argument
5389 .vma = vma, in copy_user_huge_page()
5393 copy_user_gigantic_page(dst, src, addr, vma, in copy_user_huge_page()