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