blob: 6dcf4d576970c4b43ce8be9e0373bc39d10e3518 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Gerald Schaefer106c9922013-04-29 15:07:23 -07002#ifndef _ASM_GENERIC_HUGETLB_H
3#define _ASM_GENERIC_HUGETLB_H
4
Peter Xu679d1032022-05-12 20:22:52 -07005#include <linux/swap.h>
6#include <linux/swapops.h>
7
Gerald Schaefer106c9922013-04-29 15:07:23 -07008static inline pte_t mk_huge_pte(struct page *page, pgprot_t pgprot)
9{
10 return mk_pte(page, pgprot);
11}
12
David Miller26794942013-10-02 14:25:09 -040013static inline unsigned long huge_pte_write(pte_t pte)
Gerald Schaefer106c9922013-04-29 15:07:23 -070014{
15 return pte_write(pte);
16}
17
David Miller26794942013-10-02 14:25:09 -040018static inline unsigned long huge_pte_dirty(pte_t pte)
Gerald Schaefer106c9922013-04-29 15:07:23 -070019{
20 return pte_dirty(pte);
21}
22
23static inline pte_t huge_pte_mkwrite(pte_t pte)
24{
Rick Edgecombe2f0584f2023-06-12 17:10:27 -070025 return pte_mkwrite_novma(pte);
Gerald Schaefer106c9922013-04-29 15:07:23 -070026}
27
Peter Xuf1eb1ba2022-12-14 15:15:33 -050028#ifndef __HAVE_ARCH_HUGE_PTE_WRPROTECT
29static inline pte_t huge_pte_wrprotect(pte_t pte)
30{
31 return pte_wrprotect(pte);
32}
33#endif
34
Gerald Schaefer106c9922013-04-29 15:07:23 -070035static inline pte_t huge_pte_mkdirty(pte_t pte)
36{
37 return pte_mkdirty(pte);
38}
39
40static inline pte_t huge_pte_modify(pte_t pte, pgprot_t newprot)
41{
42 return pte_modify(pte, newprot);
43}
44
Peter Xu229f3fa2022-05-12 20:22:54 -070045static inline pte_t huge_pte_mkuffd_wp(pte_t pte)
46{
Peter Xuf1eb1ba2022-12-14 15:15:33 -050047 return huge_pte_wrprotect(pte_mkuffd_wp(pte));
Peter Xu229f3fa2022-05-12 20:22:54 -070048}
49
50static inline pte_t huge_pte_clear_uffd_wp(pte_t pte)
51{
52 return pte_clear_uffd_wp(pte);
53}
54
55static inline int huge_pte_uffd_wp(pte_t pte)
56{
57 return pte_uffd_wp(pte);
58}
59
Alexandre Ghitid0184982018-10-26 15:07:59 -070060#ifndef __HAVE_ARCH_HUGE_PTE_CLEAR
Gerald Schaefer106c9922013-04-29 15:07:23 -070061static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
Punit Agrawal9386fac2017-07-06 15:39:46 -070062 pte_t *ptep, unsigned long sz)
Gerald Schaefer106c9922013-04-29 15:07:23 -070063{
64 pte_clear(mm, addr, ptep);
65}
Punit Agrawal9386fac2017-07-06 15:39:46 -070066#endif
Gerald Schaefer106c9922013-04-29 15:07:23 -070067
Alexandre Ghiti1e5f50f2018-10-26 15:08:03 -070068#ifndef __HAVE_ARCH_HUGETLB_FREE_PGD_RANGE
69static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb,
70 unsigned long addr, unsigned long end,
71 unsigned long floor, unsigned long ceiling)
72{
73 free_pgd_range(tlb, addr, end, floor, ceiling);
74}
Alexandre Ghiticea685d2018-10-26 15:08:07 -070075#endif
Alexandre Ghiti1e5f50f2018-10-26 15:08:03 -070076
Alexandre Ghiticea685d2018-10-26 15:08:07 -070077#ifndef __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT
78static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
Ryan Roberts935d4f02023-09-22 12:58:03 +010079 pte_t *ptep, pte_t pte, unsigned long sz)
Alexandre Ghiticea685d2018-10-26 15:08:07 -070080{
81 set_pte_at(mm, addr, ptep, pte);
82}
Alexandre Ghiti1e5f50f2018-10-26 15:08:03 -070083#endif
84
Alexandre Ghitia4d83852018-10-26 15:08:12 -070085#ifndef __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR
86static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
87 unsigned long addr, pte_t *ptep)
88{
89 return ptep_get_and_clear(mm, addr, ptep);
90}
91#endif
92
Alexandre Ghitife632222018-10-26 15:08:17 -070093#ifndef __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
Baolin Wangae075622022-05-13 16:48:55 -070094static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
Alexandre Ghitife632222018-10-26 15:08:17 -070095 unsigned long addr, pte_t *ptep)
96{
Baolin Wangae075622022-05-13 16:48:55 -070097 return ptep_clear_flush(vma, addr, ptep);
Alexandre Ghitife632222018-10-26 15:08:17 -070098}
99#endif
100
Alexandre Ghiticae72ab2018-10-26 15:08:22 -0700101#ifndef __HAVE_ARCH_HUGE_PTE_NONE
102static inline int huge_pte_none(pte_t pte)
103{
104 return pte_none(pte);
105}
106#endif
107
Peter Xu679d1032022-05-12 20:22:52 -0700108/* Please refer to comments above pte_none_mostly() for the usage */
109static inline int huge_pte_none_mostly(pte_t pte)
110{
111 return huge_pte_none(pte) || is_pte_marker(pte);
112}
113
Alexandre Ghiti78d6e4e2018-10-26 15:08:31 -0700114#ifndef __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE
115static inline int prepare_hugepage_range(struct file *file,
116 unsigned long addr, unsigned long len)
117{
118 struct hstate *h = hstate_file(file);
119
120 if (len & ~huge_page_mask(h))
121 return -EINVAL;
122 if (addr & ~huge_page_mask(h))
123 return -EINVAL;
124
125 return 0;
126}
127#endif
128
Alexandre Ghiti8e581d42018-10-26 15:08:35 -0700129#ifndef __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
130static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
131 unsigned long addr, pte_t *ptep)
132{
133 ptep_set_wrprotect(mm, addr, ptep);
134}
135#endif
136
Alexandre Ghitifacf6d52018-10-26 15:08:39 -0700137#ifndef __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS
138static 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)
141{
142 return ptep_set_access_flags(vma, addr, ptep, pte, dirty);
143}
144#endif
145
Alexandre Ghiti544db752018-10-26 15:08:43 -0700146#ifndef __HAVE_ARCH_HUGE_PTEP_GET
147static inline pte_t huge_ptep_get(pte_t *ptep)
148{
Christophe Leroy481e9802020-06-15 12:57:58 +0000149 return ptep_get(ptep);
Alexandre Ghiti544db752018-10-26 15:08:43 -0700150}
151#endif
152
Alexandre Ghiti4eb07162019-05-13 17:19:04 -0700153#ifndef __HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED
154static inline bool gigantic_page_runtime_supported(void)
155{
156 return IS_ENABLED(CONFIG_ARCH_HAS_GIGANTIC_PAGE);
157}
158#endif /* __HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED */
159
Gerald Schaefer106c9922013-04-29 15:07:23 -0700160#endif /* _ASM_GENERIC_HUGETLB_H */