Commit | Line | Data |
---|---|---|
df4e817b PT |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | ||
3 | /* | |
4 | * Copyright (c) 2021, Google LLC. | |
5 | * Pasha Tatashin <pasha.tatashin@soleen.com> | |
6 | */ | |
7 | #ifndef __LINUX_PAGE_TABLE_CHECK_H | |
8 | #define __LINUX_PAGE_TABLE_CHECK_H | |
9 | ||
10 | #ifdef CONFIG_PAGE_TABLE_CHECK | |
11 | #include <linux/jump_label.h> | |
12 | ||
13 | extern struct static_key_true page_table_check_disabled; | |
14 | extern struct page_ext_operations page_table_check_ops; | |
15 | ||
16 | void __page_table_check_zero(struct page *page, unsigned int order); | |
aa232204 | 17 | void __page_table_check_pte_clear(struct mm_struct *mm, pte_t pte); |
1831414c | 18 | void __page_table_check_pmd_clear(struct mm_struct *mm, pmd_t pmd); |
df4e817b PT |
19 | void __page_table_check_pud_clear(struct mm_struct *mm, unsigned long addr, |
20 | pud_t pud); | |
21 | void __page_table_check_pte_set(struct mm_struct *mm, unsigned long addr, | |
22 | pte_t *ptep, pte_t pte); | |
23 | void __page_table_check_pmd_set(struct mm_struct *mm, unsigned long addr, | |
24 | pmd_t *pmdp, pmd_t pmd); | |
25 | void __page_table_check_pud_set(struct mm_struct *mm, unsigned long addr, | |
26 | pud_t *pudp, pud_t pud); | |
80110bbf PT |
27 | void __page_table_check_pte_clear_range(struct mm_struct *mm, |
28 | unsigned long addr, | |
29 | pmd_t pmd); | |
df4e817b PT |
30 | |
31 | static inline void page_table_check_alloc(struct page *page, unsigned int order) | |
32 | { | |
33 | if (static_branch_likely(&page_table_check_disabled)) | |
34 | return; | |
35 | ||
36 | __page_table_check_zero(page, order); | |
37 | } | |
38 | ||
39 | static inline void page_table_check_free(struct page *page, unsigned int order) | |
40 | { | |
41 | if (static_branch_likely(&page_table_check_disabled)) | |
42 | return; | |
43 | ||
44 | __page_table_check_zero(page, order); | |
45 | } | |
46 | ||
aa232204 | 47 | static inline void page_table_check_pte_clear(struct mm_struct *mm, pte_t pte) |
df4e817b PT |
48 | { |
49 | if (static_branch_likely(&page_table_check_disabled)) | |
50 | return; | |
51 | ||
aa232204 | 52 | __page_table_check_pte_clear(mm, pte); |
df4e817b PT |
53 | } |
54 | ||
1831414c | 55 | static inline void page_table_check_pmd_clear(struct mm_struct *mm, pmd_t pmd) |
df4e817b PT |
56 | { |
57 | if (static_branch_likely(&page_table_check_disabled)) | |
58 | return; | |
59 | ||
1831414c | 60 | __page_table_check_pmd_clear(mm, pmd); |
df4e817b PT |
61 | } |
62 | ||
63 | static inline void page_table_check_pud_clear(struct mm_struct *mm, | |
64 | unsigned long addr, pud_t pud) | |
65 | { | |
66 | if (static_branch_likely(&page_table_check_disabled)) | |
67 | return; | |
68 | ||
69 | __page_table_check_pud_clear(mm, addr, pud); | |
70 | } | |
71 | ||
72 | static inline void page_table_check_pte_set(struct mm_struct *mm, | |
73 | unsigned long addr, pte_t *ptep, | |
74 | pte_t pte) | |
75 | { | |
76 | if (static_branch_likely(&page_table_check_disabled)) | |
77 | return; | |
78 | ||
79 | __page_table_check_pte_set(mm, addr, ptep, pte); | |
80 | } | |
81 | ||
82 | static inline void page_table_check_pmd_set(struct mm_struct *mm, | |
83 | unsigned long addr, pmd_t *pmdp, | |
84 | pmd_t pmd) | |
85 | { | |
86 | if (static_branch_likely(&page_table_check_disabled)) | |
87 | return; | |
88 | ||
89 | __page_table_check_pmd_set(mm, addr, pmdp, pmd); | |
90 | } | |
91 | ||
92 | static inline void page_table_check_pud_set(struct mm_struct *mm, | |
93 | unsigned long addr, pud_t *pudp, | |
94 | pud_t pud) | |
95 | { | |
96 | if (static_branch_likely(&page_table_check_disabled)) | |
97 | return; | |
98 | ||
99 | __page_table_check_pud_set(mm, addr, pudp, pud); | |
100 | } | |
101 | ||
80110bbf PT |
102 | static inline void page_table_check_pte_clear_range(struct mm_struct *mm, |
103 | unsigned long addr, | |
104 | pmd_t pmd) | |
105 | { | |
106 | if (static_branch_likely(&page_table_check_disabled)) | |
107 | return; | |
108 | ||
109 | __page_table_check_pte_clear_range(mm, addr, pmd); | |
110 | } | |
111 | ||
df4e817b PT |
112 | #else |
113 | ||
114 | static inline void page_table_check_alloc(struct page *page, unsigned int order) | |
115 | { | |
116 | } | |
117 | ||
118 | static inline void page_table_check_free(struct page *page, unsigned int order) | |
119 | { | |
120 | } | |
121 | ||
aa232204 | 122 | static inline void page_table_check_pte_clear(struct mm_struct *mm, pte_t pte) |
df4e817b PT |
123 | { |
124 | } | |
125 | ||
1831414c | 126 | static inline void page_table_check_pmd_clear(struct mm_struct *mm, pmd_t pmd) |
df4e817b PT |
127 | { |
128 | } | |
129 | ||
130 | static inline void page_table_check_pud_clear(struct mm_struct *mm, | |
131 | unsigned long addr, pud_t pud) | |
132 | { | |
133 | } | |
134 | ||
135 | static inline void page_table_check_pte_set(struct mm_struct *mm, | |
136 | unsigned long addr, pte_t *ptep, | |
137 | pte_t pte) | |
138 | { | |
139 | } | |
140 | ||
141 | static inline void page_table_check_pmd_set(struct mm_struct *mm, | |
142 | unsigned long addr, pmd_t *pmdp, | |
143 | pmd_t pmd) | |
144 | { | |
145 | } | |
146 | ||
147 | static inline void page_table_check_pud_set(struct mm_struct *mm, | |
148 | unsigned long addr, pud_t *pudp, | |
149 | pud_t pud) | |
150 | { | |
151 | } | |
152 | ||
80110bbf PT |
153 | static inline void page_table_check_pte_clear_range(struct mm_struct *mm, |
154 | unsigned long addr, | |
155 | pmd_t pmd) | |
156 | { | |
157 | } | |
158 | ||
df4e817b PT |
159 | #endif /* CONFIG_PAGE_TABLE_CHECK */ |
160 | #endif /* __LINUX_PAGE_TABLE_CHECK_H */ |