1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_GENERIC_HUGETLB_H
3 #define _ASM_GENERIC_HUGETLB_H
5 #include <linux/swap.h>
6 #include <linux/swapops.h>
8 static inline pte_t mk_huge_pte(struct page *page, pgprot_t pgprot)
10 return mk_pte(page, pgprot);
13 static inline unsigned long huge_pte_write(pte_t pte)
15 return pte_write(pte);
18 static inline unsigned long huge_pte_dirty(pte_t pte)
20 return pte_dirty(pte);
23 static inline pte_t huge_pte_mkwrite(pte_t pte)
25 return pte_mkwrite_novma(pte);
28 #ifndef __HAVE_ARCH_HUGE_PTE_WRPROTECT
29 static inline pte_t huge_pte_wrprotect(pte_t pte)
31 return pte_wrprotect(pte);
35 static inline pte_t huge_pte_mkdirty(pte_t pte)
37 return pte_mkdirty(pte);
40 static inline pte_t huge_pte_modify(pte_t pte, pgprot_t newprot)
42 return pte_modify(pte, newprot);
45 static inline pte_t huge_pte_mkuffd_wp(pte_t pte)
47 return huge_pte_wrprotect(pte_mkuffd_wp(pte));
50 static inline pte_t huge_pte_clear_uffd_wp(pte_t pte)
52 return pte_clear_uffd_wp(pte);
55 static inline int huge_pte_uffd_wp(pte_t pte)
57 return pte_uffd_wp(pte);
60 #ifndef __HAVE_ARCH_HUGE_PTE_CLEAR
61 static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
62 pte_t *ptep, unsigned long sz)
64 pte_clear(mm, addr, ptep);
68 #ifndef __HAVE_ARCH_HUGETLB_FREE_PGD_RANGE
69 static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb,
70 unsigned long addr, unsigned long end,
71 unsigned long floor, unsigned long ceiling)
73 free_pgd_range(tlb, addr, end, floor, ceiling);
77 #ifndef __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT
78 static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
79 pte_t *ptep, pte_t pte, unsigned long sz)
81 set_pte_at(mm, addr, ptep, pte);
85 #ifndef __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR
86 static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
87 unsigned long addr, pte_t *ptep)
89 return ptep_get_and_clear(mm, addr, ptep);
93 #ifndef __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
94 static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
95 unsigned long addr, pte_t *ptep)
97 return ptep_clear_flush(vma, addr, ptep);
101 #ifndef __HAVE_ARCH_HUGE_PTE_NONE
102 static inline int huge_pte_none(pte_t pte)
104 return pte_none(pte);
108 /* Please refer to comments above pte_none_mostly() for the usage */
109 static inline int huge_pte_none_mostly(pte_t pte)
111 return huge_pte_none(pte) || is_pte_marker(pte);
114 #ifndef __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE
115 static inline int prepare_hugepage_range(struct file *file,
116 unsigned long addr, unsigned long len)
118 struct hstate *h = hstate_file(file);
120 if (len & ~huge_page_mask(h))
122 if (addr & ~huge_page_mask(h))
129 #ifndef __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
130 static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
131 unsigned long addr, pte_t *ptep)
133 ptep_set_wrprotect(mm, addr, ptep);
137 #ifndef __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS
138 static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
139 unsigned long addr, pte_t *ptep,
140 pte_t pte, int dirty)
142 return ptep_set_access_flags(vma, addr, ptep, pte, dirty);
146 #ifndef __HAVE_ARCH_HUGE_PTEP_GET
147 static inline pte_t huge_ptep_get(pte_t *ptep)
149 return ptep_get(ptep);
153 #ifndef __HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED
154 static inline bool gigantic_page_runtime_supported(void)
156 return IS_ENABLED(CONFIG_ARCH_HAS_GIGANTIC_PAGE);
158 #endif /* __HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED */
160 #endif /* _ASM_GENERIC_HUGETLB_H */