hugetlbfs: remove call to huge_pte_alloc without i_mmap_rwsem
[linux-2.6-microblaze.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
14 struct ctl_table;
15 struct user_struct;
16 struct mmu_gather;
17
18 #ifndef is_hugepd
19 typedef struct { unsigned long pd; } hugepd_t;
20 #define is_hugepd(hugepd) (0)
21 #define __hugepd(x) ((hugepd_t) { (x) })
22 #endif
23
24 #ifdef CONFIG_HUGETLB_PAGE
25
26 #include <linux/mempolicy.h>
27 #include <linux/shm.h>
28 #include <asm/tlbflush.h>
29
30 struct hugepage_subpool {
31         spinlock_t lock;
32         long count;
33         long max_hpages;        /* Maximum huge pages or -1 if no maximum. */
34         long used_hpages;       /* Used count against maximum, includes */
35                                 /* both alloced and reserved pages. */
36         struct hstate *hstate;
37         long min_hpages;        /* Minimum huge pages or -1 if no minimum. */
38         long rsv_hpages;        /* Pages reserved against global pool to */
39                                 /* sasitfy minimum size. */
40 };
41
42 struct resv_map {
43         struct kref refs;
44         spinlock_t lock;
45         struct list_head regions;
46         long adds_in_progress;
47         struct list_head region_cache;
48         long region_cache_count;
49 #ifdef CONFIG_CGROUP_HUGETLB
50         /*
51          * On private mappings, the counter to uncharge reservations is stored
52          * here. If these fields are 0, then either the mapping is shared, or
53          * cgroup accounting is disabled for this resv_map.
54          */
55         struct page_counter *reservation_counter;
56         unsigned long pages_per_hpage;
57         struct cgroup_subsys_state *css;
58 #endif
59 };
60
61 /*
62  * Region tracking -- allows tracking of reservations and instantiated pages
63  *                    across the pages in a mapping.
64  *
65  * The region data structures are embedded into a resv_map and protected
66  * by a resv_map's lock.  The set of regions within the resv_map represent
67  * reservations for huge pages, or huge pages that have already been
68  * instantiated within the map.  The from and to elements are huge page
69  * indicies into the associated mapping.  from indicates the starting index
70  * of the region.  to represents the first index past the end of  the region.
71  *
72  * For example, a file region structure with from == 0 and to == 4 represents
73  * four huge pages in a mapping.  It is important to note that the to element
74  * represents the first element past the end of the region. This is used in
75  * arithmetic as 4(to) - 0(from) = 4 huge pages in the region.
76  *
77  * Interval notation of the form [from, to) will be used to indicate that
78  * the endpoint from is inclusive and to is exclusive.
79  */
80 struct file_region {
81         struct list_head link;
82         long from;
83         long to;
84 #ifdef CONFIG_CGROUP_HUGETLB
85         /*
86          * On shared mappings, each reserved region appears as a struct
87          * file_region in resv_map. These fields hold the info needed to
88          * uncharge each reservation.
89          */
90         struct page_counter *reservation_counter;
91         struct cgroup_subsys_state *css;
92 #endif
93 };
94
95 extern struct resv_map *resv_map_alloc(void);
96 void resv_map_release(struct kref *ref);
97
98 extern spinlock_t hugetlb_lock;
99 extern int hugetlb_max_hstate __read_mostly;
100 #define for_each_hstate(h) \
101         for ((h) = hstates; (h) < &hstates[hugetlb_max_hstate]; (h)++)
102
103 struct hugepage_subpool *hugepage_new_subpool(struct hstate *h, long max_hpages,
104                                                 long min_hpages);
105 void hugepage_put_subpool(struct hugepage_subpool *spool);
106
107 void reset_vma_resv_huge_pages(struct vm_area_struct *vma);
108 int hugetlb_sysctl_handler(struct ctl_table *, int, void *, size_t *, loff_t *);
109 int hugetlb_overcommit_handler(struct ctl_table *, int, void *, size_t *,
110                 loff_t *);
111 int hugetlb_treat_movable_handler(struct ctl_table *, int, void *, size_t *,
112                 loff_t *);
113 int hugetlb_mempolicy_sysctl_handler(struct ctl_table *, int, void *, size_t *,
114                 loff_t *);
115
116 int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *);
117 long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *,
118                          struct page **, struct vm_area_struct **,
119                          unsigned long *, unsigned long *, long, unsigned int,
120                          int *);
121 void unmap_hugepage_range(struct vm_area_struct *,
122                           unsigned long, unsigned long, struct page *);
123 void __unmap_hugepage_range_final(struct mmu_gather *tlb,
124                           struct vm_area_struct *vma,
125                           unsigned long start, unsigned long end,
126                           struct page *ref_page);
127 void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
128                                 unsigned long start, unsigned long end,
129                                 struct page *ref_page);
130 void hugetlb_report_meminfo(struct seq_file *);
131 int hugetlb_report_node_meminfo(int, char *);
132 void hugetlb_show_meminfo(void);
133 unsigned long hugetlb_total_pages(void);
134 vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
135                         unsigned long address, unsigned int flags);
136 int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, pte_t *dst_pte,
137                                 struct vm_area_struct *dst_vma,
138                                 unsigned long dst_addr,
139                                 unsigned long src_addr,
140                                 struct page **pagep);
141 int hugetlb_reserve_pages(struct inode *inode, long from, long to,
142                                                 struct vm_area_struct *vma,
143                                                 vm_flags_t vm_flags);
144 long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
145                                                 long freed);
146 bool isolate_huge_page(struct page *page, struct list_head *list);
147 void putback_active_hugepage(struct page *page);
148 void move_hugetlb_state(struct page *oldpage, struct page *newpage, int reason);
149 void free_huge_page(struct page *page);
150 void hugetlb_fix_reserve_counts(struct inode *inode);
151 extern struct mutex *hugetlb_fault_mutex_table;
152 u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx);
153
154 pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud);
155
156 struct address_space *hugetlb_page_mapping_lock_write(struct page *hpage);
157
158 extern int sysctl_hugetlb_shm_group;
159 extern struct list_head huge_boot_pages;
160
161 /* arch callbacks */
162
163 pte_t *huge_pte_alloc(struct mm_struct *mm,
164                         unsigned long addr, unsigned long sz);
165 pte_t *huge_pte_offset(struct mm_struct *mm,
166                        unsigned long addr, unsigned long sz);
167 int huge_pmd_unshare(struct mm_struct *mm, struct vm_area_struct *vma,
168                                 unsigned long *addr, pte_t *ptep);
169 void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma,
170                                 unsigned long *start, unsigned long *end);
171 struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
172                               int write);
173 struct page *follow_huge_pd(struct vm_area_struct *vma,
174                             unsigned long address, hugepd_t hpd,
175                             int flags, int pdshift);
176 struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
177                                 pmd_t *pmd, int flags);
178 struct page *follow_huge_pud(struct mm_struct *mm, unsigned long address,
179                                 pud_t *pud, int flags);
180 struct page *follow_huge_pgd(struct mm_struct *mm, unsigned long address,
181                              pgd_t *pgd, int flags);
182
183 int pmd_huge(pmd_t pmd);
184 int pud_huge(pud_t pud);
185 unsigned long hugetlb_change_protection(struct vm_area_struct *vma,
186                 unsigned long address, unsigned long end, pgprot_t newprot);
187
188 bool is_hugetlb_entry_migration(pte_t pte);
189
190 #else /* !CONFIG_HUGETLB_PAGE */
191
192 static inline void reset_vma_resv_huge_pages(struct vm_area_struct *vma)
193 {
194 }
195
196 static inline unsigned long hugetlb_total_pages(void)
197 {
198         return 0;
199 }
200
201 static inline struct address_space *hugetlb_page_mapping_lock_write(
202                                                         struct page *hpage)
203 {
204         return NULL;
205 }
206
207 static inline int huge_pmd_unshare(struct mm_struct *mm,
208                                         struct vm_area_struct *vma,
209                                         unsigned long *addr, pte_t *ptep)
210 {
211         return 0;
212 }
213
214 static inline void adjust_range_if_pmd_sharing_possible(
215                                 struct vm_area_struct *vma,
216                                 unsigned long *start, unsigned long *end)
217 {
218 }
219
220 static inline long follow_hugetlb_page(struct mm_struct *mm,
221                         struct vm_area_struct *vma, struct page **pages,
222                         struct vm_area_struct **vmas, unsigned long *position,
223                         unsigned long *nr_pages, long i, unsigned int flags,
224                         int *nonblocking)
225 {
226         BUG();
227         return 0;
228 }
229
230 static inline struct page *follow_huge_addr(struct mm_struct *mm,
231                                         unsigned long address, int write)
232 {
233         return ERR_PTR(-EINVAL);
234 }
235
236 static inline int copy_hugetlb_page_range(struct mm_struct *dst,
237                         struct mm_struct *src, struct vm_area_struct *vma)
238 {
239         BUG();
240         return 0;
241 }
242
243 static inline void hugetlb_report_meminfo(struct seq_file *m)
244 {
245 }
246
247 static inline int hugetlb_report_node_meminfo(int nid, char *buf)
248 {
249         return 0;
250 }
251
252 static inline void hugetlb_show_meminfo(void)
253 {
254 }
255
256 static inline struct page *follow_huge_pd(struct vm_area_struct *vma,
257                                 unsigned long address, hugepd_t hpd, int flags,
258                                 int pdshift)
259 {
260         return NULL;
261 }
262
263 static inline struct page *follow_huge_pmd(struct mm_struct *mm,
264                                 unsigned long address, pmd_t *pmd, int flags)
265 {
266         return NULL;
267 }
268
269 static inline struct page *follow_huge_pud(struct mm_struct *mm,
270                                 unsigned long address, pud_t *pud, int flags)
271 {
272         return NULL;
273 }
274
275 static inline struct page *follow_huge_pgd(struct mm_struct *mm,
276                                 unsigned long address, pgd_t *pgd, int flags)
277 {
278         return NULL;
279 }
280
281 static inline int prepare_hugepage_range(struct file *file,
282                                 unsigned long addr, unsigned long len)
283 {
284         return -EINVAL;
285 }
286
287 static inline int pmd_huge(pmd_t pmd)
288 {
289         return 0;
290 }
291
292 static inline int pud_huge(pud_t pud)
293 {
294         return 0;
295 }
296
297 static inline int is_hugepage_only_range(struct mm_struct *mm,
298                                         unsigned long addr, unsigned long len)
299 {
300         return 0;
301 }
302
303 static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb,
304                                 unsigned long addr, unsigned long end,
305                                 unsigned long floor, unsigned long ceiling)
306 {
307         BUG();
308 }
309
310 static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,
311                                                 pte_t *dst_pte,
312                                                 struct vm_area_struct *dst_vma,
313                                                 unsigned long dst_addr,
314                                                 unsigned long src_addr,
315                                                 struct page **pagep)
316 {
317         BUG();
318         return 0;
319 }
320
321 static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,
322                                         unsigned long sz)
323 {
324         return NULL;
325 }
326
327 static inline bool isolate_huge_page(struct page *page, struct list_head *list)
328 {
329         return false;
330 }
331
332 static inline void putback_active_hugepage(struct page *page)
333 {
334 }
335
336 static inline void move_hugetlb_state(struct page *oldpage,
337                                         struct page *newpage, int reason)
338 {
339 }
340
341 static inline unsigned long hugetlb_change_protection(
342                         struct vm_area_struct *vma, unsigned long address,
343                         unsigned long end, pgprot_t newprot)
344 {
345         return 0;
346 }
347
348 static inline void __unmap_hugepage_range_final(struct mmu_gather *tlb,
349                         struct vm_area_struct *vma, unsigned long start,
350                         unsigned long end, struct page *ref_page)
351 {
352         BUG();
353 }
354
355 static inline void __unmap_hugepage_range(struct mmu_gather *tlb,
356                         struct vm_area_struct *vma, unsigned long start,
357                         unsigned long end, struct page *ref_page)
358 {
359         BUG();
360 }
361
362 static inline vm_fault_t hugetlb_fault(struct mm_struct *mm,
363                         struct vm_area_struct *vma, unsigned long address,
364                         unsigned int flags)
365 {
366         BUG();
367         return 0;
368 }
369
370 #endif /* !CONFIG_HUGETLB_PAGE */
371 /*
372  * hugepages at page global directory. If arch support
373  * hugepages at pgd level, they need to define this.
374  */
375 #ifndef pgd_huge
376 #define pgd_huge(x)     0
377 #endif
378 #ifndef p4d_huge
379 #define p4d_huge(x)     0
380 #endif
381
382 #ifndef pgd_write
383 static inline int pgd_write(pgd_t pgd)
384 {
385         BUG();
386         return 0;
387 }
388 #endif
389
390 #define HUGETLB_ANON_FILE "anon_hugepage"
391
392 enum {
393         /*
394          * The file will be used as an shm file so shmfs accounting rules
395          * apply
396          */
397         HUGETLB_SHMFS_INODE     = 1,
398         /*
399          * The file is being created on the internal vfs mount and shmfs
400          * accounting rules do not apply
401          */
402         HUGETLB_ANONHUGE_INODE  = 2,
403 };
404
405 #ifdef CONFIG_HUGETLBFS
406 struct hugetlbfs_sb_info {
407         long    max_inodes;   /* inodes allowed */
408         long    free_inodes;  /* inodes free */
409         spinlock_t      stat_lock;
410         struct hstate *hstate;
411         struct hugepage_subpool *spool;
412         kuid_t  uid;
413         kgid_t  gid;
414         umode_t mode;
415 };
416
417 static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
418 {
419         return sb->s_fs_info;
420 }
421
422 struct hugetlbfs_inode_info {
423         struct shared_policy policy;
424         struct inode vfs_inode;
425         unsigned int seals;
426 };
427
428 static inline struct hugetlbfs_inode_info *HUGETLBFS_I(struct inode *inode)
429 {
430         return container_of(inode, struct hugetlbfs_inode_info, vfs_inode);
431 }
432
433 extern const struct file_operations hugetlbfs_file_operations;
434 extern const struct vm_operations_struct hugetlb_vm_ops;
435 struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
436                                 struct user_struct **user, int creat_flags,
437                                 int page_size_log);
438
439 static inline bool is_file_hugepages(struct file *file)
440 {
441         if (file->f_op == &hugetlbfs_file_operations)
442                 return true;
443
444         return is_file_shm_hugepages(file);
445 }
446
447 static inline struct hstate *hstate_inode(struct inode *i)
448 {
449         return HUGETLBFS_SB(i->i_sb)->hstate;
450 }
451 #else /* !CONFIG_HUGETLBFS */
452
453 #define is_file_hugepages(file)                 false
454 static inline struct file *
455 hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag,
456                 struct user_struct **user, int creat_flags,
457                 int page_size_log)
458 {
459         return ERR_PTR(-ENOSYS);
460 }
461
462 static inline struct hstate *hstate_inode(struct inode *i)
463 {
464         return NULL;
465 }
466 #endif /* !CONFIG_HUGETLBFS */
467
468 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
469 unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
470                                         unsigned long len, unsigned long pgoff,
471                                         unsigned long flags);
472 #endif /* HAVE_ARCH_HUGETLB_UNMAPPED_AREA */
473
474 #ifdef CONFIG_HUGETLB_PAGE
475
476 #define HSTATE_NAME_LEN 32
477 /* Defines one hugetlb page size */
478 struct hstate {
479         int next_nid_to_alloc;
480         int next_nid_to_free;
481         unsigned int order;
482         unsigned long mask;
483         unsigned long max_huge_pages;
484         unsigned long nr_huge_pages;
485         unsigned long free_huge_pages;
486         unsigned long resv_huge_pages;
487         unsigned long surplus_huge_pages;
488         unsigned long nr_overcommit_huge_pages;
489         struct list_head hugepage_activelist;
490         struct list_head hugepage_freelists[MAX_NUMNODES];
491         unsigned int nr_huge_pages_node[MAX_NUMNODES];
492         unsigned int free_huge_pages_node[MAX_NUMNODES];
493         unsigned int surplus_huge_pages_node[MAX_NUMNODES];
494 #ifdef CONFIG_CGROUP_HUGETLB
495         /* cgroup control files */
496         struct cftype cgroup_files_dfl[7];
497         struct cftype cgroup_files_legacy[9];
498 #endif
499         char name[HSTATE_NAME_LEN];
500 };
501
502 struct huge_bootmem_page {
503         struct list_head list;
504         struct hstate *hstate;
505 };
506
507 struct page *alloc_huge_page(struct vm_area_struct *vma,
508                                 unsigned long addr, int avoid_reserve);
509 struct page *alloc_huge_page_node(struct hstate *h, int nid);
510 struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
511                                 nodemask_t *nmask);
512 struct page *alloc_huge_page_vma(struct hstate *h, struct vm_area_struct *vma,
513                                 unsigned long address);
514 struct page *alloc_migrate_huge_page(struct hstate *h, gfp_t gfp_mask,
515                                      int nid, nodemask_t *nmask);
516 int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
517                         pgoff_t idx);
518
519 /* arch callback */
520 int __init __alloc_bootmem_huge_page(struct hstate *h);
521 int __init alloc_bootmem_huge_page(struct hstate *h);
522
523 void __init hugetlb_add_hstate(unsigned order);
524 bool __init arch_hugetlb_valid_size(unsigned long size);
525 struct hstate *size_to_hstate(unsigned long size);
526
527 #ifndef HUGE_MAX_HSTATE
528 #define HUGE_MAX_HSTATE 1
529 #endif
530
531 extern struct hstate hstates[HUGE_MAX_HSTATE];
532 extern unsigned int default_hstate_idx;
533
534 #define default_hstate (hstates[default_hstate_idx])
535
536 static inline struct hstate *hstate_file(struct file *f)
537 {
538         return hstate_inode(file_inode(f));
539 }
540
541 static inline struct hstate *hstate_sizelog(int page_size_log)
542 {
543         if (!page_size_log)
544                 return &default_hstate;
545
546         return size_to_hstate(1UL << page_size_log);
547 }
548
549 static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
550 {
551         return hstate_file(vma->vm_file);
552 }
553
554 static inline unsigned long huge_page_size(struct hstate *h)
555 {
556         return (unsigned long)PAGE_SIZE << h->order;
557 }
558
559 extern unsigned long vma_kernel_pagesize(struct vm_area_struct *vma);
560
561 extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
562
563 static inline unsigned long huge_page_mask(struct hstate *h)
564 {
565         return h->mask;
566 }
567
568 static inline unsigned int huge_page_order(struct hstate *h)
569 {
570         return h->order;
571 }
572
573 static inline unsigned huge_page_shift(struct hstate *h)
574 {
575         return h->order + PAGE_SHIFT;
576 }
577
578 static inline bool hstate_is_gigantic(struct hstate *h)
579 {
580         return huge_page_order(h) >= MAX_ORDER;
581 }
582
583 static inline unsigned int pages_per_huge_page(struct hstate *h)
584 {
585         return 1 << h->order;
586 }
587
588 static inline unsigned int blocks_per_huge_page(struct hstate *h)
589 {
590         return huge_page_size(h) / 512;
591 }
592
593 #include <asm/hugetlb.h>
594
595 #ifndef is_hugepage_only_range
596 static inline int is_hugepage_only_range(struct mm_struct *mm,
597                                         unsigned long addr, unsigned long len)
598 {
599         return 0;
600 }
601 #define is_hugepage_only_range is_hugepage_only_range
602 #endif
603
604 #ifndef arch_clear_hugepage_flags
605 static inline void arch_clear_hugepage_flags(struct page *page) { }
606 #define arch_clear_hugepage_flags arch_clear_hugepage_flags
607 #endif
608
609 #ifndef arch_make_huge_pte
610 static inline pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma,
611                                        struct page *page, int writable)
612 {
613         return entry;
614 }
615 #endif
616
617 static inline struct hstate *page_hstate(struct page *page)
618 {
619         VM_BUG_ON_PAGE(!PageHuge(page), page);
620         return size_to_hstate(page_size(page));
621 }
622
623 static inline unsigned hstate_index_to_shift(unsigned index)
624 {
625         return hstates[index].order + PAGE_SHIFT;
626 }
627
628 static inline int hstate_index(struct hstate *h)
629 {
630         return h - hstates;
631 }
632
633 pgoff_t __basepage_index(struct page *page);
634
635 /* Return page->index in PAGE_SIZE units */
636 static inline pgoff_t basepage_index(struct page *page)
637 {
638         if (!PageCompound(page))
639                 return page->index;
640
641         return __basepage_index(page);
642 }
643
644 extern int dissolve_free_huge_page(struct page *page);
645 extern int dissolve_free_huge_pages(unsigned long start_pfn,
646                                     unsigned long end_pfn);
647
648 #ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
649 #ifndef arch_hugetlb_migration_supported
650 static inline bool arch_hugetlb_migration_supported(struct hstate *h)
651 {
652         if ((huge_page_shift(h) == PMD_SHIFT) ||
653                 (huge_page_shift(h) == PUD_SHIFT) ||
654                         (huge_page_shift(h) == PGDIR_SHIFT))
655                 return true;
656         else
657                 return false;
658 }
659 #endif
660 #else
661 static inline bool arch_hugetlb_migration_supported(struct hstate *h)
662 {
663         return false;
664 }
665 #endif
666
667 static inline bool hugepage_migration_supported(struct hstate *h)
668 {
669         return arch_hugetlb_migration_supported(h);
670 }
671
672 /*
673  * Movability check is different as compared to migration check.
674  * It determines whether or not a huge page should be placed on
675  * movable zone or not. Movability of any huge page should be
676  * required only if huge page size is supported for migration.
677  * There wont be any reason for the huge page to be movable if
678  * it is not migratable to start with. Also the size of the huge
679  * page should be large enough to be placed under a movable zone
680  * and still feasible enough to be migratable. Just the presence
681  * in movable zone does not make the migration feasible.
682  *
683  * So even though large huge page sizes like the gigantic ones
684  * are migratable they should not be movable because its not
685  * feasible to migrate them from movable zone.
686  */
687 static inline bool hugepage_movable_supported(struct hstate *h)
688 {
689         if (!hugepage_migration_supported(h))
690                 return false;
691
692         if (hstate_is_gigantic(h))
693                 return false;
694         return true;
695 }
696
697 static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
698                                            struct mm_struct *mm, pte_t *pte)
699 {
700         if (huge_page_size(h) == PMD_SIZE)
701                 return pmd_lockptr(mm, (pmd_t *) pte);
702         VM_BUG_ON(huge_page_size(h) == PAGE_SIZE);
703         return &mm->page_table_lock;
704 }
705
706 #ifndef hugepages_supported
707 /*
708  * Some platform decide whether they support huge pages at boot
709  * time. Some of them, such as powerpc, set HPAGE_SHIFT to 0
710  * when there is no such support
711  */
712 #define hugepages_supported() (HPAGE_SHIFT != 0)
713 #endif
714
715 void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm);
716
717 static inline void hugetlb_count_add(long l, struct mm_struct *mm)
718 {
719         atomic_long_add(l, &mm->hugetlb_usage);
720 }
721
722 static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
723 {
724         atomic_long_sub(l, &mm->hugetlb_usage);
725 }
726
727 #ifndef set_huge_swap_pte_at
728 static inline void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr,
729                                         pte_t *ptep, pte_t pte, unsigned long sz)
730 {
731         set_huge_pte_at(mm, addr, ptep, pte);
732 }
733 #endif
734
735 #ifndef huge_ptep_modify_prot_start
736 #define huge_ptep_modify_prot_start huge_ptep_modify_prot_start
737 static inline pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma,
738                                                 unsigned long addr, pte_t *ptep)
739 {
740         return huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
741 }
742 #endif
743
744 #ifndef huge_ptep_modify_prot_commit
745 #define huge_ptep_modify_prot_commit huge_ptep_modify_prot_commit
746 static inline void huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
747                                                 unsigned long addr, pte_t *ptep,
748                                                 pte_t old_pte, pte_t pte)
749 {
750         set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
751 }
752 #endif
753
754 #else   /* CONFIG_HUGETLB_PAGE */
755 struct hstate {};
756
757 static inline struct page *alloc_huge_page(struct vm_area_struct *vma,
758                                            unsigned long addr,
759                                            int avoid_reserve)
760 {
761         return NULL;
762 }
763
764 static inline struct page *alloc_huge_page_node(struct hstate *h, int nid)
765 {
766         return NULL;
767 }
768
769 static inline struct page *
770 alloc_huge_page_nodemask(struct hstate *h, int preferred_nid, nodemask_t *nmask)
771 {
772         return NULL;
773 }
774
775 static inline struct page *alloc_huge_page_vma(struct hstate *h,
776                                                struct vm_area_struct *vma,
777                                                unsigned long address)
778 {
779         return NULL;
780 }
781
782 static inline int __alloc_bootmem_huge_page(struct hstate *h)
783 {
784         return 0;
785 }
786
787 static inline struct hstate *hstate_file(struct file *f)
788 {
789         return NULL;
790 }
791
792 static inline struct hstate *hstate_sizelog(int page_size_log)
793 {
794         return NULL;
795 }
796
797 static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
798 {
799         return NULL;
800 }
801
802 static inline struct hstate *page_hstate(struct page *page)
803 {
804         return NULL;
805 }
806
807 static inline unsigned long huge_page_size(struct hstate *h)
808 {
809         return PAGE_SIZE;
810 }
811
812 static inline unsigned long huge_page_mask(struct hstate *h)
813 {
814         return PAGE_MASK;
815 }
816
817 static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
818 {
819         return PAGE_SIZE;
820 }
821
822 static inline unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
823 {
824         return PAGE_SIZE;
825 }
826
827 static inline unsigned int huge_page_order(struct hstate *h)
828 {
829         return 0;
830 }
831
832 static inline unsigned int huge_page_shift(struct hstate *h)
833 {
834         return PAGE_SHIFT;
835 }
836
837 static inline bool hstate_is_gigantic(struct hstate *h)
838 {
839         return false;
840 }
841
842 static inline unsigned int pages_per_huge_page(struct hstate *h)
843 {
844         return 1;
845 }
846
847 static inline unsigned hstate_index_to_shift(unsigned index)
848 {
849         return 0;
850 }
851
852 static inline int hstate_index(struct hstate *h)
853 {
854         return 0;
855 }
856
857 static inline pgoff_t basepage_index(struct page *page)
858 {
859         return page->index;
860 }
861
862 static inline int dissolve_free_huge_page(struct page *page)
863 {
864         return 0;
865 }
866
867 static inline int dissolve_free_huge_pages(unsigned long start_pfn,
868                                            unsigned long end_pfn)
869 {
870         return 0;
871 }
872
873 static inline bool hugepage_migration_supported(struct hstate *h)
874 {
875         return false;
876 }
877
878 static inline bool hugepage_movable_supported(struct hstate *h)
879 {
880         return false;
881 }
882
883 static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
884                                            struct mm_struct *mm, pte_t *pte)
885 {
886         return &mm->page_table_lock;
887 }
888
889 static inline void hugetlb_report_usage(struct seq_file *f, struct mm_struct *m)
890 {
891 }
892
893 static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
894 {
895 }
896
897 static inline void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr,
898                                         pte_t *ptep, pte_t pte, unsigned long sz)
899 {
900 }
901 #endif  /* CONFIG_HUGETLB_PAGE */
902
903 static inline spinlock_t *huge_pte_lock(struct hstate *h,
904                                         struct mm_struct *mm, pte_t *pte)
905 {
906         spinlock_t *ptl;
907
908         ptl = huge_pte_lockptr(h, mm, pte);
909         spin_lock(ptl);
910         return ptl;
911 }
912
913 #if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_CMA)
914 extern void __init hugetlb_cma_reserve(int order);
915 extern void __init hugetlb_cma_check(void);
916 #else
917 static inline __init void hugetlb_cma_reserve(int order)
918 {
919 }
920 static inline __init void hugetlb_cma_check(void)
921 {
922 }
923 #endif
924
925 #endif /* _LINUX_HUGETLB_H */