pgtable-generic.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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, and
  14. * writable). 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_page(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. flush_tlb_page(vma, address);
  86. return pte;
  87. }
  88. #endif
  89. #ifndef __HAVE_ARCH_PMDP_CLEAR_FLUSH
  90. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  91. pmd_t pmdp_clear_flush(struct vm_area_struct *vma, unsigned long address,
  92. pmd_t *pmdp)
  93. {
  94. pmd_t pmd;
  95. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  96. pmd = pmdp_get_and_clear(vma->vm_mm, address, pmdp);
  97. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  98. return pmd;
  99. }
  100. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  101. #endif
  102. #ifndef __HAVE_ARCH_PMDP_SPLITTING_FLUSH
  103. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  104. void pmdp_splitting_flush(struct vm_area_struct *vma, unsigned long address,
  105. pmd_t *pmdp)
  106. {
  107. pmd_t pmd = pmd_mksplitting(*pmdp);
  108. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  109. set_pmd_at(vma->vm_mm, address, pmdp, pmd);
  110. /* tlb flush only to serialize against gup-fast */
  111. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  112. }
  113. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  114. #endif
  115. #ifndef __HAVE_ARCH_PGTABLE_DEPOSIT
  116. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  117. void pgtable_trans_huge_deposit(struct mm_struct *mm, pgtable_t pgtable)
  118. {
  119. assert_spin_locked(&mm->page_table_lock);
  120. /* FIFO */
  121. if (!mm->pmd_huge_pte)
  122. INIT_LIST_HEAD(&pgtable->lru);
  123. else
  124. list_add(&pgtable->lru, &mm->pmd_huge_pte->lru);
  125. mm->pmd_huge_pte = pgtable;
  126. }
  127. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  128. #endif
  129. #ifndef __HAVE_ARCH_PGTABLE_WITHDRAW
  130. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  131. /* no "address" argument so destroys page coloring of some arch */
  132. pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm)
  133. {
  134. pgtable_t pgtable;
  135. assert_spin_locked(&mm->page_table_lock);
  136. /* FIFO */
  137. pgtable = mm->pmd_huge_pte;
  138. if (list_empty(&pgtable->lru))
  139. mm->pmd_huge_pte = NULL;
  140. else {
  141. mm->pmd_huge_pte = list_entry(pgtable->lru.next,
  142. struct page, lru);
  143. list_del(&pgtable->lru);
  144. }
  145. return pgtable;
  146. }
  147. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  148. #endif
  149. #ifndef __HAVE_ARCH_PMDP_INVALIDATE
  150. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  151. void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
  152. pmd_t *pmdp)
  153. {
  154. set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(*pmdp));
  155. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  156. }
  157. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  158. #endif