OSDN Git Service

Merge "ARM: dts: msm: remove CARVEOUT ION for msm8996 ivi multi-gvm vplatform"
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / hugetlb.h
1 #ifndef _LINUX_HUGETLB_H
2 #define _LINUX_HUGETLB_H
3
4 #include <linux/mm_types.h>
5 #include <linux/mmdebug.h>
6 #include <linux/fs.h>
7 #include <linux/hugetlb_inline.h>
8 #include <linux/cgroup.h>
9 #include <linux/list.h>
10 #include <linux/kref.h>
11
12 struct ctl_table;
13 struct user_struct;
14 struct mmu_gather;
15
16 #ifdef CONFIG_HUGETLB_PAGE
17
18 #include <linux/mempolicy.h>
19 #include <linux/shm.h>
20 #include <asm/tlbflush.h>
21
22 struct hugepage_subpool {
23         spinlock_t lock;
24         long count;
25         long max_hpages;        /* Maximum huge pages or -1 if no maximum. */
26         long used_hpages;       /* Used count against maximum, includes */
27                                 /* both alloced and reserved pages. */
28         struct hstate *hstate;
29         long min_hpages;        /* Minimum huge pages or -1 if no minimum. */
30         long rsv_hpages;        /* Pages reserved against global pool to */
31                                 /* sasitfy minimum size. */
32 };
33
34 struct resv_map {
35         struct kref refs;
36         spinlock_t lock;
37         struct list_head regions;
38         long adds_in_progress;
39         struct list_head region_cache;
40         long region_cache_count;
41 };
42 extern struct resv_map *resv_map_alloc(void);
43 void resv_map_release(struct kref *ref);
44
45 extern spinlock_t hugetlb_lock;
46 extern int hugetlb_max_hstate __read_mostly;
47 #define for_each_hstate(h) \
48         for ((h) = hstates; (h) < &hstates[hugetlb_max_hstate]; (h)++)
49
50 struct hugepage_subpool *hugepage_new_subpool(struct hstate *h, long max_hpages,
51                                                 long min_hpages);
52 void hugepage_put_subpool(struct hugepage_subpool *spool);
53
54 void reset_vma_resv_huge_pages(struct vm_area_struct *vma);
55 int hugetlb_sysctl_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *);
56 int hugetlb_overcommit_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *);
57 int hugetlb_treat_movable_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *);
58
59 #ifdef CONFIG_NUMA
60 int hugetlb_mempolicy_sysctl_handler(struct ctl_table *, int,
61                                         void __user *, size_t *, loff_t *);
62 #endif
63
64 int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *);
65 long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *,
66                          struct page **, struct vm_area_struct **,
67                          unsigned long *, unsigned long *, long, unsigned int);
68 void unmap_hugepage_range(struct vm_area_struct *,
69                           unsigned long, unsigned long, struct page *);
70 void __unmap_hugepage_range_final(struct mmu_gather *tlb,
71                           struct vm_area_struct *vma,
72                           unsigned long start, unsigned long end,
73                           struct page *ref_page);
74 void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
75                                 unsigned long start, unsigned long end,
76                                 struct page *ref_page);
77 void hugetlb_report_meminfo(struct seq_file *);
78 int hugetlb_report_node_meminfo(int, char *);
79 void hugetlb_show_meminfo(void);
80 unsigned long hugetlb_total_pages(void);
81 int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82                         unsigned long address, unsigned int flags);
83 int hugetlb_reserve_pages(struct inode *inode, long from, long to,
84                                                 struct vm_area_struct *vma,
85                                                 vm_flags_t vm_flags);
86 long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
87                                                 long freed);
88 int dequeue_hwpoisoned_huge_page(struct page *page);
89 bool isolate_huge_page(struct page *page, struct list_head *list);
90 void putback_active_hugepage(struct page *page);
91 void free_huge_page(struct page *page);
92 void hugetlb_fix_reserve_counts(struct inode *inode, bool restore_reserve);
93 extern struct mutex *hugetlb_fault_mutex_table;
94 u32 hugetlb_fault_mutex_hash(struct hstate *h, struct address_space *mapping,
95                                 pgoff_t idx, unsigned long address);
96
97 pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud);
98
99 extern int hugepages_treat_as_movable;
100 extern int sysctl_hugetlb_shm_group;
101 extern struct list_head huge_boot_pages;
102
103 /* arch callbacks */
104
105 pte_t *huge_pte_alloc(struct mm_struct *mm,
106                         unsigned long addr, unsigned long sz);
107 pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr);
108 int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep);
109 void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma,
110                                 unsigned long *start, unsigned long *end);
111 struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
112                               int write);
113 struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
114                                 pmd_t *pmd, int flags);
115 struct page *follow_huge_pud(struct mm_struct *mm, unsigned long address,
116                                 pud_t *pud, int flags);
117 int pmd_huge(pmd_t pmd);
118 int pud_huge(pud_t pmd);
119 unsigned long hugetlb_change_protection(struct vm_area_struct *vma,
120                 unsigned long address, unsigned long end, pgprot_t newprot);
121
122 #else /* !CONFIG_HUGETLB_PAGE */
123
124 static inline void reset_vma_resv_huge_pages(struct vm_area_struct *vma)
125 {
126 }
127
128 static inline unsigned long hugetlb_total_pages(void)
129 {
130         return 0;
131 }
132
133 static inline int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr,
134                                                 pte_t *ptep)
135 {
136         return 0;
137 }
138
139 static inline void adjust_range_if_pmd_sharing_possible(
140                                 struct vm_area_struct *vma,
141                                 unsigned long *start, unsigned long *end)
142 {
143 }
144
145 #define follow_hugetlb_page(m,v,p,vs,a,b,i,w)   ({ BUG(); 0; })
146 #define follow_huge_addr(mm, addr, write)       ERR_PTR(-EINVAL)
147 #define copy_hugetlb_page_range(src, dst, vma)  ({ BUG(); 0; })
148 static inline void hugetlb_report_meminfo(struct seq_file *m)
149 {
150 }
151 #define hugetlb_report_node_meminfo(n, buf)     0
152 static inline void hugetlb_show_meminfo(void)
153 {
154 }
155 #define follow_huge_pmd(mm, addr, pmd, flags)   NULL
156 #define follow_huge_pud(mm, addr, pud, flags)   NULL
157 #define prepare_hugepage_range(file, addr, len) (-EINVAL)
158 #define pmd_huge(x)     0
159 #define pud_huge(x)     0
160 #define is_hugepage_only_range(mm, addr, len)   0
161 #define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) ({BUG(); 0; })
162 #define hugetlb_fault(mm, vma, addr, flags)     ({ BUG(); 0; })
163 #define huge_pte_offset(mm, address)    0
164 static inline int dequeue_hwpoisoned_huge_page(struct page *page)
165 {
166         return 0;
167 }
168
169 static inline bool isolate_huge_page(struct page *page, struct list_head *list)
170 {
171         return false;
172 }
173 #define putback_active_hugepage(p)      do {} while (0)
174
175 static inline unsigned long hugetlb_change_protection(struct vm_area_struct *vma,
176                 unsigned long address, unsigned long end, pgprot_t newprot)
177 {
178         return 0;
179 }
180
181 static inline void __unmap_hugepage_range_final(struct mmu_gather *tlb,
182                         struct vm_area_struct *vma, unsigned long start,
183                         unsigned long end, struct page *ref_page)
184 {
185         BUG();
186 }
187
188 static inline void __unmap_hugepage_range(struct mmu_gather *tlb,
189                         struct vm_area_struct *vma, unsigned long start,
190                         unsigned long end, struct page *ref_page)
191 {
192         BUG();
193 }
194
195 #endif /* !CONFIG_HUGETLB_PAGE */
196 /*
197  * hugepages at page global directory. If arch support
198  * hugepages at pgd level, they need to define this.
199  */
200 #ifndef pgd_huge
201 #define pgd_huge(x)     0
202 #endif
203
204 #ifndef pgd_write
205 static inline int pgd_write(pgd_t pgd)
206 {
207         BUG();
208         return 0;
209 }
210 #endif
211
212 #ifndef pud_write
213 static inline int pud_write(pud_t pud)
214 {
215         BUG();
216         return 0;
217 }
218 #endif
219
220 #ifndef is_hugepd
221 /*
222  * Some architectures requires a hugepage directory format that is
223  * required to support multiple hugepage sizes. For example
224  * a4fe3ce76 "powerpc/mm: Allow more flexible layouts for hugepage pagetables"
225  * introduced the same on powerpc. This allows for a more flexible hugepage
226  * pagetable layout.
227  */
228 typedef struct { unsigned long pd; } hugepd_t;
229 #define is_hugepd(hugepd) (0)
230 #define __hugepd(x) ((hugepd_t) { (x) })
231 static inline int gup_huge_pd(hugepd_t hugepd, unsigned long addr,
232                               unsigned pdshift, unsigned long end,
233                               int write, struct page **pages, int *nr)
234 {
235         return 0;
236 }
237 #else
238 extern int gup_huge_pd(hugepd_t hugepd, unsigned long addr,
239                        unsigned pdshift, unsigned long end,
240                        int write, struct page **pages, int *nr);
241 #endif
242
243 #define HUGETLB_ANON_FILE "anon_hugepage"
244
245 enum {
246         /*
247          * The file will be used as an shm file so shmfs accounting rules
248          * apply
249          */
250         HUGETLB_SHMFS_INODE     = 1,
251         /*
252          * The file is being created on the internal vfs mount and shmfs
253          * accounting rules do not apply
254          */
255         HUGETLB_ANONHUGE_INODE  = 2,
256 };
257
258 #ifdef CONFIG_HUGETLBFS
259 struct hugetlbfs_sb_info {
260         long    max_inodes;   /* inodes allowed */
261         long    free_inodes;  /* inodes free */
262         spinlock_t      stat_lock;
263         struct hstate *hstate;
264         struct hugepage_subpool *spool;
265 };
266
267 static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
268 {
269         return sb->s_fs_info;
270 }
271
272 extern const struct file_operations hugetlbfs_file_operations;
273 extern const struct vm_operations_struct hugetlb_vm_ops;
274 struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
275                                 struct user_struct **user, int creat_flags,
276                                 int page_size_log);
277
278 static inline int is_file_hugepages(struct file *file)
279 {
280         if (file->f_op == &hugetlbfs_file_operations)
281                 return 1;
282         if (is_file_shm_hugepages(file))
283                 return 1;
284
285         return 0;
286 }
287
288
289 #else /* !CONFIG_HUGETLBFS */
290
291 #define is_file_hugepages(file)                 0
292 static inline struct file *
293 hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag,
294                 struct user_struct **user, int creat_flags,
295                 int page_size_log)
296 {
297         return ERR_PTR(-ENOSYS);
298 }
299
300 #endif /* !CONFIG_HUGETLBFS */
301
302 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
303 unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
304                                         unsigned long len, unsigned long pgoff,
305                                         unsigned long flags);
306 #endif /* HAVE_ARCH_HUGETLB_UNMAPPED_AREA */
307
308 #ifdef CONFIG_HUGETLB_PAGE
309
310 #define HSTATE_NAME_LEN 32
311 /* Defines one hugetlb page size */
312 struct hstate {
313         int next_nid_to_alloc;
314         int next_nid_to_free;
315         unsigned int order;
316         unsigned long mask;
317         unsigned long max_huge_pages;
318         unsigned long nr_huge_pages;
319         unsigned long free_huge_pages;
320         unsigned long resv_huge_pages;
321         unsigned long surplus_huge_pages;
322         unsigned long nr_overcommit_huge_pages;
323         struct list_head hugepage_activelist;
324         struct list_head hugepage_freelists[MAX_NUMNODES];
325         unsigned int nr_huge_pages_node[MAX_NUMNODES];
326         unsigned int free_huge_pages_node[MAX_NUMNODES];
327         unsigned int surplus_huge_pages_node[MAX_NUMNODES];
328 #ifdef CONFIG_CGROUP_HUGETLB
329         /* cgroup control files */
330         struct cftype cgroup_files[5];
331 #endif
332         char name[HSTATE_NAME_LEN];
333 };
334
335 struct huge_bootmem_page {
336         struct list_head list;
337         struct hstate *hstate;
338 #ifdef CONFIG_HIGHMEM
339         phys_addr_t phys;
340 #endif
341 };
342
343 struct page *alloc_huge_page(struct vm_area_struct *vma,
344                                 unsigned long addr, int avoid_reserve);
345 struct page *alloc_huge_page_node(struct hstate *h, int nid);
346 struct page *alloc_huge_page_noerr(struct vm_area_struct *vma,
347                                 unsigned long addr, int avoid_reserve);
348 int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
349                         pgoff_t idx);
350
351 /* arch callback */
352 int __init alloc_bootmem_huge_page(struct hstate *h);
353
354 void __init hugetlb_add_hstate(unsigned order);
355 struct hstate *size_to_hstate(unsigned long size);
356
357 #ifndef HUGE_MAX_HSTATE
358 #define HUGE_MAX_HSTATE 1
359 #endif
360
361 extern struct hstate hstates[HUGE_MAX_HSTATE];
362 extern unsigned int default_hstate_idx;
363
364 #define default_hstate (hstates[default_hstate_idx])
365
366 static inline struct hstate *hstate_inode(struct inode *i)
367 {
368         struct hugetlbfs_sb_info *hsb;
369         hsb = HUGETLBFS_SB(i->i_sb);
370         return hsb->hstate;
371 }
372
373 static inline struct hstate *hstate_file(struct file *f)
374 {
375         return hstate_inode(file_inode(f));
376 }
377
378 static inline struct hstate *hstate_sizelog(int page_size_log)
379 {
380         if (!page_size_log)
381                 return &default_hstate;
382
383         return size_to_hstate(1UL << page_size_log);
384 }
385
386 static inline struct hstate *hstate_vma(struct vm_area_struct *vma)
387 {
388         return hstate_file(vma->vm_file);
389 }
390
391 static inline unsigned long huge_page_size(struct hstate *h)
392 {
393         return (unsigned long)PAGE_SIZE << h->order;
394 }
395
396 extern unsigned long vma_kernel_pagesize(struct vm_area_struct *vma);
397
398 extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
399
400 static inline unsigned long huge_page_mask(struct hstate *h)
401 {
402         return h->mask;
403 }
404
405 static inline unsigned int huge_page_order(struct hstate *h)
406 {
407         return h->order;
408 }
409
410 static inline unsigned huge_page_shift(struct hstate *h)
411 {
412         return h->order + PAGE_SHIFT;
413 }
414
415 static inline bool hstate_is_gigantic(struct hstate *h)
416 {
417         return huge_page_order(h) >= MAX_ORDER;
418 }
419
420 static inline unsigned int pages_per_huge_page(struct hstate *h)
421 {
422         return 1 << h->order;
423 }
424
425 static inline unsigned int blocks_per_huge_page(struct hstate *h)
426 {
427         return huge_page_size(h) / 512;
428 }
429
430 #include <asm/hugetlb.h>
431
432 #ifndef arch_make_huge_pte
433 static inline pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma,
434                                        struct page *page, int writable)
435 {
436         return entry;
437 }
438 #endif
439
440 static inline struct hstate *page_hstate(struct page *page)
441 {
442         VM_BUG_ON_PAGE(!PageHuge(page), page);
443         return size_to_hstate(PAGE_SIZE << compound_order(page));
444 }
445
446 static inline unsigned hstate_index_to_shift(unsigned index)
447 {
448         return hstates[index].order + PAGE_SHIFT;
449 }
450
451 static inline int hstate_index(struct hstate *h)
452 {
453         return h - hstates;
454 }
455
456 pgoff_t __basepage_index(struct page *page);
457
458 /* Return page->index in PAGE_SIZE units */
459 static inline pgoff_t basepage_index(struct page *page)
460 {
461         if (!PageCompound(page))
462                 return page->index;
463
464         return __basepage_index(page);
465 }
466
467 extern void dissolve_free_huge_pages(unsigned long start_pfn,
468                                      unsigned long end_pfn);
469 static inline int hugepage_migration_supported(struct hstate *h)
470 {
471 #ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
472         return huge_page_shift(h) == PMD_SHIFT;
473 #else
474         return 0;
475 #endif
476 }
477
478 static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
479                                            struct mm_struct *mm, pte_t *pte)
480 {
481         if (huge_page_size(h) == PMD_SIZE)
482                 return pmd_lockptr(mm, (pmd_t *) pte);
483         VM_BUG_ON(huge_page_size(h) == PAGE_SIZE);
484         return &mm->page_table_lock;
485 }
486
487 #ifndef hugepages_supported
488 /*
489  * Some platform decide whether they support huge pages at boot
490  * time. Some of them, such as powerpc, set HPAGE_SHIFT to 0
491  * when there is no such support
492  */
493 #define hugepages_supported() (HPAGE_SHIFT != 0)
494 #endif
495
496 void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm);
497
498 static inline void hugetlb_count_add(long l, struct mm_struct *mm)
499 {
500         atomic_long_add(l, &mm->hugetlb_usage);
501 }
502
503 static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
504 {
505         atomic_long_sub(l, &mm->hugetlb_usage);
506 }
507 #else   /* CONFIG_HUGETLB_PAGE */
508 struct hstate {};
509 #define alloc_huge_page(v, a, r) NULL
510 #define alloc_huge_page_node(h, nid) NULL
511 #define alloc_huge_page_noerr(v, a, r) NULL
512 #define alloc_bootmem_huge_page(h) NULL
513 #define hstate_file(f) NULL
514 #define hstate_sizelog(s) NULL
515 #define hstate_vma(v) NULL
516 #define hstate_inode(i) NULL
517 #define page_hstate(page) NULL
518 #define huge_page_size(h) PAGE_SIZE
519 #define huge_page_mask(h) PAGE_MASK
520 #define vma_kernel_pagesize(v) PAGE_SIZE
521 #define vma_mmu_pagesize(v) PAGE_SIZE
522 #define huge_page_order(h) 0
523 #define huge_page_shift(h) PAGE_SHIFT
524 static inline unsigned int pages_per_huge_page(struct hstate *h)
525 {
526         return 1;
527 }
528 #define hstate_index_to_shift(index) 0
529 #define hstate_index(h) 0
530
531 static inline pgoff_t basepage_index(struct page *page)
532 {
533         return page->index;
534 }
535 #define dissolve_free_huge_pages(s, e)  do {} while (0)
536 #define hugepage_migration_supported(h) 0
537
538 static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
539                                            struct mm_struct *mm, pte_t *pte)
540 {
541         return &mm->page_table_lock;
542 }
543
544 static inline void hugetlb_report_usage(struct seq_file *f, struct mm_struct *m)
545 {
546 }
547
548 static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
549 {
550 }
551 #endif  /* CONFIG_HUGETLB_PAGE */
552
553 static inline spinlock_t *huge_pte_lock(struct hstate *h,
554                                         struct mm_struct *mm, pte_t *pte)
555 {
556         spinlock_t *ptl;
557
558         ptl = huge_pte_lockptr(h, mm, pte);
559         spin_lock(ptl);
560         return ptl;
561 }
562
563 #endif /* _LINUX_HUGETLB_H */