pgtable-generic.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 p4d_clear_bad(p4d_t *p4d)
  22. {
  23. p4d_ERROR(*p4d);
  24. p4d_clear(p4d);
  25. }
  26. void pud_clear_bad(pud_t *pud)
  27. {
  28. pud_ERROR(*pud);
  29. pud_clear(pud);
  30. }
  31. void pmd_clear_bad(pmd_t *pmd)
  32. {
  33. pmd_ERROR(*pmd);
  34. pmd_clear(pmd);
  35. }
  36. #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  37. /*
  38. * Only sets the access flags (dirty, accessed), as well as write
  39. * permission. Furthermore, we know it always gets set to a "more
  40. * permissive" setting, which allows most architectures to optimize
  41. * this. We return whether the PTE actually changed, which in turn
  42. * instructs the caller to do things like update__mmu_cache. This
  43. * used to be done in the caller, but sparc needs minor faults to
  44. * force that call on sun4c so we changed this macro slightly
  45. */
  46. int ptep_set_access_flags(struct vm_area_struct *vma,
  47. unsigned long address, pte_t *ptep,
  48. pte_t entry, int dirty)
  49. {
  50. int changed = !pte_same(*ptep, entry);
  51. if (changed) {
  52. set_pte_at(vma->vm_mm, address, ptep, entry);
  53. flush_tlb_fix_spurious_fault(vma, address);
  54. }
  55. return changed;
  56. }
  57. #endif
  58. #ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  59. int ptep_clear_flush_young(struct vm_area_struct *vma,
  60. unsigned long address, pte_t *ptep)
  61. {
  62. int young;
  63. young = ptep_test_and_clear_young(vma, address, ptep);
  64. if (young)
  65. flush_tlb_page(vma, address);
  66. return young;
  67. }
  68. #endif
  69. #ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH
  70. pte_t ptep_clear_flush(struct vm_area_struct *vma, unsigned long address,
  71. pte_t *ptep)
  72. {
  73. struct mm_struct *mm = (vma)->vm_mm;
  74. pte_t pte;
  75. pte = ptep_get_and_clear(mm, address, ptep);
  76. if (pte_accessible(mm, pte))
  77. flush_tlb_page(vma, address);
  78. return pte;
  79. }
  80. #endif
  81. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  82. #ifndef __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
  83. int pmdp_set_access_flags(struct vm_area_struct *vma,
  84. unsigned long address, pmd_t *pmdp,
  85. pmd_t entry, int dirty)
  86. {
  87. int changed = !pmd_same(*pmdp, entry);
  88. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  89. if (changed) {
  90. set_pmd_at(vma->vm_mm, address, pmdp, entry);
  91. flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  92. }
  93. return changed;
  94. }
  95. #endif
  96. #ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
  97. int pmdp_clear_flush_young(struct vm_area_struct *vma,
  98. unsigned long address, pmd_t *pmdp)
  99. {
  100. int young;
  101. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  102. young = pmdp_test_and_clear_young(vma, address, pmdp);
  103. if (young)
  104. flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  105. return young;
  106. }
  107. #endif
  108. #ifndef __HAVE_ARCH_PMDP_HUGE_CLEAR_FLUSH
  109. pmd_t pmdp_huge_clear_flush(struct vm_area_struct *vma, unsigned long address,
  110. pmd_t *pmdp)
  111. {
  112. pmd_t pmd;
  113. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  114. VM_BUG_ON((pmd_present(*pmdp) && !pmd_trans_huge(*pmdp) &&
  115. !pmd_devmap(*pmdp)) || !pmd_present(*pmdp));
  116. pmd = pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp);
  117. flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  118. return pmd;
  119. }
  120. #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
  121. pud_t pudp_huge_clear_flush(struct vm_area_struct *vma, unsigned long address,
  122. pud_t *pudp)
  123. {
  124. pud_t pud;
  125. VM_BUG_ON(address & ~HPAGE_PUD_MASK);
  126. VM_BUG_ON(!pud_trans_huge(*pudp) && !pud_devmap(*pudp));
  127. pud = pudp_huge_get_and_clear(vma->vm_mm, address, pudp);
  128. flush_pud_tlb_range(vma, address, address + HPAGE_PUD_SIZE);
  129. return pud;
  130. }
  131. #endif
  132. #endif
  133. #ifndef __HAVE_ARCH_PGTABLE_DEPOSIT
  134. void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
  135. pgtable_t pgtable)
  136. {
  137. assert_spin_locked(pmd_lockptr(mm, pmdp));
  138. /* FIFO */
  139. if (!pmd_huge_pte(mm, pmdp))
  140. INIT_LIST_HEAD(&pgtable->lru);
  141. else
  142. list_add(&pgtable->lru, &pmd_huge_pte(mm, pmdp)->lru);
  143. pmd_huge_pte(mm, pmdp) = pgtable;
  144. }
  145. #endif
  146. #ifndef __HAVE_ARCH_PGTABLE_WITHDRAW
  147. /* no "address" argument so destroys page coloring of some arch */
  148. pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
  149. {
  150. pgtable_t pgtable;
  151. assert_spin_locked(pmd_lockptr(mm, pmdp));
  152. /* FIFO */
  153. pgtable = pmd_huge_pte(mm, pmdp);
  154. pmd_huge_pte(mm, pmdp) = list_first_entry_or_null(&pgtable->lru,
  155. struct page, lru);
  156. if (pmd_huge_pte(mm, pmdp))
  157. list_del(&pgtable->lru);
  158. return pgtable;
  159. }
  160. #endif
  161. #ifndef __HAVE_ARCH_PMDP_INVALIDATE
  162. void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
  163. pmd_t *pmdp)
  164. {
  165. pmd_t entry = *pmdp;
  166. set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(entry));
  167. flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  168. }
  169. #endif
  170. #ifndef pmdp_collapse_flush
  171. pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long address,
  172. pmd_t *pmdp)
  173. {
  174. /*
  175. * pmd and hugepage pte format are same. So we could
  176. * use the same function.
  177. */
  178. pmd_t pmd;
  179. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  180. VM_BUG_ON(pmd_trans_huge(*pmdp));
  181. pmd = pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp);
  182. /* collapse entails shooting down ptes not pmd */
  183. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  184. return pmd;
  185. }
  186. #endif
  187. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */