pgtable-generic.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * mm/pgtable-generic.c
  3. *
  4. * Generic pgtable methods declared in asm-generic/pgtable.h
  5. *
  6. * Copyright (C) 2010 Linus Torvalds
  7. */
  8. #include <linux/pagemap.h>
  9. #include <asm/tlb.h>
  10. #include <asm-generic/pgtable.h>
  11. /*
  12. * If a p?d_bad entry is found while walking page tables, report
  13. * the error, before resetting entry to p?d_none. Usually (but
  14. * very seldom) called out from the p?d_none_or_clear_bad macros.
  15. */
  16. void pgd_clear_bad(pgd_t *pgd)
  17. {
  18. pgd_ERROR(*pgd);
  19. pgd_clear(pgd);
  20. }
  21. void pud_clear_bad(pud_t *pud)
  22. {
  23. pud_ERROR(*pud);
  24. pud_clear(pud);
  25. }
  26. void pmd_clear_bad(pmd_t *pmd)
  27. {
  28. pmd_ERROR(*pmd);
  29. pmd_clear(pmd);
  30. }
  31. #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  32. /*
  33. * Only sets the access flags (dirty, accessed), as well as write
  34. * permission. Furthermore, we know it always gets set to a "more
  35. * permissive" setting, which allows most architectures to optimize
  36. * this. We return whether the PTE actually changed, which in turn
  37. * instructs the caller to do things like update__mmu_cache. This
  38. * used to be done in the caller, but sparc needs minor faults to
  39. * force that call on sun4c so we changed this macro slightly
  40. */
  41. int ptep_set_access_flags(struct vm_area_struct *vma,
  42. unsigned long address, pte_t *ptep,
  43. pte_t entry, int dirty)
  44. {
  45. int changed = !pte_same(*ptep, entry);
  46. if (changed) {
  47. set_pte_at(vma->vm_mm, address, ptep, entry);
  48. flush_tlb_fix_spurious_fault(vma, address);
  49. }
  50. return changed;
  51. }
  52. #endif
  53. #ifndef __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
  54. int pmdp_set_access_flags(struct vm_area_struct *vma,
  55. unsigned long address, pmd_t *pmdp,
  56. pmd_t entry, int dirty)
  57. {
  58. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  59. int changed = !pmd_same(*pmdp, entry);
  60. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  61. if (changed) {
  62. set_pmd_at(vma->vm_mm, address, pmdp, entry);
  63. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  64. }
  65. return changed;
  66. #else /* CONFIG_TRANSPARENT_HUGEPAGE */
  67. BUG();
  68. return 0;
  69. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  70. }
  71. #endif
  72. #ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  73. int ptep_clear_flush_young(struct vm_area_struct *vma,
  74. unsigned long address, pte_t *ptep)
  75. {
  76. int young;
  77. young = ptep_test_and_clear_young(vma, address, ptep);
  78. if (young)
  79. flush_tlb_page(vma, address);
  80. return young;
  81. }
  82. #endif
  83. #ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
  84. int pmdp_clear_flush_young(struct vm_area_struct *vma,
  85. unsigned long address, pmd_t *pmdp)
  86. {
  87. int young;
  88. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  89. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  90. #else
  91. BUG();
  92. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  93. young = pmdp_test_and_clear_young(vma, address, pmdp);
  94. if (young)
  95. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  96. return young;
  97. }
  98. #endif
  99. #ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH
  100. pte_t ptep_clear_flush(struct vm_area_struct *vma, unsigned long address,
  101. pte_t *ptep)
  102. {
  103. pte_t pte;
  104. pte = ptep_get_and_clear((vma)->vm_mm, address, ptep);
  105. if (pte_accessible(pte))
  106. flush_tlb_page(vma, address);
  107. return pte;
  108. }
  109. #endif
  110. #ifndef __HAVE_ARCH_PMDP_CLEAR_FLUSH
  111. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  112. pmd_t pmdp_clear_flush(struct vm_area_struct *vma, unsigned long address,
  113. pmd_t *pmdp)
  114. {
  115. pmd_t pmd;
  116. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  117. pmd = pmdp_get_and_clear(vma->vm_mm, address, pmdp);
  118. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  119. return pmd;
  120. }
  121. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  122. #endif
  123. #ifndef __HAVE_ARCH_PMDP_SPLITTING_FLUSH
  124. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  125. void pmdp_splitting_flush(struct vm_area_struct *vma, unsigned long address,
  126. pmd_t *pmdp)
  127. {
  128. pmd_t pmd = pmd_mksplitting(*pmdp);
  129. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  130. set_pmd_at(vma->vm_mm, address, pmdp, pmd);
  131. /* tlb flush only to serialize against gup-fast */
  132. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  133. }
  134. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  135. #endif
  136. #ifndef __HAVE_ARCH_PGTABLE_DEPOSIT
  137. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  138. void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
  139. pgtable_t pgtable)
  140. {
  141. assert_spin_locked(&mm->page_table_lock);
  142. /* FIFO */
  143. if (!mm->pmd_huge_pte)
  144. INIT_LIST_HEAD(&pgtable->lru);
  145. else
  146. list_add(&pgtable->lru, &mm->pmd_huge_pte->lru);
  147. mm->pmd_huge_pte = pgtable;
  148. }
  149. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  150. #endif
  151. #ifndef __HAVE_ARCH_PGTABLE_WITHDRAW
  152. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  153. /* no "address" argument so destroys page coloring of some arch */
  154. pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
  155. {
  156. pgtable_t pgtable;
  157. assert_spin_locked(&mm->page_table_lock);
  158. /* FIFO */
  159. pgtable = mm->pmd_huge_pte;
  160. if (list_empty(&pgtable->lru))
  161. mm->pmd_huge_pte = NULL;
  162. else {
  163. mm->pmd_huge_pte = list_entry(pgtable->lru.next,
  164. struct page, lru);
  165. list_del(&pgtable->lru);
  166. }
  167. return pgtable;
  168. }
  169. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  170. #endif
  171. #ifndef __HAVE_ARCH_PMDP_INVALIDATE
  172. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  173. void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
  174. pmd_t *pmdp)
  175. {
  176. set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(*pmdp));
  177. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  178. }
  179. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  180. #endif