2 #include <linux/highmem.h>
3 #include <linux/sched.h>
5 static int walk_pte_range(pmd_t
*pmd
, unsigned long addr
, unsigned long end
,
6 const struct mm_walk
*walk
, void *private)
11 pte
= pte_offset_map(pmd
, addr
);
13 err
= walk
->pte_entry(pte
, addr
, addr
+ PAGE_SIZE
, private);
16 } while (pte
++, addr
+= PAGE_SIZE
, addr
!= end
);
22 static int walk_pmd_range(pud_t
*pud
, unsigned long addr
, unsigned long end
,
23 const struct mm_walk
*walk
, void *private)
29 pmd
= pmd_offset(pud
, addr
);
31 next
= pmd_addr_end(addr
, end
);
32 if (pmd_none_or_clear_bad(pmd
)) {
34 err
= walk
->pte_hole(addr
, next
, private);
40 err
= walk
->pmd_entry(pmd
, addr
, next
, private);
41 if (!err
&& walk
->pte_entry
)
42 err
= walk_pte_range(pmd
, addr
, next
, walk
, private);
45 } while (pmd
++, addr
= next
, addr
!= end
);
50 static int walk_pud_range(pgd_t
*pgd
, unsigned long addr
, unsigned long end
,
51 const struct mm_walk
*walk
, void *private)
57 pud
= pud_offset(pgd
, addr
);
59 next
= pud_addr_end(addr
, end
);
60 if (pud_none_or_clear_bad(pud
)) {
62 err
= walk
->pte_hole(addr
, next
, private);
68 err
= walk
->pud_entry(pud
, addr
, next
, private);
69 if (!err
&& (walk
->pmd_entry
|| walk
->pte_entry
))
70 err
= walk_pmd_range(pud
, addr
, next
, walk
, private);
73 } while (pud
++, addr
= next
, addr
!= end
);
79 * walk_page_range - walk a memory map's page tables with a callback
80 * @mm: memory map to walk
81 * @addr: starting address
82 * @end: ending address
83 * @walk: set of callbacks to invoke for each level of the tree
84 * @private: private data passed to the callback function
86 * Recursively walk the page table for the memory area in a VMA,
87 * calling supplied callbacks. Callbacks are called in-order (first
88 * PGD, first PUD, first PMD, first PTE, second PTE... second PMD,
89 * etc.). If lower-level callbacks are omitted, walking depth is reduced.
91 * Each callback receives an entry pointer, the start and end of the
92 * associated range, and a caller-supplied private data pointer.
94 * No locks are taken, but the bottom level iterator will map PTE
95 * directories from highmem if necessary.
97 * If any callback returns a non-zero value, the walk is aborted and
98 * the return value is propagated back to the caller. Otherwise 0 is returned.
100 int walk_page_range(const struct mm_struct
*mm
,
101 unsigned long addr
, unsigned long end
,
102 const struct mm_walk
*walk
, void *private)
111 pgd
= pgd_offset(mm
, addr
);
113 next
= pgd_addr_end(addr
, end
);
114 if (pgd_none_or_clear_bad(pgd
)) {
116 err
= walk
->pte_hole(addr
, next
, private);
122 err
= walk
->pgd_entry(pgd
, addr
, next
, private);
124 (walk
->pud_entry
|| walk
->pmd_entry
|| walk
->pte_entry
))
125 err
= walk_pud_range(pgd
, addr
, next
, walk
, private);
128 } while (pgd
++, addr
= next
, addr
!= end
);