pgtable-generic.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #ifndef CONFIG_TRANSPARENT_HUGEPAGE
  69. BUG();
  70. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  71. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  72. young = pmdp_test_and_clear_young(vma, address, pmdp);
  73. if (young)
  74. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  75. return young;
  76. }
  77. #endif
  78. #ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH
  79. pte_t ptep_clear_flush(struct vm_area_struct *vma, unsigned long address,
  80. pte_t *ptep)
  81. {
  82. pte_t pte;
  83. pte = ptep_get_and_clear((vma)->vm_mm, address, ptep);
  84. flush_tlb_page(vma, address);
  85. return pte;
  86. }
  87. #endif
  88. #ifndef __HAVE_ARCH_PMDP_CLEAR_FLUSH
  89. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  90. pmd_t pmdp_clear_flush(struct vm_area_struct *vma, unsigned long address,
  91. pmd_t *pmdp)
  92. {
  93. pmd_t pmd;
  94. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  95. pmd = pmdp_get_and_clear(vma->vm_mm, address, pmdp);
  96. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  97. return pmd;
  98. }
  99. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  100. #endif
  101. #ifndef __HAVE_ARCH_PMDP_SPLITTING_FLUSH
  102. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  103. pmd_t pmdp_splitting_flush(struct vm_area_struct *vma, unsigned long address,
  104. pmd_t *pmdp)
  105. {
  106. pmd_t pmd = pmd_mksplitting(*pmdp);
  107. VM_BUG_ON(address & ~HPAGE_PMD_MASK);
  108. set_pmd_at(vma->vm_mm, address, pmdp, pmd);
  109. /* tlb flush only to serialize against gup-fast */
  110. flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
  111. }
  112. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  113. #endif