xref: /openbmc/linux/include/linux/pagewalk.h (revision 4bb1e4e7)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_PAGEWALK_H
3 #define _LINUX_PAGEWALK_H
4 
5 #include <linux/mm.h>
6 
7 struct mm_walk;
8 
9 /**
10  * mm_walk_ops - callbacks for walk_page_range
11  * @pud_entry:		if set, called for each non-empty PUD (2nd-level) entry
12  *			this handler should only handle pud_trans_huge() puds.
13  *			the pmd_entry or pte_entry callbacks will be used for
14  *			regular PUDs.
15  * @pmd_entry:		if set, called for each non-empty PMD (3rd-level) entry
16  *			this handler is required to be able to handle
17  *			pmd_trans_huge() pmds.  They may simply choose to
18  *			split_huge_page() instead of handling it explicitly.
19  * @pte_entry:		if set, called for each non-empty PTE (4th-level) entry
20  * @pte_hole:		if set, called for each hole at all levels
21  * @hugetlb_entry:	if set, called for each hugetlb entry
22  * @test_walk:		caller specific callback function to determine whether
23  *			we walk over the current vma or not. Returning 0 means
24  *			"do page table walk over the current vma", returning
25  *			a negative value means "abort current page table walk
26  *			right now" and returning 1 means "skip the current vma"
27  * @pre_vma:            if set, called before starting walk on a non-null vma.
28  * @post_vma:           if set, called after a walk on a non-null vma, provided
29  *                      that @pre_vma and the vma walk succeeded.
30  */
31 struct mm_walk_ops {
32 	int (*pud_entry)(pud_t *pud, unsigned long addr,
33 			 unsigned long next, struct mm_walk *walk);
34 	int (*pmd_entry)(pmd_t *pmd, unsigned long addr,
35 			 unsigned long next, struct mm_walk *walk);
36 	int (*pte_entry)(pte_t *pte, unsigned long addr,
37 			 unsigned long next, struct mm_walk *walk);
38 	int (*pte_hole)(unsigned long addr, unsigned long next,
39 			struct mm_walk *walk);
40 	int (*hugetlb_entry)(pte_t *pte, unsigned long hmask,
41 			     unsigned long addr, unsigned long next,
42 			     struct mm_walk *walk);
43 	int (*test_walk)(unsigned long addr, unsigned long next,
44 			struct mm_walk *walk);
45 	int (*pre_vma)(unsigned long start, unsigned long end,
46 		       struct mm_walk *walk);
47 	void (*post_vma)(struct mm_walk *walk);
48 };
49 
50 /**
51  * mm_walk - walk_page_range data
52  * @ops:	operation to call during the walk
53  * @mm:		mm_struct representing the target process of page table walk
54  * @vma:	vma currently walked (NULL if walking outside vmas)
55  * @private:	private data for callbacks' usage
56  *
57  * (see the comment on walk_page_range() for more details)
58  */
59 struct mm_walk {
60 	const struct mm_walk_ops *ops;
61 	struct mm_struct *mm;
62 	struct vm_area_struct *vma;
63 	void *private;
64 };
65 
66 int walk_page_range(struct mm_struct *mm, unsigned long start,
67 		unsigned long end, const struct mm_walk_ops *ops,
68 		void *private);
69 int walk_page_vma(struct vm_area_struct *vma, const struct mm_walk_ops *ops,
70 		void *private);
71 int walk_page_mapping(struct address_space *mapping, pgoff_t first_index,
72 		      pgoff_t nr, const struct mm_walk_ops *ops,
73 		      void *private);
74 
75 #endif /* _LINUX_PAGEWALK_H */
76