Merge tag 'perf-core-2023-04-27' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-block.git] / include / linux / pagewalk.h
CommitLineData
a520110e
CH
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_PAGEWALK_H
3#define _LINUX_PAGEWALK_H
4
5#include <linux/mm.h>
6
7b86ac33
CH
7struct mm_walk;
8
a520110e 9/**
91ab1a41 10 * struct mm_walk_ops - callbacks for walk_page_range
3afc4236
SP
11 * @pgd_entry: if set, called for each non-empty PGD (top-level) entry
12 * @p4d_entry: if set, called for each non-empty P4D entry
13 * @pud_entry: if set, called for each non-empty PUD entry
14 * @pmd_entry: if set, called for each non-empty PMD entry
7b86ac33
CH
15 * this handler is required to be able to handle
16 * pmd_trans_huge() pmds. They may simply choose to
17 * split_huge_page() instead of handling it explicitly.
e2f8f44b
REB
18 * @pte_entry: if set, called for each PTE (lowest-level) entry,
19 * including empty ones
b7a16c7a 20 * @pte_hole: if set, called for each hole at all levels,
e2f8f44b
REB
21 * depth is -1 if not known, 0:PGD, 1:P4D, 2:PUD, 3:PMD.
22 * Any folded depths (where PTRS_PER_P?D is equal to 1)
23 * are skipped.
dd361e50
PX
24 * @hugetlb_entry: if set, called for each hugetlb entry. This hook
25 * function is called with the vma lock held, in order to
26 * protect against a concurrent freeing of the pte_t* or
27 * the ptl. In some cases, the hook function needs to drop
28 * and retake the vma lock in order to avoid deadlocks
29 * while calling other functions. In such cases the hook
30 * function must either refrain from accessing the pte or
31 * ptl after dropping the vma lock, or else revalidate
32 * those items after re-acquiring the vma lock and before
33 * accessing them.
7b86ac33
CH
34 * @test_walk: caller specific callback function to determine whether
35 * we walk over the current vma or not. Returning 0 means
36 * "do page table walk over the current vma", returning
37 * a negative value means "abort current page table walk
38 * right now" and returning 1 means "skip the current vma"
c31783ee
DH
39 * Note that this callback is not called when the caller
40 * passes in a single VMA as for walk_page_vma().
ecaad8ac
TH
41 * @pre_vma: if set, called before starting walk on a non-null vma.
42 * @post_vma: if set, called after a walk on a non-null vma, provided
43 * that @pre_vma and the vma walk succeeded.
3afc4236
SP
44 *
45 * p?d_entry callbacks are called even if those levels are folded on a
46 * particular architecture/configuration.
a520110e 47 */
7b86ac33 48struct mm_walk_ops {
3afc4236
SP
49 int (*pgd_entry)(pgd_t *pgd, unsigned long addr,
50 unsigned long next, struct mm_walk *walk);
51 int (*p4d_entry)(p4d_t *p4d, unsigned long addr,
52 unsigned long next, struct mm_walk *walk);
a520110e
CH
53 int (*pud_entry)(pud_t *pud, unsigned long addr,
54 unsigned long next, struct mm_walk *walk);
55 int (*pmd_entry)(pmd_t *pmd, unsigned long addr,
56 unsigned long next, struct mm_walk *walk);
57 int (*pte_entry)(pte_t *pte, unsigned long addr,
58 unsigned long next, struct mm_walk *walk);
59 int (*pte_hole)(unsigned long addr, unsigned long next,
b7a16c7a 60 int depth, struct mm_walk *walk);
a520110e
CH
61 int (*hugetlb_entry)(pte_t *pte, unsigned long hmask,
62 unsigned long addr, unsigned long next,
63 struct mm_walk *walk);
64 int (*test_walk)(unsigned long addr, unsigned long next,
65 struct mm_walk *walk);
ecaad8ac
TH
66 int (*pre_vma)(unsigned long start, unsigned long end,
67 struct mm_walk *walk);
68 void (*post_vma)(struct mm_walk *walk);
7b86ac33
CH
69};
70
3afc4236
SP
71/*
72 * Action for pud_entry / pmd_entry callbacks.
73 * ACTION_SUBTREE is the default
74 */
75enum page_walk_action {
76 /* Descend to next level, splitting huge pages if needed and possible */
77 ACTION_SUBTREE = 0,
78 /* Continue to next entry at this level (ignoring any subtree) */
79 ACTION_CONTINUE = 1,
80 /* Call again for this entry */
81 ACTION_AGAIN = 2
82};
83
7b86ac33 84/**
91ab1a41 85 * struct mm_walk - walk_page_range data
7b86ac33
CH
86 * @ops: operation to call during the walk
87 * @mm: mm_struct representing the target process of page table walk
e47690d7 88 * @pgd: pointer to PGD; only valid with no_vma (otherwise set to NULL)
7b86ac33 89 * @vma: vma currently walked (NULL if walking outside vmas)
3afc4236 90 * @action: next action to perform (see enum page_walk_action)
488ae6a2 91 * @no_vma: walk ignoring vmas (vma will always be NULL)
7b86ac33
CH
92 * @private: private data for callbacks' usage
93 *
94 * (see the comment on walk_page_range() for more details)
95 */
96struct mm_walk {
97 const struct mm_walk_ops *ops;
a520110e 98 struct mm_struct *mm;
e47690d7 99 pgd_t *pgd;
a520110e 100 struct vm_area_struct *vma;
3afc4236 101 enum page_walk_action action;
488ae6a2 102 bool no_vma;
a520110e
CH
103 void *private;
104};
105
7b86ac33
CH
106int walk_page_range(struct mm_struct *mm, unsigned long start,
107 unsigned long end, const struct mm_walk_ops *ops,
108 void *private);
488ae6a2
SP
109int walk_page_range_novma(struct mm_struct *mm, unsigned long start,
110 unsigned long end, const struct mm_walk_ops *ops,
e47690d7 111 pgd_t *pgd,
488ae6a2 112 void *private);
e07cda5f
DH
113int walk_page_range_vma(struct vm_area_struct *vma, unsigned long start,
114 unsigned long end, const struct mm_walk_ops *ops,
115 void *private);
7b86ac33
CH
116int walk_page_vma(struct vm_area_struct *vma, const struct mm_walk_ops *ops,
117 void *private);
ecaad8ac
TH
118int walk_page_mapping(struct address_space *mapping, pgoff_t first_index,
119 pgoff_t nr, const struct mm_walk_ops *ops,
120 void *private);
a520110e
CH
121
122#endif /* _LINUX_PAGEWALK_H */