diff options
Diffstat (limited to 'mm/memory.c')
-rw-r--r-- | mm/memory.c | 276 |
1 files changed, 84 insertions, 192 deletions
diff --git a/mm/memory.c b/mm/memory.c index d707c4dfbbb4..d63849b5188f 100644 --- a/mm/memory.c +++ b/mm/memory.c | |||
@@ -813,42 +813,40 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, | |||
813 | 813 | ||
814 | /* pte contains position in swap or file, so copy. */ | 814 | /* pte contains position in swap or file, so copy. */ |
815 | if (unlikely(!pte_present(pte))) { | 815 | if (unlikely(!pte_present(pte))) { |
816 | if (!pte_file(pte)) { | 816 | swp_entry_t entry = pte_to_swp_entry(pte); |
817 | swp_entry_t entry = pte_to_swp_entry(pte); | 817 | |
818 | 818 | if (likely(!non_swap_entry(entry))) { | |
819 | if (likely(!non_swap_entry(entry))) { | 819 | if (swap_duplicate(entry) < 0) |
820 | if (swap_duplicate(entry) < 0) | 820 | return entry.val; |
821 | return entry.val; | 821 | |
822 | 822 | /* make sure dst_mm is on swapoff's mmlist. */ | |
823 | /* make sure dst_mm is on swapoff's mmlist. */ | 823 | if (unlikely(list_empty(&dst_mm->mmlist))) { |
824 | if (unlikely(list_empty(&dst_mm->mmlist))) { | 824 | spin_lock(&mmlist_lock); |
825 | spin_lock(&mmlist_lock); | 825 | if (list_empty(&dst_mm->mmlist)) |
826 | if (list_empty(&dst_mm->mmlist)) | 826 | list_add(&dst_mm->mmlist, |
827 | list_add(&dst_mm->mmlist, | 827 | &src_mm->mmlist); |
828 | &src_mm->mmlist); | 828 | spin_unlock(&mmlist_lock); |
829 | spin_unlock(&mmlist_lock); | 829 | } |
830 | } | 830 | rss[MM_SWAPENTS]++; |
831 | rss[MM_SWAPENTS]++; | 831 | } else if (is_migration_entry(entry)) { |
832 | } else if (is_migration_entry(entry)) { | 832 | page = migration_entry_to_page(entry); |
833 | page = migration_entry_to_page(entry); | 833 | |
834 | 834 | if (PageAnon(page)) | |
835 | if (PageAnon(page)) | 835 | rss[MM_ANONPAGES]++; |
836 | rss[MM_ANONPAGES]++; | 836 | else |
837 | else | 837 | rss[MM_FILEPAGES]++; |
838 | rss[MM_FILEPAGES]++; | 838 | |
839 | 839 | if (is_write_migration_entry(entry) && | |
840 | if (is_write_migration_entry(entry) && | 840 | is_cow_mapping(vm_flags)) { |
841 | is_cow_mapping(vm_flags)) { | 841 | /* |
842 | /* | 842 | * COW mappings require pages in both |
843 | * COW mappings require pages in both | 843 | * parent and child to be set to read. |
844 | * parent and child to be set to read. | 844 | */ |
845 | */ | 845 | make_migration_entry_read(&entry); |
846 | make_migration_entry_read(&entry); | 846 | pte = swp_entry_to_pte(entry); |
847 | pte = swp_entry_to_pte(entry); | 847 | if (pte_swp_soft_dirty(*src_pte)) |
848 | if (pte_swp_soft_dirty(*src_pte)) | 848 | pte = pte_swp_mksoft_dirty(pte); |
849 | pte = pte_swp_mksoft_dirty(pte); | 849 | set_pte_at(src_mm, addr, src_pte, pte); |
850 | set_pte_at(src_mm, addr, src_pte, pte); | ||
851 | } | ||
852 | } | 850 | } |
853 | } | 851 | } |
854 | goto out_set_pte; | 852 | goto out_set_pte; |
@@ -1022,11 +1020,9 @@ int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm, | |||
1022 | * readonly mappings. The tradeoff is that copy_page_range is more | 1020 | * readonly mappings. The tradeoff is that copy_page_range is more |
1023 | * efficient than faulting. | 1021 | * efficient than faulting. |
1024 | */ | 1022 | */ |
1025 | if (!(vma->vm_flags & (VM_HUGETLB | VM_NONLINEAR | | 1023 | if (!(vma->vm_flags & (VM_HUGETLB | VM_PFNMAP | VM_MIXEDMAP)) && |
1026 | VM_PFNMAP | VM_MIXEDMAP))) { | 1024 | !vma->anon_vma) |
1027 | if (!vma->anon_vma) | 1025 | return 0; |
1028 | return 0; | ||
1029 | } | ||
1030 | 1026 | ||
1031 | if (is_vm_hugetlb_page(vma)) | 1027 | if (is_vm_hugetlb_page(vma)) |
1032 | return copy_hugetlb_page_range(dst_mm, src_mm, vma); | 1028 | return copy_hugetlb_page_range(dst_mm, src_mm, vma); |
@@ -1084,6 +1080,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, | |||
1084 | spinlock_t *ptl; | 1080 | spinlock_t *ptl; |
1085 | pte_t *start_pte; | 1081 | pte_t *start_pte; |
1086 | pte_t *pte; | 1082 | pte_t *pte; |
1083 | swp_entry_t entry; | ||
1087 | 1084 | ||
1088 | again: | 1085 | again: |
1089 | init_rss_vec(rss); | 1086 | init_rss_vec(rss); |
@@ -1109,28 +1106,12 @@ again: | |||
1109 | if (details->check_mapping && | 1106 | if (details->check_mapping && |
1110 | details->check_mapping != page->mapping) | 1107 | details->check_mapping != page->mapping) |
1111 | continue; | 1108 | continue; |
1112 | /* | ||
1113 | * Each page->index must be checked when | ||
1114 | * invalidating or truncating nonlinear. | ||
1115 | */ | ||
1116 | if (details->nonlinear_vma && | ||
1117 | (page->index < details->first_index || | ||
1118 | page->index > details->last_index)) | ||
1119 | continue; | ||
1120 | } | 1109 | } |
1121 | ptent = ptep_get_and_clear_full(mm, addr, pte, | 1110 | ptent = ptep_get_and_clear_full(mm, addr, pte, |
1122 | tlb->fullmm); | 1111 | tlb->fullmm); |
1123 | tlb_remove_tlb_entry(tlb, pte, addr); | 1112 | tlb_remove_tlb_entry(tlb, pte, addr); |
1124 | if (unlikely(!page)) | 1113 | if (unlikely(!page)) |
1125 | continue; | 1114 | continue; |
1126 | if (unlikely(details) && details->nonlinear_vma | ||
1127 | && linear_page_index(details->nonlinear_vma, | ||
1128 | addr) != page->index) { | ||
1129 | pte_t ptfile = pgoff_to_pte(page->index); | ||
1130 | if (pte_soft_dirty(ptent)) | ||
1131 | ptfile = pte_file_mksoft_dirty(ptfile); | ||
1132 | set_pte_at(mm, addr, pte, ptfile); | ||
1133 | } | ||
1134 | if (PageAnon(page)) | 1115 | if (PageAnon(page)) |
1135 | rss[MM_ANONPAGES]--; | 1116 | rss[MM_ANONPAGES]--; |
1136 | else { | 1117 | else { |
@@ -1153,33 +1134,25 @@ again: | |||
1153 | } | 1134 | } |
1154 | continue; | 1135 | continue; |
1155 | } | 1136 | } |
1156 | /* | 1137 | /* If details->check_mapping, we leave swap entries. */ |
1157 | * If details->check_mapping, we leave swap entries; | ||
1158 | * if details->nonlinear_vma, we leave file entries. | ||
1159 | */ | ||
1160 | if (unlikely(details)) | 1138 | if (unlikely(details)) |
1161 | continue; | 1139 | continue; |
1162 | if (pte_file(ptent)) { | ||
1163 | if (unlikely(!(vma->vm_flags & VM_NONLINEAR))) | ||
1164 | print_bad_pte(vma, addr, ptent, NULL); | ||
1165 | } else { | ||
1166 | swp_entry_t entry = pte_to_swp_entry(ptent); | ||
1167 | 1140 | ||
1168 | if (!non_swap_entry(entry)) | 1141 | entry = pte_to_swp_entry(ptent); |
1169 | rss[MM_SWAPENTS]--; | 1142 | if (!non_swap_entry(entry)) |
1170 | else if (is_migration_entry(entry)) { | 1143 | rss[MM_SWAPENTS]--; |
1171 | struct page *page; | 1144 | else if (is_migration_entry(entry)) { |
1145 | struct page *page; | ||
1172 | 1146 | ||
1173 | page = migration_entry_to_page(entry); | 1147 | page = migration_entry_to_page(entry); |
1174 | 1148 | ||
1175 | if (PageAnon(page)) | 1149 | if (PageAnon(page)) |
1176 | rss[MM_ANONPAGES]--; | 1150 | rss[MM_ANONPAGES]--; |
1177 | else | 1151 | else |
1178 | rss[MM_FILEPAGES]--; | 1152 | rss[MM_FILEPAGES]--; |
1179 | } | ||
1180 | if (unlikely(!free_swap_and_cache(entry))) | ||
1181 | print_bad_pte(vma, addr, ptent, NULL); | ||
1182 | } | 1153 | } |
1154 | if (unlikely(!free_swap_and_cache(entry))) | ||
1155 | print_bad_pte(vma, addr, ptent, NULL); | ||
1183 | pte_clear_not_present_full(mm, addr, pte, tlb->fullmm); | 1156 | pte_clear_not_present_full(mm, addr, pte, tlb->fullmm); |
1184 | } while (pte++, addr += PAGE_SIZE, addr != end); | 1157 | } while (pte++, addr += PAGE_SIZE, addr != end); |
1185 | 1158 | ||
@@ -1279,7 +1252,7 @@ static void unmap_page_range(struct mmu_gather *tlb, | |||
1279 | pgd_t *pgd; | 1252 | pgd_t *pgd; |
1280 | unsigned long next; | 1253 | unsigned long next; |
1281 | 1254 | ||
1282 | if (details && !details->check_mapping && !details->nonlinear_vma) | 1255 | if (details && !details->check_mapping) |
1283 | details = NULL; | 1256 | details = NULL; |
1284 | 1257 | ||
1285 | BUG_ON(addr >= end); | 1258 | BUG_ON(addr >= end); |
@@ -1373,7 +1346,7 @@ void unmap_vmas(struct mmu_gather *tlb, | |||
1373 | * @vma: vm_area_struct holding the applicable pages | 1346 | * @vma: vm_area_struct holding the applicable pages |
1374 | * @start: starting address of pages to zap | 1347 | * @start: starting address of pages to zap |
1375 | * @size: number of bytes to zap | 1348 | * @size: number of bytes to zap |
1376 | * @details: details of nonlinear truncation or shared cache invalidation | 1349 | * @details: details of shared cache invalidation |
1377 | * | 1350 | * |
1378 | * Caller must protect the VMA list | 1351 | * Caller must protect the VMA list |
1379 | */ | 1352 | */ |
@@ -1399,7 +1372,7 @@ void zap_page_range(struct vm_area_struct *vma, unsigned long start, | |||
1399 | * @vma: vm_area_struct holding the applicable pages | 1372 | * @vma: vm_area_struct holding the applicable pages |
1400 | * @address: starting address of pages to zap | 1373 | * @address: starting address of pages to zap |
1401 | * @size: number of bytes to zap | 1374 | * @size: number of bytes to zap |
1402 | * @details: details of nonlinear truncation or shared cache invalidation | 1375 | * @details: details of shared cache invalidation |
1403 | * | 1376 | * |
1404 | * The range must fit into one VMA. | 1377 | * The range must fit into one VMA. |
1405 | */ | 1378 | */ |
@@ -1924,12 +1897,11 @@ int apply_to_page_range(struct mm_struct *mm, unsigned long addr, | |||
1924 | EXPORT_SYMBOL_GPL(apply_to_page_range); | 1897 | EXPORT_SYMBOL_GPL(apply_to_page_range); |
1925 | 1898 | ||
1926 | /* | 1899 | /* |
1927 | * handle_pte_fault chooses page fault handler according to an entry | 1900 | * handle_pte_fault chooses page fault handler according to an entry which was |
1928 | * which was read non-atomically. Before making any commitment, on | 1901 | * read non-atomically. Before making any commitment, on those architectures |
1929 | * those architectures or configurations (e.g. i386 with PAE) which | 1902 | * or configurations (e.g. i386 with PAE) which might give a mix of unmatched |
1930 | * might give a mix of unmatched parts, do_swap_page and do_nonlinear_fault | 1903 | * parts, do_swap_page must check under lock before unmapping the pte and |
1931 | * must check under lock before unmapping the pte and proceeding | 1904 | * proceeding (but do_wp_page is only called after already making such a check; |
1932 | * (but do_wp_page is only called after already making such a check; | ||
1933 | * and do_anonymous_page can safely check later on). | 1905 | * and do_anonymous_page can safely check later on). |
1934 | */ | 1906 | */ |
1935 | static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, | 1907 | static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, |
@@ -2035,7 +2007,7 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma, | |||
2035 | pte_t entry; | 2007 | pte_t entry; |
2036 | int ret = 0; | 2008 | int ret = 0; |
2037 | int page_mkwrite = 0; | 2009 | int page_mkwrite = 0; |
2038 | struct page *dirty_page = NULL; | 2010 | bool dirty_shared = false; |
2039 | unsigned long mmun_start = 0; /* For mmu_notifiers */ | 2011 | unsigned long mmun_start = 0; /* For mmu_notifiers */ |
2040 | unsigned long mmun_end = 0; /* For mmu_notifiers */ | 2012 | unsigned long mmun_end = 0; /* For mmu_notifiers */ |
2041 | struct mem_cgroup *memcg; | 2013 | struct mem_cgroup *memcg; |
@@ -2086,6 +2058,7 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma, | |||
2086 | unlock_page(old_page); | 2058 | unlock_page(old_page); |
2087 | } else if (unlikely((vma->vm_flags & (VM_WRITE|VM_SHARED)) == | 2059 | } else if (unlikely((vma->vm_flags & (VM_WRITE|VM_SHARED)) == |
2088 | (VM_WRITE|VM_SHARED))) { | 2060 | (VM_WRITE|VM_SHARED))) { |
2061 | page_cache_get(old_page); | ||
2089 | /* | 2062 | /* |
2090 | * Only catch write-faults on shared writable pages, | 2063 | * Only catch write-faults on shared writable pages, |
2091 | * read-only shared pages can get COWed by | 2064 | * read-only shared pages can get COWed by |
@@ -2093,7 +2066,7 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma, | |||
2093 | */ | 2066 | */ |
2094 | if (vma->vm_ops && vma->vm_ops->page_mkwrite) { | 2067 | if (vma->vm_ops && vma->vm_ops->page_mkwrite) { |
2095 | int tmp; | 2068 | int tmp; |
2096 | page_cache_get(old_page); | 2069 | |
2097 | pte_unmap_unlock(page_table, ptl); | 2070 | pte_unmap_unlock(page_table, ptl); |
2098 | tmp = do_page_mkwrite(vma, old_page, address); | 2071 | tmp = do_page_mkwrite(vma, old_page, address); |
2099 | if (unlikely(!tmp || (tmp & | 2072 | if (unlikely(!tmp || (tmp & |
@@ -2113,11 +2086,10 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma, | |||
2113 | unlock_page(old_page); | 2086 | unlock_page(old_page); |
2114 | goto unlock; | 2087 | goto unlock; |
2115 | } | 2088 | } |
2116 | |||
2117 | page_mkwrite = 1; | 2089 | page_mkwrite = 1; |
2118 | } | 2090 | } |
2119 | dirty_page = old_page; | 2091 | |
2120 | get_page(dirty_page); | 2092 | dirty_shared = true; |
2121 | 2093 | ||
2122 | reuse: | 2094 | reuse: |
2123 | /* | 2095 | /* |
@@ -2136,20 +2108,20 @@ reuse: | |||
2136 | pte_unmap_unlock(page_table, ptl); | 2108 | pte_unmap_unlock(page_table, ptl); |
2137 | ret |= VM_FAULT_WRITE; | 2109 | ret |= VM_FAULT_WRITE; |
2138 | 2110 | ||
2139 | if (!dirty_page) | 2111 | if (dirty_shared) { |
2140 | return ret; | ||
2141 | |||
2142 | if (!page_mkwrite) { | ||
2143 | struct address_space *mapping; | 2112 | struct address_space *mapping; |
2144 | int dirtied; | 2113 | int dirtied; |
2145 | 2114 | ||
2146 | lock_page(dirty_page); | 2115 | if (!page_mkwrite) |
2147 | dirtied = set_page_dirty(dirty_page); | 2116 | lock_page(old_page); |
2148 | VM_BUG_ON_PAGE(PageAnon(dirty_page), dirty_page); | ||
2149 | mapping = dirty_page->mapping; | ||
2150 | unlock_page(dirty_page); | ||
2151 | 2117 | ||
2152 | if (dirtied && mapping) { | 2118 | dirtied = set_page_dirty(old_page); |
2119 | VM_BUG_ON_PAGE(PageAnon(old_page), old_page); | ||
2120 | mapping = old_page->mapping; | ||
2121 | unlock_page(old_page); | ||
2122 | page_cache_release(old_page); | ||
2123 | |||
2124 | if ((dirtied || page_mkwrite) && mapping) { | ||
2153 | /* | 2125 | /* |
2154 | * Some device drivers do not set page.mapping | 2126 | * Some device drivers do not set page.mapping |
2155 | * but still dirty their pages | 2127 | * but still dirty their pages |
@@ -2157,25 +2129,9 @@ reuse: | |||
2157 | balance_dirty_pages_ratelimited(mapping); | 2129 | balance_dirty_pages_ratelimited(mapping); |
2158 | } | 2130 | } |
2159 | 2131 | ||
2160 | /* file_update_time outside page_lock */ | 2132 | if (!page_mkwrite) |
2161 | if (vma->vm_file) | ||
2162 | file_update_time(vma->vm_file); | 2133 | file_update_time(vma->vm_file); |
2163 | } | 2134 | } |
2164 | put_page(dirty_page); | ||
2165 | if (page_mkwrite) { | ||
2166 | struct address_space *mapping = dirty_page->mapping; | ||
2167 | |||
2168 | set_page_dirty(dirty_page); | ||
2169 | unlock_page(dirty_page); | ||
2170 | page_cache_release(dirty_page); | ||
2171 | if (mapping) { | ||
2172 | /* | ||
2173 | * Some device drivers do not set page.mapping | ||
2174 | * but still dirty their pages | ||
2175 | */ | ||
2176 | balance_dirty_pages_ratelimited(mapping); | ||
2177 | } | ||
2178 | } | ||
2179 | 2135 | ||
2180 | return ret; | 2136 | return ret; |
2181 | } | 2137 | } |
@@ -2333,25 +2289,11 @@ static inline void unmap_mapping_range_tree(struct rb_root *root, | |||
2333 | } | 2289 | } |
2334 | } | 2290 | } |
2335 | 2291 | ||
2336 | static inline void unmap_mapping_range_list(struct list_head *head, | ||
2337 | struct zap_details *details) | ||
2338 | { | ||
2339 | struct vm_area_struct *vma; | ||
2340 | |||
2341 | /* | ||
2342 | * In nonlinear VMAs there is no correspondence between virtual address | ||
2343 | * offset and file offset. So we must perform an exhaustive search | ||
2344 | * across *all* the pages in each nonlinear VMA, not just the pages | ||
2345 | * whose virtual address lies outside the file truncation point. | ||
2346 | */ | ||
2347 | list_for_each_entry(vma, head, shared.nonlinear) { | ||
2348 | details->nonlinear_vma = vma; | ||
2349 | unmap_mapping_range_vma(vma, vma->vm_start, vma->vm_end, details); | ||
2350 | } | ||
2351 | } | ||
2352 | |||
2353 | /** | 2292 | /** |
2354 | * unmap_mapping_range - unmap the portion of all mmaps in the specified address_space corresponding to the specified page range in the underlying file. | 2293 | * unmap_mapping_range - unmap the portion of all mmaps in the specified |
2294 | * address_space corresponding to the specified page range in the underlying | ||
2295 | * file. | ||
2296 | * | ||
2355 | * @mapping: the address space containing mmaps to be unmapped. | 2297 | * @mapping: the address space containing mmaps to be unmapped. |
2356 | * @holebegin: byte in first page to unmap, relative to the start of | 2298 | * @holebegin: byte in first page to unmap, relative to the start of |
2357 | * the underlying file. This will be rounded down to a PAGE_SIZE | 2299 | * the underlying file. This will be rounded down to a PAGE_SIZE |
@@ -2380,7 +2322,6 @@ void unmap_mapping_range(struct address_space *mapping, | |||
2380 | } | 2322 | } |
2381 | 2323 | ||
2382 | details.check_mapping = even_cows? NULL: mapping; | 2324 | details.check_mapping = even_cows? NULL: mapping; |
2383 | details.nonlinear_vma = NULL; | ||
2384 | details.first_index = hba; | 2325 | details.first_index = hba; |
2385 | details.last_index = hba + hlen - 1; | 2326 | details.last_index = hba + hlen - 1; |
2386 | if (details.last_index < details.first_index) | 2327 | if (details.last_index < details.first_index) |
@@ -2390,8 +2331,6 @@ void unmap_mapping_range(struct address_space *mapping, | |||
2390 | i_mmap_lock_write(mapping); | 2331 | i_mmap_lock_write(mapping); |
2391 | if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap))) | 2332 | if (unlikely(!RB_EMPTY_ROOT(&mapping->i_mmap))) |
2392 | unmap_mapping_range_tree(&mapping->i_mmap, &details); | 2333 | unmap_mapping_range_tree(&mapping->i_mmap, &details); |
2393 | if (unlikely(!list_empty(&mapping->i_mmap_nonlinear))) | ||
2394 | unmap_mapping_range_list(&mapping->i_mmap_nonlinear, &details); | ||
2395 | i_mmap_unlock_write(mapping); | 2334 | i_mmap_unlock_write(mapping); |
2396 | } | 2335 | } |
2397 | EXPORT_SYMBOL(unmap_mapping_range); | 2336 | EXPORT_SYMBOL(unmap_mapping_range); |
@@ -2752,8 +2691,6 @@ void do_set_pte(struct vm_area_struct *vma, unsigned long address, | |||
2752 | entry = mk_pte(page, vma->vm_page_prot); | 2691 | entry = mk_pte(page, vma->vm_page_prot); |
2753 | if (write) | 2692 | if (write) |
2754 | entry = maybe_mkwrite(pte_mkdirty(entry), vma); | 2693 | entry = maybe_mkwrite(pte_mkdirty(entry), vma); |
2755 | else if (pte_file(*pte) && pte_file_soft_dirty(*pte)) | ||
2756 | entry = pte_mksoft_dirty(entry); | ||
2757 | if (anon) { | 2694 | if (anon) { |
2758 | inc_mm_counter_fast(vma->vm_mm, MM_ANONPAGES); | 2695 | inc_mm_counter_fast(vma->vm_mm, MM_ANONPAGES); |
2759 | page_add_new_anon_rmap(page, vma, address); | 2696 | page_add_new_anon_rmap(page, vma, address); |
@@ -2888,8 +2825,7 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma, | |||
2888 | * if page by the offset is not ready to be mapped (cold cache or | 2825 | * if page by the offset is not ready to be mapped (cold cache or |
2889 | * something). | 2826 | * something). |
2890 | */ | 2827 | */ |
2891 | if (vma->vm_ops->map_pages && !(flags & FAULT_FLAG_NONLINEAR) && | 2828 | if (vma->vm_ops->map_pages && fault_around_bytes >> PAGE_SHIFT > 1) { |
2892 | fault_around_bytes >> PAGE_SHIFT > 1) { | ||
2893 | pte = pte_offset_map_lock(mm, pmd, address, &ptl); | 2829 | pte = pte_offset_map_lock(mm, pmd, address, &ptl); |
2894 | do_fault_around(vma, address, pte, pgoff, flags); | 2830 | do_fault_around(vma, address, pte, pgoff, flags); |
2895 | if (!pte_same(*pte, orig_pte)) | 2831 | if (!pte_same(*pte, orig_pte)) |
@@ -3021,8 +2957,7 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma, | |||
3021 | balance_dirty_pages_ratelimited(mapping); | 2957 | balance_dirty_pages_ratelimited(mapping); |
3022 | } | 2958 | } |
3023 | 2959 | ||
3024 | /* file_update_time outside page_lock */ | 2960 | if (!vma->vm_ops->page_mkwrite) |
3025 | if (vma->vm_file && !vma->vm_ops->page_mkwrite) | ||
3026 | file_update_time(vma->vm_file); | 2961 | file_update_time(vma->vm_file); |
3027 | 2962 | ||
3028 | return ret; | 2963 | return ret; |
@@ -3034,7 +2969,7 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma, | |||
3034 | * The mmap_sem may have been released depending on flags and our | 2969 | * The mmap_sem may have been released depending on flags and our |
3035 | * return value. See filemap_fault() and __lock_page_or_retry(). | 2970 | * return value. See filemap_fault() and __lock_page_or_retry(). |
3036 | */ | 2971 | */ |
3037 | static int do_linear_fault(struct mm_struct *mm, struct vm_area_struct *vma, | 2972 | static int do_fault(struct mm_struct *mm, struct vm_area_struct *vma, |
3038 | unsigned long address, pte_t *page_table, pmd_t *pmd, | 2973 | unsigned long address, pte_t *page_table, pmd_t *pmd, |
3039 | unsigned int flags, pte_t orig_pte) | 2974 | unsigned int flags, pte_t orig_pte) |
3040 | { | 2975 | { |
@@ -3051,46 +2986,6 @@ static int do_linear_fault(struct mm_struct *mm, struct vm_area_struct *vma, | |||
3051 | return do_shared_fault(mm, vma, address, pmd, pgoff, flags, orig_pte); | 2986 | return do_shared_fault(mm, vma, address, pmd, pgoff, flags, orig_pte); |
3052 | } | 2987 | } |
3053 | 2988 | ||
3054 | /* | ||
3055 | * Fault of a previously existing named mapping. Repopulate the pte | ||
3056 | * from the encoded file_pte if possible. This enables swappable | ||
3057 | * nonlinear vmas. | ||
3058 | * | ||
3059 | * We enter with non-exclusive mmap_sem (to exclude vma changes, | ||
3060 | * but allow concurrent faults), and pte mapped but not yet locked. | ||
3061 | * We return with pte unmapped and unlocked. | ||
3062 | * The mmap_sem may have been released depending on flags and our | ||
3063 | * return value. See filemap_fault() and __lock_page_or_retry(). | ||
3064 | */ | ||
3065 | static int do_nonlinear_fault(struct mm_struct *mm, struct vm_area_struct *vma, | ||
3066 | unsigned long address, pte_t *page_table, pmd_t *pmd, | ||
3067 | unsigned int flags, pte_t orig_pte) | ||
3068 | { | ||
3069 | pgoff_t pgoff; | ||
3070 | |||
3071 | flags |= FAULT_FLAG_NONLINEAR; | ||
3072 | |||
3073 | if (!pte_unmap_same(mm, pmd, page_table, orig_pte)) | ||
3074 | return 0; | ||
3075 | |||
3076 | if (unlikely(!(vma->vm_flags & VM_NONLINEAR))) { | ||
3077 | /* | ||
3078 | * Page table corrupted: show pte and kill process. | ||
3079 | */ | ||
3080 | print_bad_pte(vma, address, orig_pte, NULL); | ||
3081 | return VM_FAULT_SIGBUS; | ||
3082 | } | ||
3083 | |||
3084 | pgoff = pte_to_pgoff(orig_pte); | ||
3085 | if (!(flags & FAULT_FLAG_WRITE)) | ||
3086 | return do_read_fault(mm, vma, address, pmd, pgoff, flags, | ||
3087 | orig_pte); | ||
3088 | if (!(vma->vm_flags & VM_SHARED)) | ||
3089 | return do_cow_fault(mm, vma, address, pmd, pgoff, flags, | ||
3090 | orig_pte); | ||
3091 | return do_shared_fault(mm, vma, address, pmd, pgoff, flags, orig_pte); | ||
3092 | } | ||
3093 | |||
3094 | static int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, | 2989 | static int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, |
3095 | unsigned long addr, int page_nid, | 2990 | unsigned long addr, int page_nid, |
3096 | int *flags) | 2991 | int *flags) |
@@ -3218,15 +3113,12 @@ static int handle_pte_fault(struct mm_struct *mm, | |||
3218 | if (pte_none(entry)) { | 3113 | if (pte_none(entry)) { |
3219 | if (vma->vm_ops) { | 3114 | if (vma->vm_ops) { |
3220 | if (likely(vma->vm_ops->fault)) | 3115 | if (likely(vma->vm_ops->fault)) |
3221 | return do_linear_fault(mm, vma, address, | 3116 | return do_fault(mm, vma, address, pte, |
3222 | pte, pmd, flags, entry); | 3117 | pmd, flags, entry); |
3223 | } | 3118 | } |
3224 | return do_anonymous_page(mm, vma, address, | 3119 | return do_anonymous_page(mm, vma, address, |
3225 | pte, pmd, flags); | 3120 | pte, pmd, flags); |
3226 | } | 3121 | } |
3227 | if (pte_file(entry)) | ||
3228 | return do_nonlinear_fault(mm, vma, address, | ||
3229 | pte, pmd, flags, entry); | ||
3230 | return do_swap_page(mm, vma, address, | 3122 | return do_swap_page(mm, vma, address, |
3231 | pte, pmd, flags, entry); | 3123 | pte, pmd, flags, entry); |
3232 | } | 3124 | } |