hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/mm/mincore.c
....@@ -10,16 +10,16 @@
1010 */
1111 #include <linux/pagemap.h>
1212 #include <linux/gfp.h>
13
-#include <linux/mm.h>
13
+#include <linux/pagewalk.h>
1414 #include <linux/mman.h>
1515 #include <linux/syscalls.h>
1616 #include <linux/swap.h>
1717 #include <linux/swapops.h>
1818 #include <linux/shmem_fs.h>
1919 #include <linux/hugetlb.h>
20
+#include <linux/pgtable.h>
2021
2122 #include <linux/uaccess.h>
22
-#include <asm/pgtable.h>
2323
2424 static int mincore_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr,
2525 unsigned long end, struct mm_walk *walk)
....@@ -48,7 +48,7 @@
4848 * and is up to date; i.e. that no page-in operation would be required
4949 * at this time if an application were to map and access this page.
5050 */
51
-static unsigned char mincore_page(struct address_space *mapping, pgoff_t pgoff)
51
+static unsigned char mincore_page(struct address_space *mapping, pgoff_t index)
5252 {
5353 unsigned char present = 0;
5454 struct page *page;
....@@ -59,23 +59,7 @@
5959 * any other file mapping (ie. marked !present and faulted in with
6060 * tmpfs's .fault). So swapped out tmpfs mappings are tested here.
6161 */
62
-#ifdef CONFIG_SWAP
63
- if (shmem_mapping(mapping)) {
64
- page = find_get_entry(mapping, pgoff);
65
- /*
66
- * shmem/tmpfs may return swap: account for swapcache
67
- * page too.
68
- */
69
- if (radix_tree_exceptional_entry(page)) {
70
- swp_entry_t swp = radix_to_swp_entry(page);
71
- page = find_get_page(swap_address_space(swp),
72
- swp_offset(swp));
73
- }
74
- } else
75
- page = find_get_page(mapping, pgoff);
76
-#else
77
- page = find_get_page(mapping, pgoff);
78
-#endif
62
+ page = find_get_incore_page(mapping, index);
7963 if (page) {
8064 present = PageUptodate(page);
8165 put_page(page);
....@@ -104,6 +88,7 @@
10488 }
10589
10690 static int mincore_unmapped_range(unsigned long addr, unsigned long end,
91
+ __always_unused int depth,
10792 struct mm_walk *walk)
10893 {
10994 walk->private += __mincore_unmapped_range(addr, end,
....@@ -185,6 +170,12 @@
185170 inode_permission(file_inode(vma->vm_file), MAY_WRITE) == 0;
186171 }
187172
173
+static const struct mm_walk_ops mincore_walk_ops = {
174
+ .pmd_entry = mincore_pte_range,
175
+ .pte_hole = mincore_unmapped_range,
176
+ .hugetlb_entry = mincore_hugetlb,
177
+};
178
+
188179 /*
189180 * Do a chunk of "sys_mincore()". We've already checked
190181 * all the arguments, we hold the mmap semaphore: we should
....@@ -195,12 +186,6 @@
195186 struct vm_area_struct *vma;
196187 unsigned long end;
197188 int err;
198
- struct mm_walk mincore_walk = {
199
- .pmd_entry = mincore_pte_range,
200
- .pte_hole = mincore_unmapped_range,
201
- .hugetlb_entry = mincore_hugetlb,
202
- .private = vec,
203
- };
204189
205190 vma = find_vma(current->mm, addr);
206191 if (!vma || addr < vma->vm_start)
....@@ -211,8 +196,7 @@
211196 memset(vec, 1, pages);
212197 return pages;
213198 }
214
- mincore_walk.mm = vma->vm_mm;
215
- err = walk_page_range(addr, end, &mincore_walk);
199
+ err = walk_page_range(vma->vm_mm, addr, end, &mincore_walk_ops, vec);
216200 if (err < 0)
217201 return err;
218202 return (end - addr) >> PAGE_SHIFT;
....@@ -256,14 +240,14 @@
256240 return -EINVAL;
257241
258242 /* ..and we need to be passed a valid user-space range */
259
- if (!access_ok(VERIFY_READ, (void __user *) start, len))
243
+ if (!access_ok((void __user *) start, len))
260244 return -ENOMEM;
261245
262246 /* This also avoids any overflows on PAGE_ALIGN */
263247 pages = len >> PAGE_SHIFT;
264248 pages += (offset_in_page(len)) != 0;
265249
266
- if (!access_ok(VERIFY_WRITE, vec, pages))
250
+ if (!access_ok(vec, pages))
267251 return -EFAULT;
268252
269253 tmp = (void *) __get_free_page(GFP_USER);
....@@ -276,9 +260,9 @@
276260 * Do at most PAGE_SIZE entries per iteration, due to
277261 * the temporary buffer size.
278262 */
279
- down_read(&current->mm->mmap_sem);
263
+ mmap_read_lock(current->mm);
280264 retval = do_mincore(start, min(pages, PAGE_SIZE), tmp);
281
- up_read(&current->mm->mmap_sem);
265
+ mmap_read_unlock(current->mm);
282266
283267 if (retval <= 0)
284268 break;