1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_GENERIC_PGALLOC_H
3 #define __ASM_GENERIC_PGALLOC_H
7 #define GFP_PGTABLE_KERNEL (GFP_KERNEL | __GFP_ZERO)
8 #define GFP_PGTABLE_USER (GFP_PGTABLE_KERNEL | __GFP_ACCOUNT)
11 * __pte_alloc_one_kernel - allocate a page for PTE-level kernel page table
12 * @mm: the mm_struct of the current context
14 * This function is intended for architectures that need
15 * anything beyond simple page allocation.
17 * Return: pointer to the allocated memory or %NULL on error
19 static inline pte_t *__pte_alloc_one_kernel(struct mm_struct *mm)
21 return (pte_t *)__get_free_page(GFP_PGTABLE_KERNEL);
24 #ifndef __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL
26 * pte_alloc_one_kernel - allocate a page for PTE-level kernel page table
27 * @mm: the mm_struct of the current context
29 * Return: pointer to the allocated memory or %NULL on error
31 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
33 return __pte_alloc_one_kernel(mm);
38 * pte_free_kernel - free PTE-level kernel page table page
39 * @mm: the mm_struct of the current context
40 * @pte: pointer to the memory containing the page table
42 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
44 free_page((unsigned long)pte);
48 * __pte_alloc_one - allocate a page for PTE-level user page table
49 * @mm: the mm_struct of the current context
50 * @gfp: GFP flags to use for the allocation
52 * Allocates a page and runs the pgtable_page_ctor().
54 * This function is intended for architectures that need
55 * anything beyond simple page allocation or must have custom GFP flags.
57 * Return: `struct page` initialized as page table or %NULL on error
59 static inline pgtable_t __pte_alloc_one(struct mm_struct *mm, gfp_t gfp)
63 pte = alloc_page(gfp);
66 if (!pgtable_page_ctor(pte)) {
74 #ifndef __HAVE_ARCH_PTE_ALLOC_ONE
76 * pte_alloc_one - allocate a page for PTE-level user page table
77 * @mm: the mm_struct of the current context
79 * Allocates a page and runs the pgtable_page_ctor().
81 * Return: `struct page` initialized as page table or %NULL on error
83 static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
85 return __pte_alloc_one(mm, GFP_PGTABLE_USER);
90 * Should really implement gc for free page table pages. This could be
91 * done with a reference count in struct page.
95 * pte_free - free PTE-level user page table page
96 * @mm: the mm_struct of the current context
97 * @pte_page: the `struct page` representing the page table
99 static inline void pte_free(struct mm_struct *mm, struct page *pte_page)
101 pgtable_page_dtor(pte_page);
102 __free_page(pte_page);
105 #else /* CONFIG_MMU */
107 /* This is enough for a nommu architecture */
108 #define check_pgt_cache() do { } while (0)
110 #endif /* CONFIG_MMU */
112 #endif /* __ASM_GENERIC_PGALLOC_H */