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
13extern struct static_key_true page_table_check_disabled;
14extern struct page_ext_operations page_table_check_ops;
15
16void __page_table_check_zero(struct page *page, unsigned int order);
17void __page_table_check_pte_clear(struct mm_struct *mm, pte_t pte);
18void __page_table_check_pmd_clear(struct mm_struct *mm, pmd_t pmd);
19void __page_table_check_pud_clear(struct mm_struct *mm, pud_t pud);
20void __page_table_check_ptes_set(struct mm_struct *mm, pte_t *ptep, pte_t pte,
21 unsigned int nr);
22void __page_table_check_pmd_set(struct mm_struct *mm, pmd_t *pmdp, pmd_t pmd);
23void __page_table_check_pud_set(struct mm_struct *mm, pud_t *pudp, pud_t pud);
24void __page_table_check_pte_clear_range(struct mm_struct *mm,
25 unsigned long addr,
26 pmd_t pmd);
27
28static inline void page_table_check_alloc(struct page *page, unsigned int order)
29{
30 if (static_branch_likely(&page_table_check_disabled))
31 return;
32
33 __page_table_check_zero(page, order);
34}
35
36static inline void page_table_check_free(struct page *page, unsigned int order)
37{
38 if (static_branch_likely(&page_table_check_disabled))
39 return;
40
41 __page_table_check_zero(page, order);
42}
43
44static inline void page_table_check_pte_clear(struct mm_struct *mm, pte_t pte)
45{
46 if (static_branch_likely(&page_table_check_disabled))
47 return;
48
49 __page_table_check_pte_clear(mm, pte);
50}
51
52static inline void page_table_check_pmd_clear(struct mm_struct *mm, pmd_t pmd)
53{
54 if (static_branch_likely(&page_table_check_disabled))
55 return;
56
57 __page_table_check_pmd_clear(mm, pmd);
58}
59
60static inline void page_table_check_pud_clear(struct mm_struct *mm, pud_t pud)
61{
62 if (static_branch_likely(&page_table_check_disabled))
63 return;
64
65 __page_table_check_pud_clear(mm, pud);
66}
67
68static inline void page_table_check_ptes_set(struct mm_struct *mm,
69 pte_t *ptep, pte_t pte, unsigned int nr)
70{
71 if (static_branch_likely(&page_table_check_disabled))
72 return;
73
74 __page_table_check_ptes_set(mm, ptep, pte, nr);
75}
76
77static inline void page_table_check_pmd_set(struct mm_struct *mm, pmd_t *pmdp,
78 pmd_t pmd)
79{
80 if (static_branch_likely(&page_table_check_disabled))
81 return;
82
83 __page_table_check_pmd_set(mm, pmdp, pmd);
84}
85
86static inline void page_table_check_pud_set(struct mm_struct *mm, pud_t *pudp,
87 pud_t pud)
88{
89 if (static_branch_likely(&page_table_check_disabled))
90 return;
91
92 __page_table_check_pud_set(mm, pudp, pud);
93}
94
95static inline void page_table_check_pte_clear_range(struct mm_struct *mm,
96 unsigned long addr,
97 pmd_t pmd)
98{
99 if (static_branch_likely(&page_table_check_disabled))
100 return;
101
102 __page_table_check_pte_clear_range(mm, addr, pmd);
103}
104
105#else
106
107static inline void page_table_check_alloc(struct page *page, unsigned int order)
108{
109}
110
111static inline void page_table_check_free(struct page *page, unsigned int order)
112{
113}
114
115static inline void page_table_check_pte_clear(struct mm_struct *mm, pte_t pte)
116{
117}
118
119static inline void page_table_check_pmd_clear(struct mm_struct *mm, pmd_t pmd)
120{
121}
122
123static inline void page_table_check_pud_clear(struct mm_struct *mm, pud_t pud)
124{
125}
126
127static inline void page_table_check_ptes_set(struct mm_struct *mm,
128 pte_t *ptep, pte_t pte, unsigned int nr)
129{
130}
131
132static inline void page_table_check_pmd_set(struct mm_struct *mm, pmd_t *pmdp,
133 pmd_t pmd)
134{
135}
136
137static inline void page_table_check_pud_set(struct mm_struct *mm, pud_t *pudp,
138 pud_t pud)
139{
140}
141
142static inline void page_table_check_pte_clear_range(struct mm_struct *mm,
143 unsigned long addr,
144 pmd_t pmd)
145{
146}
147
148#endif /* CONFIG_PAGE_TABLE_CHECK */
149#endif /* __LINUX_PAGE_TABLE_CHECK_H */
150

source code of linux/include/linux/page_table_check.h