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