pgtable-generic.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  12. /*
  13. * Only sets the access flags (dirty, accessed), as well as write
  14. * permission. Furthermore, we know it always gets set to a "more
  15. * permissive" setting, which allows most architectures to optimize
  16. * this. We return whether the PTE actually changed, which in turn
  17. * instructs the caller to do things like update__mmu_cache. This
  18. * used to be done in the caller, but sparc needs minor faults to
  19. * force that call on sun4c so we changed this macro slightly
  20. */
  21. int ptep_set_access_flags(struct vm_area_struct *vma,
  22. unsigned long address, pte_t *ptep,
  23. pte_t entry, int dirty)
  24. {
  25. int changed = !pte_same(*ptep, entry);
  26. if (changed) {
  27. set_pte_at(vma->vm_mm, address, ptep, entry);
  28. flush_tlb_fix_spurious_fault(vma, address);
  29. }
  30. return changed;
  31. }
  32. #endif
  33. #ifndef __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
  34. int pmdp_set_access_flags(struct vm_area_struct *vma,
  35. unsigned long address, pmd_t *pmdp,
  36. pmd_t entry, int dirty)
  37. {
  38. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  39. int changed = !pmd_same(*pmdp, entry);
  40. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  41. if (changed) {
  42. set_pmd_at(vma->vm_mm, address, pmdp, entry);
  43. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  44. }
  45. return changed;
  46. #else /* CONFIG_TRANSPARENT_HUGEPAGE */
  47. BUG();
  48. return 0;
  49. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  50. }
  51. #endif
  52. #ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  53. int ptep_clear_flush_young(struct vm_area_struct *vma,
  54. unsigned long address, pte_t *ptep)
  55. {
  56. int young;
  57. young = ptep_test_and_clear_young(vma, address, ptep);
  58. if (young)
  59. flush_tlb_page(vma, address);
  60. return young;
  61. }
  62. #endif
  63. #ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
  64. int pmdp_clear_flush_young(struct vm_area_struct *vma,
  65. unsigned long address, pmd_t *pmdp)
  66. {
  67. int young;
  68. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  69. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  70. #else
  71. BUG();
  72. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  73. young = pmdp_test_and_clear_young(vma, address, pmdp);
  74. if (young)
  75. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  76. return young;
  77. }
  78. #endif
  79. #ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH
  80. pte_t ptep_clear_flush(struct vm_area_struct *vma, unsigned long address,
  81. pte_t *ptep)
  82. {
  83. pte_t pte;
  84. pte = ptep_get_and_clear((vma)->vm_mm, address, ptep);
  85. if (pte_accessible(pte))
  86. flush_tlb_page(vma, address);
  87. return pte;
  88. }
  89. #endif
  90. #ifndef __HAVE_ARCH_PMDP_CLEAR_FLUSH
  91. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  92. pmd_t pmdp_clear_flush(struct vm_area_struct *vma, unsigned long address,
  93. pmd_t *pmdp)
  94. {
  95. pmd_t pmd;
  96. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  97. pmd = pmdp_get_and_clear(vma->vm_mm, address, pmdp);
  98. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  99. return pmd;
  100. }
  101. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  102. #endif
  103. #ifndef __HAVE_ARCH_PMDP_SPLITTING_FLUSH
  104. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  105. void pmdp_splitting_flush(struct vm_area_struct *vma, unsigned long address,
  106. pmd_t *pmdp)
  107. {
  108. pmd_t pmd = pmd_mksplitting(*pmdp);
  109. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  110. set_pmd_at(vma->vm_mm, address, pmdp, pmd);
  111. /* tlb flush only to serialize against gup-fast */
  112. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  113. }
  114. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  115. #endif
  116. #ifndef __HAVE_ARCH_PGTABLE_DEPOSIT
  117. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  118. void pgtable_trans_huge_deposit(struct mm_struct *mm, pgtable_t pgtable)
  119. {
  120. assert_spin_locked(&mm->page_table_lock);
  121. /* FIFO */
  122. if (!mm->pmd_huge_pte)
  123. INIT_LIST_HEAD(&pgtable->lru);
  124. else
  125. list_add(&pgtable->lru, &mm->pmd_huge_pte->lru);
  126. mm->pmd_huge_pte = pgtable;
  127. }
  128. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  129. #endif
  130. #ifndef __HAVE_ARCH_PGTABLE_WITHDRAW
  131. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  132. /* no "address" argument so destroys page coloring of some arch */
  133. pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm)
  134. {
  135. pgtable_t pgtable;
  136. assert_spin_locked(&mm->page_table_lock);
  137. /* FIFO */
  138. pgtable = mm->pmd_huge_pte;
  139. if (list_empty(&pgtable->lru))
  140. mm->pmd_huge_pte = NULL;
  141. else {
  142. mm->pmd_huge_pte = list_entry(pgtable->lru.next,
  143. struct page, lru);
  144. list_del(&pgtable->lru);
  145. }
  146. return pgtable;
  147. }
  148. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  149. #endif
  150. #ifndef __HAVE_ARCH_PMDP_INVALIDATE
  151. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  152. void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
  153. pmd_t *pmdp)
  154. {
  155. set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(*pmdp));
  156. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  157. }
  158. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  159. #endif