pgtable-generic.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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_trans_huge(*pmdp) && !pmd_devmap(*pmdp));
  115. pmd = pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp);
  116. flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  117. return pmd;
  118. }
  119. #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
  120. pud_t pudp_huge_clear_flush(struct vm_area_struct *vma, unsigned long address,
  121. pud_t *pudp)
  122. {
  123. pud_t pud;
  124. VM_BUG_ON(address & ~HPAGE_PUD_MASK);
  125. VM_BUG_ON(!pud_trans_huge(*pudp) && !pud_devmap(*pudp));
  126. pud = pudp_huge_get_and_clear(vma->vm_mm, address, pudp);
  127. flush_pud_tlb_range(vma, address, address + HPAGE_PUD_SIZE);
  128. return pud;
  129. }
  130. #endif
  131. #endif
  132. #ifndef __HAVE_ARCH_PGTABLE_DEPOSIT
  133. void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
  134. pgtable_t pgtable)
  135. {
  136. assert_spin_locked(pmd_lockptr(mm, pmdp));
  137. /* FIFO */
  138. if (!pmd_huge_pte(mm, pmdp))
  139. INIT_LIST_HEAD(&pgtable->lru);
  140. else
  141. list_add(&pgtable->lru, &pmd_huge_pte(mm, pmdp)->lru);
  142. pmd_huge_pte(mm, pmdp) = pgtable;
  143. }
  144. #endif
  145. #ifndef __HAVE_ARCH_PGTABLE_WITHDRAW
  146. /* no "address" argument so destroys page coloring of some arch */
  147. pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
  148. {
  149. pgtable_t pgtable;
  150. assert_spin_locked(pmd_lockptr(mm, pmdp));
  151. /* FIFO */
  152. pgtable = pmd_huge_pte(mm, pmdp);
  153. pmd_huge_pte(mm, pmdp) = list_first_entry_or_null(&pgtable->lru,
  154. struct page, lru);
  155. if (pmd_huge_pte(mm, pmdp))
  156. list_del(&pgtable->lru);
  157. return pgtable;
  158. }
  159. #endif
  160. #ifndef __HAVE_ARCH_PMDP_INVALIDATE
  161. void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
  162. pmd_t *pmdp)
  163. {
  164. pmd_t entry = *pmdp;
  165. set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(entry));
  166. flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  167. }
  168. #endif
  169. #ifndef pmdp_collapse_flush
  170. pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long address,
  171. pmd_t *pmdp)
  172. {
  173. /*
  174. * pmd and hugepage pte format are same. So we could
  175. * use the same function.
  176. */
  177. pmd_t pmd;
  178. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  179. VM_BUG_ON(pmd_trans_huge(*pmdp));
  180. pmd = pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp);
  181. /* collapse entails shooting down ptes not pmd */
  182. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  183. return pmd;
  184. }
  185. #endif
  186. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */