pagewalk.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_PAGEWALK_H
  3. #define _LINUX_PAGEWALK_H
  4. #include <linux/mm.h>
  5. struct mm_walk;
  6. /* Locking requirement during a page walk. */
  7. enum page_walk_lock {
  8. /* mmap_lock should be locked for read to stabilize the vma tree */
  9. PGWALK_RDLOCK = 0,
  10. /* vma will be write-locked during the walk */
  11. PGWALK_WRLOCK = 1,
  12. /* vma is expected to be already write-locked during the walk */
  13. PGWALK_WRLOCK_VERIFY = 2,
  14. };
  15. /**
  16. * struct mm_walk_ops - callbacks for walk_page_range
  17. * @pgd_entry: if set, called for each non-empty PGD (top-level) entry
  18. * @p4d_entry: if set, called for each non-empty P4D entry
  19. * @pud_entry: if set, called for each non-empty PUD entry
  20. * @pmd_entry: if set, called for each non-empty PMD entry
  21. * this handler is required to be able to handle
  22. * pmd_trans_huge() pmds. They may simply choose to
  23. * split_huge_page() instead of handling it explicitly.
  24. * @pte_entry: if set, called for each PTE (lowest-level) entry,
  25. * including empty ones
  26. * @pte_hole: if set, called for each hole at all levels,
  27. * depth is -1 if not known, 0:PGD, 1:P4D, 2:PUD, 3:PMD.
  28. * Any folded depths (where PTRS_PER_P?D is equal to 1)
  29. * are skipped.
  30. * @hugetlb_entry: if set, called for each hugetlb entry
  31. * @test_walk: caller specific callback function to determine whether
  32. * we walk over the current vma or not. Returning 0 means
  33. * "do page table walk over the current vma", returning
  34. * a negative value means "abort current page table walk
  35. * right now" and returning 1 means "skip the current vma"
  36. * @pre_vma: if set, called before starting walk on a non-null vma.
  37. * @post_vma: if set, called after a walk on a non-null vma, provided
  38. * that @pre_vma and the vma walk succeeded.
  39. *
  40. * p?d_entry callbacks are called even if those levels are folded on a
  41. * particular architecture/configuration.
  42. */
  43. struct mm_walk_ops {
  44. int (*pgd_entry)(pgd_t *pgd, unsigned long addr,
  45. unsigned long next, struct mm_walk *walk);
  46. int (*p4d_entry)(p4d_t *p4d, unsigned long addr,
  47. unsigned long next, struct mm_walk *walk);
  48. int (*pud_entry)(pud_t *pud, unsigned long addr,
  49. unsigned long next, struct mm_walk *walk);
  50. int (*pmd_entry)(pmd_t *pmd, unsigned long addr,
  51. unsigned long next, struct mm_walk *walk);
  52. int (*pte_entry)(pte_t *pte, unsigned long addr,
  53. unsigned long next, struct mm_walk *walk);
  54. int (*pte_hole)(unsigned long addr, unsigned long next,
  55. int depth, struct mm_walk *walk);
  56. int (*hugetlb_entry)(pte_t *pte, unsigned long hmask,
  57. unsigned long addr, unsigned long next,
  58. struct mm_walk *walk);
  59. int (*test_walk)(unsigned long addr, unsigned long next,
  60. struct mm_walk *walk);
  61. int (*pre_vma)(unsigned long start, unsigned long end,
  62. struct mm_walk *walk);
  63. void (*post_vma)(struct mm_walk *walk);
  64. enum page_walk_lock walk_lock;
  65. };
  66. /*
  67. * Action for pud_entry / pmd_entry callbacks.
  68. * ACTION_SUBTREE is the default
  69. */
  70. enum page_walk_action {
  71. /* Descend to next level, splitting huge pages if needed and possible */
  72. ACTION_SUBTREE = 0,
  73. /* Continue to next entry at this level (ignoring any subtree) */
  74. ACTION_CONTINUE = 1,
  75. /* Call again for this entry */
  76. ACTION_AGAIN = 2
  77. };
  78. /**
  79. * struct mm_walk - walk_page_range data
  80. * @ops: operation to call during the walk
  81. * @mm: mm_struct representing the target process of page table walk
  82. * @pgd: pointer to PGD; only valid with no_vma (otherwise set to NULL)
  83. * @vma: vma currently walked (NULL if walking outside vmas)
  84. * @action: next action to perform (see enum page_walk_action)
  85. * @no_vma: walk ignoring vmas (vma will always be NULL)
  86. * @private: private data for callbacks' usage
  87. *
  88. * (see the comment on walk_page_range() for more details)
  89. */
  90. struct mm_walk {
  91. const struct mm_walk_ops *ops;
  92. struct mm_struct *mm;
  93. pgd_t *pgd;
  94. struct vm_area_struct *vma;
  95. enum page_walk_action action;
  96. bool no_vma;
  97. void *private;
  98. };
  99. int walk_page_range(struct mm_struct *mm, unsigned long start,
  100. unsigned long end, const struct mm_walk_ops *ops,
  101. void *private);
  102. int walk_page_range_novma(struct mm_struct *mm, unsigned long start,
  103. unsigned long end, const struct mm_walk_ops *ops,
  104. pgd_t *pgd,
  105. void *private);
  106. int walk_page_vma(struct vm_area_struct *vma, const struct mm_walk_ops *ops,
  107. void *private);
  108. int walk_page_mapping(struct address_space *mapping, pgoff_t first_index,
  109. pgoff_t nr, const struct mm_walk_ops *ops,
  110. void *private);
  111. #endif /* _LINUX_PAGEWALK_H */