pagewalk.h 4.1 KB

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