thp: verify pmd_trans_huge isn't leaking
[linux-2.6.git] / include / linux / huge_mm.h
1 #ifndef _LINUX_HUGE_MM_H
2 #define _LINUX_HUGE_MM_H
3
4 extern int do_huge_pmd_anonymous_page(struct mm_struct *mm,
5                                       struct vm_area_struct *vma,
6                                       unsigned long address, pmd_t *pmd,
7                                       unsigned int flags);
8 extern int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
9                          pmd_t *dst_pmd, pmd_t *src_pmd, unsigned long addr,
10                          struct vm_area_struct *vma);
11 extern int do_huge_pmd_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
12                                unsigned long address, pmd_t *pmd,
13                                pmd_t orig_pmd);
14 extern pgtable_t get_pmd_huge_pte(struct mm_struct *mm);
15 extern struct page *follow_trans_huge_pmd(struct mm_struct *mm,
16                                           unsigned long addr,
17                                           pmd_t *pmd,
18                                           unsigned int flags);
19 extern int zap_huge_pmd(struct mmu_gather *tlb,
20                         struct vm_area_struct *vma,
21                         pmd_t *pmd);
22
23 enum transparent_hugepage_flag {
24         TRANSPARENT_HUGEPAGE_FLAG,
25         TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG,
26         TRANSPARENT_HUGEPAGE_DEFRAG_FLAG,
27         TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
28 #ifdef CONFIG_DEBUG_VM
29         TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG,
30 #endif
31 };
32
33 enum page_check_address_pmd_flag {
34         PAGE_CHECK_ADDRESS_PMD_FLAG,
35         PAGE_CHECK_ADDRESS_PMD_NOTSPLITTING_FLAG,
36         PAGE_CHECK_ADDRESS_PMD_SPLITTING_FLAG,
37 };
38 extern pmd_t *page_check_address_pmd(struct page *page,
39                                      struct mm_struct *mm,
40                                      unsigned long address,
41                                      enum page_check_address_pmd_flag flag);
42
43 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
44 #define HPAGE_PMD_SHIFT HPAGE_SHIFT
45 #define HPAGE_PMD_MASK HPAGE_MASK
46 #define HPAGE_PMD_SIZE HPAGE_SIZE
47
48 #define transparent_hugepage_enabled(__vma)                             \
49         (transparent_hugepage_flags & (1<<TRANSPARENT_HUGEPAGE_FLAG) || \
50          (transparent_hugepage_flags &                                  \
51           (1<<TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG) &&                    \
52           (__vma)->vm_flags & VM_HUGEPAGE))
53 #define transparent_hugepage_defrag(__vma)                              \
54         ((transparent_hugepage_flags &                                  \
55           (1<<TRANSPARENT_HUGEPAGE_DEFRAG_FLAG)) ||                     \
56          (transparent_hugepage_flags &                                  \
57           (1<<TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG) &&             \
58           (__vma)->vm_flags & VM_HUGEPAGE))
59 #ifdef CONFIG_DEBUG_VM
60 #define transparent_hugepage_debug_cow()                                \
61         (transparent_hugepage_flags &                                   \
62          (1<<TRANSPARENT_HUGEPAGE_DEBUG_COW_FLAG))
63 #else /* CONFIG_DEBUG_VM */
64 #define transparent_hugepage_debug_cow() 0
65 #endif /* CONFIG_DEBUG_VM */
66
67 extern unsigned long transparent_hugepage_flags;
68 extern int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
69                           pmd_t *dst_pmd, pmd_t *src_pmd,
70                           struct vm_area_struct *vma,
71                           unsigned long addr, unsigned long end);
72 extern int handle_pte_fault(struct mm_struct *mm,
73                             struct vm_area_struct *vma, unsigned long address,
74                             pte_t *pte, pmd_t *pmd, unsigned int flags);
75 extern int split_huge_page(struct page *page);
76 extern void __split_huge_page_pmd(struct mm_struct *mm, pmd_t *pmd);
77 #define split_huge_page_pmd(__mm, __pmd)                                \
78         do {                                                            \
79                 pmd_t *____pmd = (__pmd);                               \
80                 if (unlikely(pmd_trans_huge(*____pmd)))                 \
81                         __split_huge_page_pmd(__mm, ____pmd);           \
82         }  while (0)
83 #define wait_split_huge_page(__anon_vma, __pmd)                         \
84         do {                                                            \
85                 pmd_t *____pmd = (__pmd);                               \
86                 spin_unlock_wait(&(__anon_vma)->root->lock);            \
87                 /*                                                      \
88                  * spin_unlock_wait() is just a loop in C and so the    \
89                  * CPU can reorder anything around it.                  \
90                  */                                                     \
91                 smp_mb();                                               \
92                 BUG_ON(pmd_trans_splitting(*____pmd) ||                 \
93                        pmd_trans_huge(*____pmd));                       \
94         } while (0)
95 #define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
96 #define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
97 #if HPAGE_PMD_ORDER > MAX_ORDER
98 #error "hugepages can't be allocated by the buddy allocator"
99 #endif
100 #else /* CONFIG_TRANSPARENT_HUGEPAGE */
101 #define HPAGE_PMD_SHIFT ({ BUG(); 0; })
102 #define HPAGE_PMD_MASK ({ BUG(); 0; })
103 #define HPAGE_PMD_SIZE ({ BUG(); 0; })
104
105 #define transparent_hugepage_enabled(__vma) 0
106
107 #define transparent_hugepage_flags 0UL
108 static inline int split_huge_page(struct page *page)
109 {
110         return 0;
111 }
112 #define split_huge_page_pmd(__mm, __pmd)        \
113         do { } while (0)
114 #define wait_split_huge_page(__anon_vma, __pmd) \
115         do { } while (0)
116 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
117
118 #endif /* _LINUX_HUGE_MM_H */