Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _LINUX_HUGETLB_H |
3 | #define _LINUX_HUGETLB_H | |
4 | ||
9c67a207 | 5 | #include <linux/mm.h> |
be93d8cf | 6 | #include <linux/mm_types.h> |
309381fe | 7 | #include <linux/mmdebug.h> |
4e950f6f | 8 | #include <linux/fs.h> |
8edf344c | 9 | #include <linux/hugetlb_inline.h> |
abb8206c | 10 | #include <linux/cgroup.h> |
3489dbb6 | 11 | #include <linux/page_ref.h> |
9119a41e JK |
12 | #include <linux/list.h> |
13 | #include <linux/kref.h> | |
ca5999fd | 14 | #include <linux/pgtable.h> |
d92bbc27 | 15 | #include <linux/gfp.h> |
f6191471 | 16 | #include <linux/userfaultfd_k.h> |
4e950f6f | 17 | |
e9ea0e2d AM |
18 | struct ctl_table; |
19 | struct user_struct; | |
24669e58 | 20 | struct mmu_gather; |
a4a00b45 | 21 | struct node; |
e9ea0e2d | 22 | |
691cdf01 | 23 | #ifndef CONFIG_ARCH_HAS_HUGEPD |
e2299292 AK |
24 | typedef struct { unsigned long pd; } hugepd_t; |
25 | #define is_hugepd(hugepd) (0) | |
26 | #define __hugepd(x) ((hugepd_t) { (x) }) | |
e2299292 AK |
27 | #endif |
28 | ||
1da177e4 LT |
29 | #ifdef CONFIG_HUGETLB_PAGE |
30 | ||
31 | #include <linux/mempolicy.h> | |
516dffdc | 32 | #include <linux/shm.h> |
63551ae0 | 33 | #include <asm/tlbflush.h> |
1da177e4 | 34 | |
cd39d4e9 MS |
35 | /* |
36 | * For HugeTLB page, there are more metadata to save in the struct page. But | |
37 | * the head struct page cannot meet our needs, so we have to abuse other tail | |
dad6a5eb | 38 | * struct page to store the metadata. |
cd39d4e9 | 39 | */ |
dad6a5eb | 40 | #define __NR_USED_SUBPAGE 3 |
cd39d4e9 | 41 | |
90481622 DG |
42 | struct hugepage_subpool { |
43 | spinlock_t lock; | |
44 | long count; | |
c6a91820 MK |
45 | long max_hpages; /* Maximum huge pages or -1 if no maximum. */ |
46 | long used_hpages; /* Used count against maximum, includes */ | |
06c88398 | 47 | /* both allocated and reserved pages. */ |
c6a91820 MK |
48 | struct hstate *hstate; |
49 | long min_hpages; /* Minimum huge pages or -1 if no minimum. */ | |
50 | long rsv_hpages; /* Pages reserved against global pool to */ | |
6c26d310 | 51 | /* satisfy minimum size. */ |
90481622 DG |
52 | }; |
53 | ||
9119a41e JK |
54 | struct resv_map { |
55 | struct kref refs; | |
7b24d861 | 56 | spinlock_t lock; |
9119a41e | 57 | struct list_head regions; |
5e911373 MK |
58 | long adds_in_progress; |
59 | struct list_head region_cache; | |
60 | long region_cache_count; | |
e9fe92ae MA |
61 | #ifdef CONFIG_CGROUP_HUGETLB |
62 | /* | |
63 | * On private mappings, the counter to uncharge reservations is stored | |
64 | * here. If these fields are 0, then either the mapping is shared, or | |
65 | * cgroup accounting is disabled for this resv_map. | |
66 | */ | |
67 | struct page_counter *reservation_counter; | |
68 | unsigned long pages_per_hpage; | |
69 | struct cgroup_subsys_state *css; | |
70 | #endif | |
9119a41e | 71 | }; |
075a61d0 MA |
72 | |
73 | /* | |
74 | * Region tracking -- allows tracking of reservations and instantiated pages | |
75 | * across the pages in a mapping. | |
76 | * | |
77 | * The region data structures are embedded into a resv_map and protected | |
78 | * by a resv_map's lock. The set of regions within the resv_map represent | |
79 | * reservations for huge pages, or huge pages that have already been | |
80 | * instantiated within the map. The from and to elements are huge page | |
06c88398 | 81 | * indices into the associated mapping. from indicates the starting index |
075a61d0 MA |
82 | * of the region. to represents the first index past the end of the region. |
83 | * | |
84 | * For example, a file region structure with from == 0 and to == 4 represents | |
85 | * four huge pages in a mapping. It is important to note that the to element | |
86 | * represents the first element past the end of the region. This is used in | |
87 | * arithmetic as 4(to) - 0(from) = 4 huge pages in the region. | |
88 | * | |
89 | * Interval notation of the form [from, to) will be used to indicate that | |
90 | * the endpoint from is inclusive and to is exclusive. | |
91 | */ | |
92 | struct file_region { | |
93 | struct list_head link; | |
94 | long from; | |
95 | long to; | |
96 | #ifdef CONFIG_CGROUP_HUGETLB | |
97 | /* | |
98 | * On shared mappings, each reserved region appears as a struct | |
99 | * file_region in resv_map. These fields hold the info needed to | |
100 | * uncharge each reservation. | |
101 | */ | |
102 | struct page_counter *reservation_counter; | |
103 | struct cgroup_subsys_state *css; | |
104 | #endif | |
105 | }; | |
106 | ||
8d9bfb26 MK |
107 | struct hugetlb_vma_lock { |
108 | struct kref refs; | |
109 | struct rw_semaphore rw_sema; | |
110 | struct vm_area_struct *vma; | |
111 | }; | |
112 | ||
9119a41e JK |
113 | extern struct resv_map *resv_map_alloc(void); |
114 | void resv_map_release(struct kref *ref); | |
115 | ||
c3f38a38 AK |
116 | extern spinlock_t hugetlb_lock; |
117 | extern int hugetlb_max_hstate __read_mostly; | |
118 | #define for_each_hstate(h) \ | |
119 | for ((h) = hstates; (h) < &hstates[hugetlb_max_hstate]; (h)++) | |
120 | ||
7ca02d0a MK |
121 | struct hugepage_subpool *hugepage_new_subpool(struct hstate *h, long max_hpages, |
122 | long min_hpages); | |
90481622 DG |
123 | void hugepage_put_subpool(struct hugepage_subpool *spool); |
124 | ||
8d9bfb26 | 125 | void hugetlb_dup_vma_private(struct vm_area_struct *vma); |
550a7d60 | 126 | void clear_vma_resv_huge_pages(struct vm_area_struct *vma); |
550a7d60 MA |
127 | int move_hugetlb_page_tables(struct vm_area_struct *vma, |
128 | struct vm_area_struct *new_vma, | |
129 | unsigned long old_addr, unsigned long new_addr, | |
130 | unsigned long len); | |
bc70fbf2 PX |
131 | int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, |
132 | struct vm_area_struct *, struct vm_area_struct *); | |
57a196a5 MK |
133 | struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, |
134 | unsigned long address, unsigned int flags); | |
28a35716 ML |
135 | long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *, |
136 | struct page **, struct vm_area_struct **, | |
87ffc118 AA |
137 | unsigned long *, unsigned long *, long, unsigned int, |
138 | int *); | |
04f2cbe3 | 139 | void unmap_hugepage_range(struct vm_area_struct *, |
05e90bd0 PX |
140 | unsigned long, unsigned long, struct page *, |
141 | zap_flags_t); | |
d833352a MG |
142 | void __unmap_hugepage_range_final(struct mmu_gather *tlb, |
143 | struct vm_area_struct *vma, | |
144 | unsigned long start, unsigned long end, | |
05e90bd0 | 145 | struct page *ref_page, zap_flags_t zap_flags); |
e1759c21 | 146 | void hugetlb_report_meminfo(struct seq_file *); |
7981593b | 147 | int hugetlb_report_node_meminfo(char *buf, int len, int nid); |
dcadcf1c | 148 | void hugetlb_show_meminfo_node(int nid); |
1da177e4 | 149 | unsigned long hugetlb_total_pages(void); |
2b740303 | 150 | vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, |
788c7df4 | 151 | unsigned long address, unsigned int flags); |
714c1891 | 152 | #ifdef CONFIG_USERFAULTFD |
61c50040 | 153 | int hugetlb_mfill_atomic_pte(pte_t *dst_pte, |
a734991c AR |
154 | struct vm_area_struct *dst_vma, |
155 | unsigned long dst_addr, | |
156 | unsigned long src_addr, | |
d9712937 | 157 | uffd_flags_t flags, |
0169fd51 | 158 | struct folio **foliop); |
714c1891 | 159 | #endif /* CONFIG_USERFAULTFD */ |
33b8f84a | 160 | bool hugetlb_reserve_pages(struct inode *inode, long from, long to, |
5a6fe125 | 161 | struct vm_area_struct *vma, |
ca16d140 | 162 | vm_flags_t vm_flags); |
b5cec28d MK |
163 | long hugetlb_unreserve_pages(struct inode *inode, long start, long end, |
164 | long freed); | |
9747b9e9 | 165 | bool isolate_hugetlb(struct folio *folio, struct list_head *list); |
04bac040 | 166 | int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison); |
e591ef7d NH |
167 | int get_huge_page_for_hwpoison(unsigned long pfn, int flags, |
168 | bool *migratable_cleared); | |
ea8e72f4 | 169 | void folio_putback_active_hugetlb(struct folio *folio); |
345c62d1 | 170 | void move_hugetlb_state(struct folio *old_folio, struct folio *new_folio, int reason); |
8f1d26d0 | 171 | void free_huge_page(struct page *page); |
72e2936c | 172 | void hugetlb_fix_reserve_counts(struct inode *inode); |
c672c7f2 | 173 | extern struct mutex *hugetlb_fault_mutex_table; |
188b04a7 | 174 | u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx); |
1da177e4 | 175 | |
aec44e0f PX |
176 | pte_t *huge_pmd_share(struct mm_struct *mm, struct vm_area_struct *vma, |
177 | unsigned long addr, pud_t *pud); | |
3212b535 | 178 | |
c0d0381a MK |
179 | struct address_space *hugetlb_page_mapping_lock_write(struct page *hpage); |
180 | ||
1da177e4 | 181 | extern int sysctl_hugetlb_shm_group; |
53ba51d2 | 182 | extern struct list_head huge_boot_pages; |
1da177e4 | 183 | |
63551ae0 DG |
184 | /* arch callbacks */ |
185 | ||
f7243924 HD |
186 | #ifndef CONFIG_HIGHPTE |
187 | /* | |
188 | * pte_offset_huge() and pte_alloc_huge() are helpers for those architectures | |
189 | * which may go down to the lowest PTE level in their huge_pte_offset() and | |
190 | * huge_pte_alloc(): to avoid reliance on pte_offset_map() without pte_unmap(). | |
191 | */ | |
192 | static inline pte_t *pte_offset_huge(pmd_t *pmd, unsigned long address) | |
193 | { | |
194 | return pte_offset_kernel(pmd, address); | |
195 | } | |
196 | static inline pte_t *pte_alloc_huge(struct mm_struct *mm, pmd_t *pmd, | |
197 | unsigned long address) | |
198 | { | |
199 | return pte_alloc(mm, pmd) ? NULL : pte_offset_huge(pmd, address); | |
200 | } | |
201 | #endif | |
202 | ||
aec44e0f | 203 | pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, |
a5516438 | 204 | unsigned long addr, unsigned long sz); |
fe7d4c6d PX |
205 | /* |
206 | * huge_pte_offset(): Walk the hugetlb pgtable until the last level PTE. | |
207 | * Returns the pte_t* if found, or NULL if the address is not mapped. | |
208 | * | |
9c67a207 PX |
209 | * IMPORTANT: we should normally not directly call this function, instead |
210 | * this is only a common interface to implement arch-specific | |
211 | * walker. Please use hugetlb_walk() instead, because that will attempt to | |
212 | * verify the locking for you. | |
213 | * | |
fe7d4c6d PX |
214 | * Since this function will walk all the pgtable pages (including not only |
215 | * high-level pgtable page, but also PUD entry that can be unshared | |
216 | * concurrently for VM_SHARED), the caller of this function should be | |
217 | * responsible of its thread safety. One can follow this rule: | |
218 | * | |
219 | * (1) For private mappings: pmd unsharing is not possible, so holding the | |
220 | * mmap_lock for either read or write is sufficient. Most callers | |
221 | * already hold the mmap_lock, so normally, no special action is | |
222 | * required. | |
223 | * | |
224 | * (2) For shared mappings: pmd unsharing is possible (so the PUD-ranged | |
225 | * pgtable page can go away from under us! It can be done by a pmd | |
226 | * unshare with a follow up munmap() on the other process), then we | |
227 | * need either: | |
228 | * | |
229 | * (2.1) hugetlb vma lock read or write held, to make sure pmd unshare | |
230 | * won't happen upon the range (it also makes sure the pte_t we | |
231 | * read is the right and stable one), or, | |
232 | * | |
233 | * (2.2) hugetlb mapping i_mmap_rwsem lock held read or write, to make | |
234 | * sure even if unshare happened the racy unmap() will wait until | |
235 | * i_mmap_rwsem is released. | |
236 | * | |
237 | * Option (2.1) is the safest, which guarantees pte stability from pmd | |
238 | * sharing pov, until the vma lock released. Option (2.2) doesn't protect | |
239 | * a concurrent pmd unshare, but it makes sure the pgtable page is safe to | |
240 | * access. | |
241 | */ | |
7868a208 PA |
242 | pte_t *huge_pte_offset(struct mm_struct *mm, |
243 | unsigned long addr, unsigned long sz); | |
e95a9851 | 244 | unsigned long hugetlb_mask_last_page(struct hstate *h); |
34ae204f | 245 | int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma, |
4ddb4d91 | 246 | unsigned long addr, pte_t *ptep); |
017b1660 MK |
247 | void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma, |
248 | unsigned long *start, unsigned long *end); | |
faaa5b62 | 249 | |
8d9bfb26 MK |
250 | void hugetlb_vma_lock_read(struct vm_area_struct *vma); |
251 | void hugetlb_vma_unlock_read(struct vm_area_struct *vma); | |
252 | void hugetlb_vma_lock_write(struct vm_area_struct *vma); | |
253 | void hugetlb_vma_unlock_write(struct vm_area_struct *vma); | |
254 | int hugetlb_vma_trylock_write(struct vm_area_struct *vma); | |
255 | void hugetlb_vma_assert_locked(struct vm_area_struct *vma); | |
256 | void hugetlb_vma_lock_release(struct kref *kref); | |
257 | ||
63551ae0 | 258 | int pmd_huge(pmd_t pmd); |
c2febafc | 259 | int pud_huge(pud_t pud); |
a79390f5 | 260 | long hugetlb_change_protection(struct vm_area_struct *vma, |
5a90d5a1 PX |
261 | unsigned long address, unsigned long end, pgprot_t newprot, |
262 | unsigned long cp_flags); | |
63551ae0 | 263 | |
d5ed7444 | 264 | bool is_hugetlb_entry_migration(pte_t pte); |
6dfeaff9 | 265 | void hugetlb_unshare_all_pmds(struct vm_area_struct *vma); |
ab5ac90a | 266 | |
1da177e4 LT |
267 | #else /* !CONFIG_HUGETLB_PAGE */ |
268 | ||
8d9bfb26 | 269 | static inline void hugetlb_dup_vma_private(struct vm_area_struct *vma) |
a1e78772 MG |
270 | { |
271 | } | |
272 | ||
550a7d60 MA |
273 | static inline void clear_vma_resv_huge_pages(struct vm_area_struct *vma) |
274 | { | |
275 | } | |
276 | ||
1da177e4 LT |
277 | static inline unsigned long hugetlb_total_pages(void) |
278 | { | |
279 | return 0; | |
280 | } | |
281 | ||
c0d0381a MK |
282 | static inline struct address_space *hugetlb_page_mapping_lock_write( |
283 | struct page *hpage) | |
284 | { | |
285 | return NULL; | |
286 | } | |
287 | ||
34ae204f MK |
288 | static inline int huge_pmd_unshare(struct mm_struct *mm, |
289 | struct vm_area_struct *vma, | |
4ddb4d91 | 290 | unsigned long addr, pte_t *ptep) |
017b1660 MK |
291 | { |
292 | return 0; | |
293 | } | |
294 | ||
295 | static inline void adjust_range_if_pmd_sharing_possible( | |
296 | struct vm_area_struct *vma, | |
297 | unsigned long *start, unsigned long *end) | |
298 | { | |
299 | } | |
300 | ||
57a196a5 MK |
301 | static inline struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, |
302 | unsigned long address, unsigned int flags) | |
303 | { | |
304 | BUILD_BUG(); /* should never be compiled in if !CONFIG_HUGETLB_PAGE*/ | |
305 | } | |
306 | ||
1f9dccb2 MK |
307 | static inline long follow_hugetlb_page(struct mm_struct *mm, |
308 | struct vm_area_struct *vma, struct page **pages, | |
309 | struct vm_area_struct **vmas, unsigned long *position, | |
310 | unsigned long *nr_pages, long i, unsigned int flags, | |
311 | int *nonblocking) | |
312 | { | |
313 | BUG(); | |
314 | return 0; | |
315 | } | |
316 | ||
1f9dccb2 | 317 | static inline int copy_hugetlb_page_range(struct mm_struct *dst, |
bc70fbf2 PX |
318 | struct mm_struct *src, |
319 | struct vm_area_struct *dst_vma, | |
320 | struct vm_area_struct *src_vma) | |
1f9dccb2 MK |
321 | { |
322 | BUG(); | |
323 | return 0; | |
324 | } | |
325 | ||
550a7d60 MA |
326 | static inline int move_hugetlb_page_tables(struct vm_area_struct *vma, |
327 | struct vm_area_struct *new_vma, | |
328 | unsigned long old_addr, | |
329 | unsigned long new_addr, | |
330 | unsigned long len) | |
331 | { | |
332 | BUG(); | |
333 | return 0; | |
334 | } | |
335 | ||
e1759c21 AD |
336 | static inline void hugetlb_report_meminfo(struct seq_file *m) |
337 | { | |
338 | } | |
1f9dccb2 | 339 | |
7981593b | 340 | static inline int hugetlb_report_node_meminfo(char *buf, int len, int nid) |
1f9dccb2 MK |
341 | { |
342 | return 0; | |
343 | } | |
344 | ||
dcadcf1c | 345 | static inline void hugetlb_show_meminfo_node(int nid) |
949f7ec5 DR |
346 | { |
347 | } | |
1f9dccb2 | 348 | |
1f9dccb2 MK |
349 | static inline int prepare_hugepage_range(struct file *file, |
350 | unsigned long addr, unsigned long len) | |
351 | { | |
352 | return -EINVAL; | |
353 | } | |
354 | ||
8d9bfb26 MK |
355 | static inline void hugetlb_vma_lock_read(struct vm_area_struct *vma) |
356 | { | |
357 | } | |
358 | ||
359 | static inline void hugetlb_vma_unlock_read(struct vm_area_struct *vma) | |
360 | { | |
361 | } | |
362 | ||
363 | static inline void hugetlb_vma_lock_write(struct vm_area_struct *vma) | |
364 | { | |
365 | } | |
366 | ||
367 | static inline void hugetlb_vma_unlock_write(struct vm_area_struct *vma) | |
368 | { | |
369 | } | |
370 | ||
371 | static inline int hugetlb_vma_trylock_write(struct vm_area_struct *vma) | |
372 | { | |
373 | return 1; | |
374 | } | |
375 | ||
376 | static inline void hugetlb_vma_assert_locked(struct vm_area_struct *vma) | |
377 | { | |
378 | } | |
379 | ||
1f9dccb2 MK |
380 | static inline int pmd_huge(pmd_t pmd) |
381 | { | |
382 | return 0; | |
383 | } | |
384 | ||
385 | static inline int pud_huge(pud_t pud) | |
386 | { | |
387 | return 0; | |
388 | } | |
389 | ||
390 | static inline int is_hugepage_only_range(struct mm_struct *mm, | |
391 | unsigned long addr, unsigned long len) | |
392 | { | |
393 | return 0; | |
394 | } | |
395 | ||
396 | static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb, | |
397 | unsigned long addr, unsigned long end, | |
398 | unsigned long floor, unsigned long ceiling) | |
399 | { | |
400 | BUG(); | |
401 | } | |
402 | ||
714c1891 | 403 | #ifdef CONFIG_USERFAULTFD |
61c50040 | 404 | static inline int hugetlb_mfill_atomic_pte(pte_t *dst_pte, |
a734991c AR |
405 | struct vm_area_struct *dst_vma, |
406 | unsigned long dst_addr, | |
407 | unsigned long src_addr, | |
d9712937 | 408 | uffd_flags_t flags, |
0169fd51 | 409 | struct folio **foliop) |
1f9dccb2 MK |
410 | { |
411 | BUG(); | |
412 | return 0; | |
413 | } | |
714c1891 | 414 | #endif /* CONFIG_USERFAULTFD */ |
1f9dccb2 MK |
415 | |
416 | static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr, | |
417 | unsigned long sz) | |
418 | { | |
419 | return NULL; | |
420 | } | |
24669e58 | 421 | |
9747b9e9 | 422 | static inline bool isolate_hugetlb(struct folio *folio, struct list_head *list) |
f40386a4 | 423 | { |
9747b9e9 | 424 | return false; |
f40386a4 | 425 | } |
1da177e4 | 426 | |
04bac040 | 427 | static inline int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison) |
25182f05 NH |
428 | { |
429 | return 0; | |
430 | } | |
431 | ||
e591ef7d NH |
432 | static inline int get_huge_page_for_hwpoison(unsigned long pfn, int flags, |
433 | bool *migratable_cleared) | |
405ce051 NH |
434 | { |
435 | return 0; | |
436 | } | |
437 | ||
ea8e72f4 | 438 | static inline void folio_putback_active_hugetlb(struct folio *folio) |
1f9dccb2 MK |
439 | { |
440 | } | |
441 | ||
345c62d1 SK |
442 | static inline void move_hugetlb_state(struct folio *old_folio, |
443 | struct folio *new_folio, int reason) | |
1f9dccb2 MK |
444 | { |
445 | } | |
446 | ||
a79390f5 | 447 | static inline long hugetlb_change_protection( |
1f9dccb2 | 448 | struct vm_area_struct *vma, unsigned long address, |
5a90d5a1 PX |
449 | unsigned long end, pgprot_t newprot, |
450 | unsigned long cp_flags) | |
7da4d641 PZ |
451 | { |
452 | return 0; | |
453 | } | |
8f860591 | 454 | |
d833352a MG |
455 | static inline void __unmap_hugepage_range_final(struct mmu_gather *tlb, |
456 | struct vm_area_struct *vma, unsigned long start, | |
05e90bd0 PX |
457 | unsigned long end, struct page *ref_page, |
458 | zap_flags_t zap_flags) | |
d833352a MG |
459 | { |
460 | BUG(); | |
461 | } | |
462 | ||
a953e772 | 463 | static inline vm_fault_t hugetlb_fault(struct mm_struct *mm, |
1f9dccb2 MK |
464 | struct vm_area_struct *vma, unsigned long address, |
465 | unsigned int flags) | |
a953e772 SJ |
466 | { |
467 | BUG(); | |
468 | return 0; | |
469 | } | |
24669e58 | 470 | |
6dfeaff9 PX |
471 | static inline void hugetlb_unshare_all_pmds(struct vm_area_struct *vma) { } |
472 | ||
1da177e4 | 473 | #endif /* !CONFIG_HUGETLB_PAGE */ |
f30c59e9 AK |
474 | /* |
475 | * hugepages at page global directory. If arch support | |
476 | * hugepages at pgd level, they need to define this. | |
477 | */ | |
478 | #ifndef pgd_huge | |
479 | #define pgd_huge(x) 0 | |
480 | #endif | |
c2febafc KS |
481 | #ifndef p4d_huge |
482 | #define p4d_huge(x) 0 | |
483 | #endif | |
f30c59e9 AK |
484 | |
485 | #ifndef pgd_write | |
486 | static inline int pgd_write(pgd_t pgd) | |
487 | { | |
488 | BUG(); | |
489 | return 0; | |
490 | } | |
491 | #endif | |
492 | ||
4e52780d EM |
493 | #define HUGETLB_ANON_FILE "anon_hugepage" |
494 | ||
6bfde05b EM |
495 | enum { |
496 | /* | |
497 | * The file will be used as an shm file so shmfs accounting rules | |
498 | * apply | |
499 | */ | |
500 | HUGETLB_SHMFS_INODE = 1, | |
4e52780d EM |
501 | /* |
502 | * The file is being created on the internal vfs mount and shmfs | |
503 | * accounting rules do not apply | |
504 | */ | |
505 | HUGETLB_ANONHUGE_INODE = 2, | |
6bfde05b EM |
506 | }; |
507 | ||
1da177e4 | 508 | #ifdef CONFIG_HUGETLBFS |
1da177e4 | 509 | struct hugetlbfs_sb_info { |
1da177e4 LT |
510 | long max_inodes; /* inodes allowed */ |
511 | long free_inodes; /* inodes free */ | |
512 | spinlock_t stat_lock; | |
a137e1cc | 513 | struct hstate *hstate; |
90481622 | 514 | struct hugepage_subpool *spool; |
4a25220d DH |
515 | kuid_t uid; |
516 | kgid_t gid; | |
517 | umode_t mode; | |
1da177e4 LT |
518 | }; |
519 | ||
1da177e4 LT |
520 | static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb) |
521 | { | |
522 | return sb->s_fs_info; | |
523 | } | |
524 | ||
da14c1e5 MAL |
525 | struct hugetlbfs_inode_info { |
526 | struct shared_policy policy; | |
527 | struct inode vfs_inode; | |
ff62a342 | 528 | unsigned int seals; |
da14c1e5 MAL |
529 | }; |
530 | ||
531 | static inline struct hugetlbfs_inode_info *HUGETLBFS_I(struct inode *inode) | |
532 | { | |
533 | return container_of(inode, struct hugetlbfs_inode_info, vfs_inode); | |
534 | } | |
535 | ||
4b6f5d20 | 536 | extern const struct file_operations hugetlbfs_file_operations; |
f0f37e2f | 537 | extern const struct vm_operations_struct hugetlb_vm_ops; |
af73e4d9 | 538 | struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct, |
83c1fd76 | 539 | int creat_flags, int page_size_log); |
1da177e4 | 540 | |
719ff321 | 541 | static inline bool is_file_hugepages(struct file *file) |
1da177e4 | 542 | { |
516dffdc | 543 | if (file->f_op == &hugetlbfs_file_operations) |
719ff321 | 544 | return true; |
516dffdc | 545 | |
719ff321 | 546 | return is_file_shm_hugepages(file); |
1da177e4 LT |
547 | } |
548 | ||
bb297bb2 CL |
549 | static inline struct hstate *hstate_inode(struct inode *i) |
550 | { | |
551 | return HUGETLBFS_SB(i->i_sb)->hstate; | |
552 | } | |
1da177e4 LT |
553 | #else /* !CONFIG_HUGETLBFS */ |
554 | ||
719ff321 | 555 | #define is_file_hugepages(file) false |
40716e29 | 556 | static inline struct file * |
af73e4d9 | 557 | hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag, |
83c1fd76 | 558 | int creat_flags, int page_size_log) |
e9ea0e2d AM |
559 | { |
560 | return ERR_PTR(-ENOSYS); | |
561 | } | |
1da177e4 | 562 | |
bb297bb2 CL |
563 | static inline struct hstate *hstate_inode(struct inode *i) |
564 | { | |
565 | return NULL; | |
566 | } | |
1da177e4 LT |
567 | #endif /* !CONFIG_HUGETLBFS */ |
568 | ||
d2ba27e8 AB |
569 | #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA |
570 | unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, | |
571 | unsigned long len, unsigned long pgoff, | |
572 | unsigned long flags); | |
573 | #endif /* HAVE_ARCH_HUGETLB_UNMAPPED_AREA */ | |
574 | ||
4b439e25 CL |
575 | unsigned long |
576 | generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, | |
577 | unsigned long len, unsigned long pgoff, | |
578 | unsigned long flags); | |
579 | ||
d6995da3 MK |
580 | /* |
581 | * huegtlb page specific state flags. These flags are located in page.private | |
582 | * of the hugetlb head page. Functions created via the below macros should be | |
583 | * used to manipulate these flags. | |
584 | * | |
585 | * HPG_restore_reserve - Set when a hugetlb page consumes a reservation at | |
586 | * allocation time. Cleared when page is fully instantiated. Free | |
587 | * routine checks flag to restore a reservation on error paths. | |
d95c0337 MK |
588 | * Synchronization: Examined or modified by code that knows it has |
589 | * the only reference to page. i.e. After allocation but before use | |
590 | * or when the page is being freed. | |
8f251a3d MK |
591 | * HPG_migratable - Set after a newly allocated page is added to the page |
592 | * cache and/or page tables. Indicates the page is a candidate for | |
593 | * migration. | |
d95c0337 MK |
594 | * Synchronization: Initially set after new page allocation with no |
595 | * locking. When examined and modified during migration processing | |
596 | * (isolate, migrate, putback) the hugetlb_lock is held. | |
161df60e | 597 | * HPG_temporary - Set on a page that is temporarily allocated from the buddy |
9157c311 MK |
598 | * allocator. Typically used for migration target pages when no pages |
599 | * are available in the pool. The hugetlb free page path will | |
600 | * immediately free pages with this flag set to the buddy allocator. | |
d95c0337 MK |
601 | * Synchronization: Can be set after huge page allocation from buddy when |
602 | * code knows it has only reference. All other examinations and | |
603 | * modifications require hugetlb_lock. | |
6c037149 | 604 | * HPG_freed - Set when page is on the free lists. |
d95c0337 | 605 | * Synchronization: hugetlb_lock held for examination and modification. |
ad2fa371 | 606 | * HPG_vmemmap_optimized - Set when the vmemmap pages of the page are freed. |
161df60e NH |
607 | * HPG_raw_hwp_unreliable - Set when the hugetlb page has a hwpoison sub-page |
608 | * that is not tracked by raw_hwp_page list. | |
d6995da3 MK |
609 | */ |
610 | enum hugetlb_page_flags { | |
611 | HPG_restore_reserve = 0, | |
8f251a3d | 612 | HPG_migratable, |
9157c311 | 613 | HPG_temporary, |
6c037149 | 614 | HPG_freed, |
ad2fa371 | 615 | HPG_vmemmap_optimized, |
161df60e | 616 | HPG_raw_hwp_unreliable, |
d6995da3 MK |
617 | __NR_HPAGEFLAGS, |
618 | }; | |
619 | ||
620 | /* | |
621 | * Macros to create test, set and clear function definitions for | |
622 | * hugetlb specific page flags. | |
623 | */ | |
624 | #ifdef CONFIG_HUGETLB_PAGE | |
625 | #define TESTHPAGEFLAG(uname, flname) \ | |
d03c376d SK |
626 | static __always_inline \ |
627 | bool folio_test_hugetlb_##flname(struct folio *folio) \ | |
628 | { void *private = &folio->private; \ | |
629 | return test_bit(HPG_##flname, private); \ | |
630 | } \ | |
d6995da3 MK |
631 | static inline int HPage##uname(struct page *page) \ |
632 | { return test_bit(HPG_##flname, &(page->private)); } | |
633 | ||
634 | #define SETHPAGEFLAG(uname, flname) \ | |
d03c376d SK |
635 | static __always_inline \ |
636 | void folio_set_hugetlb_##flname(struct folio *folio) \ | |
637 | { void *private = &folio->private; \ | |
638 | set_bit(HPG_##flname, private); \ | |
639 | } \ | |
d6995da3 MK |
640 | static inline void SetHPage##uname(struct page *page) \ |
641 | { set_bit(HPG_##flname, &(page->private)); } | |
642 | ||
643 | #define CLEARHPAGEFLAG(uname, flname) \ | |
d03c376d SK |
644 | static __always_inline \ |
645 | void folio_clear_hugetlb_##flname(struct folio *folio) \ | |
646 | { void *private = &folio->private; \ | |
647 | clear_bit(HPG_##flname, private); \ | |
648 | } \ | |
d6995da3 MK |
649 | static inline void ClearHPage##uname(struct page *page) \ |
650 | { clear_bit(HPG_##flname, &(page->private)); } | |
651 | #else | |
652 | #define TESTHPAGEFLAG(uname, flname) \ | |
d03c376d SK |
653 | static inline bool \ |
654 | folio_test_hugetlb_##flname(struct folio *folio) \ | |
655 | { return 0; } \ | |
d6995da3 MK |
656 | static inline int HPage##uname(struct page *page) \ |
657 | { return 0; } | |
658 | ||
659 | #define SETHPAGEFLAG(uname, flname) \ | |
d03c376d SK |
660 | static inline void \ |
661 | folio_set_hugetlb_##flname(struct folio *folio) \ | |
662 | { } \ | |
d6995da3 MK |
663 | static inline void SetHPage##uname(struct page *page) \ |
664 | { } | |
665 | ||
666 | #define CLEARHPAGEFLAG(uname, flname) \ | |
d03c376d SK |
667 | static inline void \ |
668 | folio_clear_hugetlb_##flname(struct folio *folio) \ | |
669 | { } \ | |
d6995da3 MK |
670 | static inline void ClearHPage##uname(struct page *page) \ |
671 | { } | |
672 | #endif | |
673 | ||
674 | #define HPAGEFLAG(uname, flname) \ | |
675 | TESTHPAGEFLAG(uname, flname) \ | |
676 | SETHPAGEFLAG(uname, flname) \ | |
677 | CLEARHPAGEFLAG(uname, flname) \ | |
678 | ||
679 | /* | |
680 | * Create functions associated with hugetlb page flags | |
681 | */ | |
682 | HPAGEFLAG(RestoreReserve, restore_reserve) | |
8f251a3d | 683 | HPAGEFLAG(Migratable, migratable) |
9157c311 | 684 | HPAGEFLAG(Temporary, temporary) |
6c037149 | 685 | HPAGEFLAG(Freed, freed) |
ad2fa371 | 686 | HPAGEFLAG(VmemmapOptimized, vmemmap_optimized) |
161df60e | 687 | HPAGEFLAG(RawHwpUnreliable, raw_hwp_unreliable) |
d6995da3 | 688 | |
a5516438 AK |
689 | #ifdef CONFIG_HUGETLB_PAGE |
690 | ||
a3437870 | 691 | #define HSTATE_NAME_LEN 32 |
a5516438 AK |
692 | /* Defines one hugetlb page size */ |
693 | struct hstate { | |
29383967 | 694 | struct mutex resize_lock; |
e8c5c824 LS |
695 | int next_nid_to_alloc; |
696 | int next_nid_to_free; | |
a5516438 | 697 | unsigned int order; |
79dfc695 | 698 | unsigned int demote_order; |
a5516438 AK |
699 | unsigned long mask; |
700 | unsigned long max_huge_pages; | |
701 | unsigned long nr_huge_pages; | |
702 | unsigned long free_huge_pages; | |
703 | unsigned long resv_huge_pages; | |
704 | unsigned long surplus_huge_pages; | |
705 | unsigned long nr_overcommit_huge_pages; | |
0edaecfa | 706 | struct list_head hugepage_activelist; |
a5516438 | 707 | struct list_head hugepage_freelists[MAX_NUMNODES]; |
b5389086 | 708 | unsigned int max_huge_pages_node[MAX_NUMNODES]; |
a5516438 AK |
709 | unsigned int nr_huge_pages_node[MAX_NUMNODES]; |
710 | unsigned int free_huge_pages_node[MAX_NUMNODES]; | |
711 | unsigned int surplus_huge_pages_node[MAX_NUMNODES]; | |
abb8206c AK |
712 | #ifdef CONFIG_CGROUP_HUGETLB |
713 | /* cgroup control files */ | |
f4776199 MA |
714 | struct cftype cgroup_files_dfl[8]; |
715 | struct cftype cgroup_files_legacy[10]; | |
abb8206c | 716 | #endif |
a3437870 | 717 | char name[HSTATE_NAME_LEN]; |
a5516438 AK |
718 | }; |
719 | ||
53ba51d2 JT |
720 | struct huge_bootmem_page { |
721 | struct list_head list; | |
722 | struct hstate *hstate; | |
723 | }; | |
724 | ||
ae37c7ff | 725 | int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list); |
d0ce0e47 | 726 | struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, |
70c3547e | 727 | unsigned long addr, int avoid_reserve); |
e37d3e83 | 728 | struct folio *alloc_hugetlb_folio_nodemask(struct hstate *h, int preferred_nid, |
d92bbc27 | 729 | nodemask_t *nmask, gfp_t gfp_mask); |
d0ce0e47 | 730 | struct folio *alloc_hugetlb_folio_vma(struct hstate *h, struct vm_area_struct *vma, |
389c8178 | 731 | unsigned long address); |
9b91c0e2 | 732 | int hugetlb_add_to_page_cache(struct folio *folio, struct address_space *mapping, |
ab76ad54 | 733 | pgoff_t idx); |
846be085 | 734 | void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma, |
d2d7bb44 | 735 | unsigned long address, struct folio *folio); |
bf50bab2 | 736 | |
53ba51d2 | 737 | /* arch callback */ |
b5389086 ZY |
738 | int __init __alloc_bootmem_huge_page(struct hstate *h, int nid); |
739 | int __init alloc_bootmem_huge_page(struct hstate *h, int nid); | |
740 | bool __init hugetlb_node_alloc_supported(void); | |
53ba51d2 | 741 | |
e5ff2159 | 742 | void __init hugetlb_add_hstate(unsigned order); |
ae94da89 | 743 | bool __init arch_hugetlb_valid_size(unsigned long size); |
e5ff2159 AK |
744 | struct hstate *size_to_hstate(unsigned long size); |
745 | ||
746 | #ifndef HUGE_MAX_HSTATE | |
747 | #define HUGE_MAX_HSTATE 1 | |
748 | #endif | |
749 | ||
750 | extern struct hstate hstates[HUGE_MAX_HSTATE]; | |
751 | extern unsigned int default_hstate_idx; | |
752 | ||
753 | #define default_hstate (hstates[default_hstate_idx]) | |
a5516438 | 754 | |
149562f7 SK |
755 | static inline struct hugepage_subpool *hugetlb_folio_subpool(struct folio *folio) |
756 | { | |
dad6a5eb | 757 | return folio->_hugetlb_subpool; |
149562f7 SK |
758 | } |
759 | ||
d6995da3 | 760 | /* |
dad6a5eb | 761 | * hugetlb page subpool pointer located in hpage[2].hugetlb_subpool |
d6995da3 MK |
762 | */ |
763 | static inline struct hugepage_subpool *hugetlb_page_subpool(struct page *hpage) | |
764 | { | |
149562f7 SK |
765 | return hugetlb_folio_subpool(page_folio(hpage)); |
766 | } | |
767 | ||
768 | static inline void hugetlb_set_folio_subpool(struct folio *folio, | |
769 | struct hugepage_subpool *subpool) | |
770 | { | |
dad6a5eb | 771 | folio->_hugetlb_subpool = subpool; |
d6995da3 MK |
772 | } |
773 | ||
774 | static inline void hugetlb_set_page_subpool(struct page *hpage, | |
775 | struct hugepage_subpool *subpool) | |
776 | { | |
149562f7 | 777 | hugetlb_set_folio_subpool(page_folio(hpage), subpool); |
d6995da3 MK |
778 | } |
779 | ||
a5516438 AK |
780 | static inline struct hstate *hstate_file(struct file *f) |
781 | { | |
496ad9aa | 782 | return hstate_inode(file_inode(f)); |
a5516438 AK |
783 | } |
784 | ||
af73e4d9 NH |
785 | static inline struct hstate *hstate_sizelog(int page_size_log) |
786 | { | |
787 | if (!page_size_log) | |
788 | return &default_hstate; | |
97ad2be1 | 789 | |
ec4288fe MK |
790 | if (page_size_log < BITS_PER_LONG) |
791 | return size_to_hstate(1UL << page_size_log); | |
792 | ||
793 | return NULL; | |
af73e4d9 NH |
794 | } |
795 | ||
a137e1cc | 796 | static inline struct hstate *hstate_vma(struct vm_area_struct *vma) |
a5516438 | 797 | { |
a137e1cc | 798 | return hstate_file(vma->vm_file); |
a5516438 AK |
799 | } |
800 | ||
6213834c | 801 | static inline unsigned long huge_page_size(const struct hstate *h) |
a5516438 AK |
802 | { |
803 | return (unsigned long)PAGE_SIZE << h->order; | |
804 | } | |
805 | ||
08fba699 MG |
806 | extern unsigned long vma_kernel_pagesize(struct vm_area_struct *vma); |
807 | ||
3340289d MG |
808 | extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma); |
809 | ||
a5516438 AK |
810 | static inline unsigned long huge_page_mask(struct hstate *h) |
811 | { | |
812 | return h->mask; | |
813 | } | |
814 | ||
815 | static inline unsigned int huge_page_order(struct hstate *h) | |
816 | { | |
817 | return h->order; | |
818 | } | |
819 | ||
820 | static inline unsigned huge_page_shift(struct hstate *h) | |
821 | { | |
822 | return h->order + PAGE_SHIFT; | |
823 | } | |
824 | ||
bae7f4ae LC |
825 | static inline bool hstate_is_gigantic(struct hstate *h) |
826 | { | |
23baf831 | 827 | return huge_page_order(h) > MAX_ORDER; |
bae7f4ae LC |
828 | } |
829 | ||
6213834c | 830 | static inline unsigned int pages_per_huge_page(const struct hstate *h) |
a5516438 AK |
831 | { |
832 | return 1 << h->order; | |
833 | } | |
834 | ||
835 | static inline unsigned int blocks_per_huge_page(struct hstate *h) | |
836 | { | |
837 | return huge_page_size(h) / 512; | |
838 | } | |
839 | ||
840 | #include <asm/hugetlb.h> | |
841 | ||
b0eae98c AK |
842 | #ifndef is_hugepage_only_range |
843 | static inline int is_hugepage_only_range(struct mm_struct *mm, | |
844 | unsigned long addr, unsigned long len) | |
845 | { | |
846 | return 0; | |
847 | } | |
848 | #define is_hugepage_only_range is_hugepage_only_range | |
849 | #endif | |
850 | ||
5be99343 AK |
851 | #ifndef arch_clear_hugepage_flags |
852 | static inline void arch_clear_hugepage_flags(struct page *page) { } | |
853 | #define arch_clear_hugepage_flags arch_clear_hugepage_flags | |
854 | #endif | |
855 | ||
d9ed9faa | 856 | #ifndef arch_make_huge_pte |
79c1c594 CL |
857 | static inline pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, |
858 | vm_flags_t flags) | |
d9ed9faa | 859 | { |
16785bd7 | 860 | return pte_mkhuge(entry); |
d9ed9faa CM |
861 | } |
862 | #endif | |
863 | ||
e51da3a9 SK |
864 | static inline struct hstate *folio_hstate(struct folio *folio) |
865 | { | |
866 | VM_BUG_ON_FOLIO(!folio_test_hugetlb(folio), folio); | |
867 | return size_to_hstate(folio_size(folio)); | |
868 | } | |
869 | ||
e5ff2159 AK |
870 | static inline struct hstate *page_hstate(struct page *page) |
871 | { | |
e51da3a9 | 872 | return folio_hstate(page_folio(page)); |
e5ff2159 AK |
873 | } |
874 | ||
aa50d3a7 AK |
875 | static inline unsigned hstate_index_to_shift(unsigned index) |
876 | { | |
877 | return hstates[index].order + PAGE_SHIFT; | |
878 | } | |
879 | ||
972dc4de AK |
880 | static inline int hstate_index(struct hstate *h) |
881 | { | |
882 | return h - hstates; | |
883 | } | |
884 | ||
c3114a84 | 885 | extern int dissolve_free_huge_page(struct page *page); |
082d5b6b GS |
886 | extern int dissolve_free_huge_pages(unsigned long start_pfn, |
887 | unsigned long end_pfn); | |
e693de18 | 888 | |
161df60e | 889 | #ifdef CONFIG_MEMORY_FAILURE |
2ff6cece | 890 | extern void folio_clear_hugetlb_hwpoison(struct folio *folio); |
161df60e | 891 | #else |
2ff6cece | 892 | static inline void folio_clear_hugetlb_hwpoison(struct folio *folio) |
161df60e NH |
893 | { |
894 | } | |
895 | #endif | |
896 | ||
c177c81e | 897 | #ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION |
e693de18 AK |
898 | #ifndef arch_hugetlb_migration_supported |
899 | static inline bool arch_hugetlb_migration_supported(struct hstate *h) | |
900 | { | |
94310cbc | 901 | if ((huge_page_shift(h) == PMD_SHIFT) || |
9b553bf5 AK |
902 | (huge_page_shift(h) == PUD_SHIFT) || |
903 | (huge_page_shift(h) == PGDIR_SHIFT)) | |
94310cbc AK |
904 | return true; |
905 | else | |
906 | return false; | |
e693de18 AK |
907 | } |
908 | #endif | |
c177c81e | 909 | #else |
e693de18 AK |
910 | static inline bool arch_hugetlb_migration_supported(struct hstate *h) |
911 | { | |
d70c17d4 | 912 | return false; |
e693de18 | 913 | } |
c177c81e | 914 | #endif |
e693de18 AK |
915 | |
916 | static inline bool hugepage_migration_supported(struct hstate *h) | |
917 | { | |
918 | return arch_hugetlb_migration_supported(h); | |
83467efb | 919 | } |
c8721bbb | 920 | |
7ed2c31d AK |
921 | /* |
922 | * Movability check is different as compared to migration check. | |
923 | * It determines whether or not a huge page should be placed on | |
924 | * movable zone or not. Movability of any huge page should be | |
925 | * required only if huge page size is supported for migration. | |
06c88398 | 926 | * There won't be any reason for the huge page to be movable if |
7ed2c31d AK |
927 | * it is not migratable to start with. Also the size of the huge |
928 | * page should be large enough to be placed under a movable zone | |
929 | * and still feasible enough to be migratable. Just the presence | |
930 | * in movable zone does not make the migration feasible. | |
931 | * | |
932 | * So even though large huge page sizes like the gigantic ones | |
933 | * are migratable they should not be movable because its not | |
934 | * feasible to migrate them from movable zone. | |
935 | */ | |
936 | static inline bool hugepage_movable_supported(struct hstate *h) | |
937 | { | |
938 | if (!hugepage_migration_supported(h)) | |
939 | return false; | |
940 | ||
941 | if (hstate_is_gigantic(h)) | |
942 | return false; | |
943 | return true; | |
944 | } | |
945 | ||
d92bbc27 JK |
946 | /* Movability of hugepages depends on migration support. */ |
947 | static inline gfp_t htlb_alloc_mask(struct hstate *h) | |
948 | { | |
949 | if (hugepage_movable_supported(h)) | |
950 | return GFP_HIGHUSER_MOVABLE; | |
951 | else | |
952 | return GFP_HIGHUSER; | |
953 | } | |
954 | ||
19fc7bed JK |
955 | static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask) |
956 | { | |
957 | gfp_t modified_mask = htlb_alloc_mask(h); | |
958 | ||
959 | /* Some callers might want to enforce node */ | |
960 | modified_mask |= (gfp_mask & __GFP_THISNODE); | |
961 | ||
41b4dc14 JK |
962 | modified_mask |= (gfp_mask & __GFP_NOWARN); |
963 | ||
19fc7bed JK |
964 | return modified_mask; |
965 | } | |
966 | ||
cb900f41 KS |
967 | static inline spinlock_t *huge_pte_lockptr(struct hstate *h, |
968 | struct mm_struct *mm, pte_t *pte) | |
969 | { | |
970 | if (huge_page_size(h) == PMD_SIZE) | |
971 | return pmd_lockptr(mm, (pmd_t *) pte); | |
972 | VM_BUG_ON(huge_page_size(h) == PAGE_SIZE); | |
973 | return &mm->page_table_lock; | |
974 | } | |
975 | ||
2531c8cf DD |
976 | #ifndef hugepages_supported |
977 | /* | |
978 | * Some platform decide whether they support huge pages at boot | |
979 | * time. Some of them, such as powerpc, set HPAGE_SHIFT to 0 | |
980 | * when there is no such support | |
981 | */ | |
982 | #define hugepages_supported() (HPAGE_SHIFT != 0) | |
983 | #endif | |
457c1b27 | 984 | |
5d317b2b NH |
985 | void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm); |
986 | ||
13db8c50 LZ |
987 | static inline void hugetlb_count_init(struct mm_struct *mm) |
988 | { | |
989 | atomic_long_set(&mm->hugetlb_usage, 0); | |
990 | } | |
991 | ||
5d317b2b NH |
992 | static inline void hugetlb_count_add(long l, struct mm_struct *mm) |
993 | { | |
994 | atomic_long_add(l, &mm->hugetlb_usage); | |
995 | } | |
996 | ||
997 | static inline void hugetlb_count_sub(long l, struct mm_struct *mm) | |
998 | { | |
999 | atomic_long_sub(l, &mm->hugetlb_usage); | |
1000 | } | |
e5251fd4 | 1001 | |
023bdd00 AK |
1002 | #ifndef huge_ptep_modify_prot_start |
1003 | #define huge_ptep_modify_prot_start huge_ptep_modify_prot_start | |
1004 | static inline pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma, | |
1005 | unsigned long addr, pte_t *ptep) | |
1006 | { | |
1007 | return huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); | |
1008 | } | |
1009 | #endif | |
1010 | ||
1011 | #ifndef huge_ptep_modify_prot_commit | |
1012 | #define huge_ptep_modify_prot_commit huge_ptep_modify_prot_commit | |
1013 | static inline void huge_ptep_modify_prot_commit(struct vm_area_struct *vma, | |
1014 | unsigned long addr, pte_t *ptep, | |
1015 | pte_t old_pte, pte_t pte) | |
1016 | { | |
1017 | set_huge_pte_at(vma->vm_mm, addr, ptep, pte); | |
1018 | } | |
1019 | #endif | |
1020 | ||
a4a00b45 MS |
1021 | #ifdef CONFIG_NUMA |
1022 | void hugetlb_register_node(struct node *node); | |
1023 | void hugetlb_unregister_node(struct node *node); | |
1024 | #endif | |
1025 | ||
af73e4d9 | 1026 | #else /* CONFIG_HUGETLB_PAGE */ |
a5516438 | 1027 | struct hstate {}; |
442a5a9a | 1028 | |
345c62d1 SK |
1029 | static inline struct hugepage_subpool *hugetlb_folio_subpool(struct folio *folio) |
1030 | { | |
1031 | return NULL; | |
1032 | } | |
1033 | ||
6acfb5ba MS |
1034 | static inline struct hugepage_subpool *hugetlb_page_subpool(struct page *hpage) |
1035 | { | |
1036 | return NULL; | |
1037 | } | |
1038 | ||
ae37c7ff OS |
1039 | static inline int isolate_or_dissolve_huge_page(struct page *page, |
1040 | struct list_head *list) | |
369fa227 OS |
1041 | { |
1042 | return -ENOMEM; | |
1043 | } | |
1044 | ||
d0ce0e47 | 1045 | static inline struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, |
442a5a9a JG |
1046 | unsigned long addr, |
1047 | int avoid_reserve) | |
1048 | { | |
1049 | return NULL; | |
1050 | } | |
1051 | ||
e37d3e83 SK |
1052 | static inline struct folio * |
1053 | alloc_hugetlb_folio_nodemask(struct hstate *h, int preferred_nid, | |
d92bbc27 | 1054 | nodemask_t *nmask, gfp_t gfp_mask) |
442a5a9a JG |
1055 | { |
1056 | return NULL; | |
1057 | } | |
1058 | ||
d0ce0e47 | 1059 | static inline struct folio *alloc_hugetlb_folio_vma(struct hstate *h, |
442a5a9a JG |
1060 | struct vm_area_struct *vma, |
1061 | unsigned long address) | |
1062 | { | |
1063 | return NULL; | |
1064 | } | |
1065 | ||
1066 | static inline int __alloc_bootmem_huge_page(struct hstate *h) | |
1067 | { | |
1068 | return 0; | |
1069 | } | |
1070 | ||
1071 | static inline struct hstate *hstate_file(struct file *f) | |
1072 | { | |
1073 | return NULL; | |
1074 | } | |
1075 | ||
1076 | static inline struct hstate *hstate_sizelog(int page_size_log) | |
1077 | { | |
1078 | return NULL; | |
1079 | } | |
1080 | ||
1081 | static inline struct hstate *hstate_vma(struct vm_area_struct *vma) | |
1082 | { | |
1083 | return NULL; | |
442a5a9a JG |
1084 | } |
1085 | ||
e51da3a9 SK |
1086 | static inline struct hstate *folio_hstate(struct folio *folio) |
1087 | { | |
1088 | return NULL; | |
1089 | } | |
1090 | ||
442a5a9a JG |
1091 | static inline struct hstate *page_hstate(struct page *page) |
1092 | { | |
1093 | return NULL; | |
1094 | } | |
1095 | ||
2aff7a47 MWO |
1096 | static inline struct hstate *size_to_hstate(unsigned long size) |
1097 | { | |
1098 | return NULL; | |
1099 | } | |
1100 | ||
442a5a9a JG |
1101 | static inline unsigned long huge_page_size(struct hstate *h) |
1102 | { | |
1103 | return PAGE_SIZE; | |
1104 | } | |
1105 | ||
1106 | static inline unsigned long huge_page_mask(struct hstate *h) | |
1107 | { | |
1108 | return PAGE_MASK; | |
1109 | } | |
1110 | ||
1111 | static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma) | |
1112 | { | |
1113 | return PAGE_SIZE; | |
1114 | } | |
1115 | ||
1116 | static inline unsigned long vma_mmu_pagesize(struct vm_area_struct *vma) | |
1117 | { | |
1118 | return PAGE_SIZE; | |
1119 | } | |
1120 | ||
1121 | static inline unsigned int huge_page_order(struct hstate *h) | |
1122 | { | |
1123 | return 0; | |
1124 | } | |
1125 | ||
1126 | static inline unsigned int huge_page_shift(struct hstate *h) | |
1127 | { | |
1128 | return PAGE_SHIFT; | |
1129 | } | |
1130 | ||
94310cbc AK |
1131 | static inline bool hstate_is_gigantic(struct hstate *h) |
1132 | { | |
1133 | return false; | |
1134 | } | |
1135 | ||
510a35d4 AR |
1136 | static inline unsigned int pages_per_huge_page(struct hstate *h) |
1137 | { | |
1138 | return 1; | |
1139 | } | |
c3114a84 AK |
1140 | |
1141 | static inline unsigned hstate_index_to_shift(unsigned index) | |
1142 | { | |
1143 | return 0; | |
1144 | } | |
1145 | ||
1146 | static inline int hstate_index(struct hstate *h) | |
1147 | { | |
1148 | return 0; | |
1149 | } | |
13d60f4b | 1150 | |
c3114a84 AK |
1151 | static inline int dissolve_free_huge_page(struct page *page) |
1152 | { | |
1153 | return 0; | |
1154 | } | |
1155 | ||
1156 | static inline int dissolve_free_huge_pages(unsigned long start_pfn, | |
1157 | unsigned long end_pfn) | |
1158 | { | |
1159 | return 0; | |
1160 | } | |
1161 | ||
1162 | static inline bool hugepage_migration_supported(struct hstate *h) | |
1163 | { | |
1164 | return false; | |
1165 | } | |
cb900f41 | 1166 | |
7ed2c31d AK |
1167 | static inline bool hugepage_movable_supported(struct hstate *h) |
1168 | { | |
1169 | return false; | |
1170 | } | |
1171 | ||
d92bbc27 JK |
1172 | static inline gfp_t htlb_alloc_mask(struct hstate *h) |
1173 | { | |
1174 | return 0; | |
1175 | } | |
1176 | ||
19fc7bed JK |
1177 | static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask) |
1178 | { | |
1179 | return 0; | |
1180 | } | |
1181 | ||
cb900f41 KS |
1182 | static inline spinlock_t *huge_pte_lockptr(struct hstate *h, |
1183 | struct mm_struct *mm, pte_t *pte) | |
1184 | { | |
1185 | return &mm->page_table_lock; | |
1186 | } | |
5d317b2b | 1187 | |
13db8c50 LZ |
1188 | static inline void hugetlb_count_init(struct mm_struct *mm) |
1189 | { | |
1190 | } | |
1191 | ||
5d317b2b NH |
1192 | static inline void hugetlb_report_usage(struct seq_file *f, struct mm_struct *m) |
1193 | { | |
1194 | } | |
1195 | ||
1196 | static inline void hugetlb_count_sub(long l, struct mm_struct *mm) | |
1197 | { | |
1198 | } | |
e5251fd4 | 1199 | |
5d4af619 BW |
1200 | static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, |
1201 | unsigned long addr, pte_t *ptep) | |
1202 | { | |
1203 | return *ptep; | |
1204 | } | |
1205 | ||
1206 | static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, | |
1207 | pte_t *ptep, pte_t pte) | |
1208 | { | |
1209 | } | |
a4a00b45 MS |
1210 | |
1211 | static inline void hugetlb_register_node(struct node *node) | |
1212 | { | |
1213 | } | |
1214 | ||
1215 | static inline void hugetlb_unregister_node(struct node *node) | |
1216 | { | |
1217 | } | |
af73e4d9 | 1218 | #endif /* CONFIG_HUGETLB_PAGE */ |
a5516438 | 1219 | |
cb900f41 KS |
1220 | static inline spinlock_t *huge_pte_lock(struct hstate *h, |
1221 | struct mm_struct *mm, pte_t *pte) | |
1222 | { | |
1223 | spinlock_t *ptl; | |
1224 | ||
1225 | ptl = huge_pte_lockptr(h, mm, pte); | |
1226 | spin_lock(ptl); | |
1227 | return ptl; | |
1228 | } | |
1229 | ||
cf11e85f RG |
1230 | #if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_CMA) |
1231 | extern void __init hugetlb_cma_reserve(int order); | |
cf11e85f RG |
1232 | #else |
1233 | static inline __init void hugetlb_cma_reserve(int order) | |
1234 | { | |
1235 | } | |
cf11e85f RG |
1236 | #endif |
1237 | ||
3489dbb6 MK |
1238 | #ifdef CONFIG_ARCH_WANT_HUGE_PMD_SHARE |
1239 | static inline bool hugetlb_pmd_shared(pte_t *pte) | |
1240 | { | |
1241 | return page_count(virt_to_page(pte)) > 1; | |
1242 | } | |
1243 | #else | |
1244 | static inline bool hugetlb_pmd_shared(pte_t *pte) | |
1245 | { | |
1246 | return false; | |
1247 | } | |
1248 | #endif | |
1249 | ||
c1991e07 PX |
1250 | bool want_pmd_share(struct vm_area_struct *vma, unsigned long addr); |
1251 | ||
537cf30b PX |
1252 | #ifndef __HAVE_ARCH_FLUSH_HUGETLB_TLB_RANGE |
1253 | /* | |
1254 | * ARCHes with special requirements for evicting HUGETLB backing TLB entries can | |
1255 | * implement this. | |
1256 | */ | |
1257 | #define flush_hugetlb_tlb_range(vma, addr, end) flush_tlb_range(vma, addr, end) | |
1258 | #endif | |
1259 | ||
9c67a207 PX |
1260 | static inline bool __vma_shareable_lock(struct vm_area_struct *vma) |
1261 | { | |
1262 | return (vma->vm_flags & VM_MAYSHARE) && vma->vm_private_data; | |
1263 | } | |
1264 | ||
1265 | /* | |
1266 | * Safe version of huge_pte_offset() to check the locks. See comments | |
1267 | * above huge_pte_offset(). | |
1268 | */ | |
1269 | static inline pte_t * | |
1270 | hugetlb_walk(struct vm_area_struct *vma, unsigned long addr, unsigned long sz) | |
1271 | { | |
1272 | #if defined(CONFIG_HUGETLB_PAGE) && \ | |
1273 | defined(CONFIG_ARCH_WANT_HUGE_PMD_SHARE) && defined(CONFIG_LOCKDEP) | |
1274 | struct hugetlb_vma_lock *vma_lock = vma->vm_private_data; | |
1275 | ||
1276 | /* | |
1277 | * If pmd sharing possible, locking needed to safely walk the | |
1278 | * hugetlb pgtables. More information can be found at the comment | |
1279 | * above huge_pte_offset() in the same file. | |
1280 | * | |
1281 | * NOTE: lockdep_is_held() is only defined with CONFIG_LOCKDEP. | |
1282 | */ | |
1283 | if (__vma_shareable_lock(vma)) | |
1284 | WARN_ON_ONCE(!lockdep_is_held(&vma_lock->rw_sema) && | |
1285 | !lockdep_is_held( | |
1286 | &vma->vm_file->f_mapping->i_mmap_rwsem)); | |
1287 | #endif | |
1288 | return huge_pte_offset(vma->vm_mm, addr, sz); | |
1289 | } | |
1290 | ||
1da177e4 | 1291 | #endif /* _LINUX_HUGETLB_H */ |