我正在尝试编写获取页面并在 Linux 内核中返回 PTE(页表条目)的代码。
函数的原型应该是这样的:
static pte_t getPteOfPage(struct page *page);
我试图在页面的struct description中找到页面的PTE,但是比较复杂。
任何人都可以展示如何做到这一点?
我正在尝试编写获取页面并在 Linux 内核中返回 PTE(页表条目)的代码。
函数的原型应该是这样的:
static pte_t getPteOfPage(struct page *page);
我试图在页面的struct description中找到页面的PTE,但是比较复杂。
任何人都可以展示如何做到这一点?
walk_page_range
查看函数的良好起点。
/**
143 * walk_page_range - walk a memory map's page tables with a callback
144 * @addr: starting address
145 * @end: ending address
146 * @walk: set of callbacks to invoke for each level of the tree
147 *
148 * Recursively walk the page table for the memory area in a VMA,
149 * calling supplied callbacks. Callbacks are called in-order (first
150 * PGD, first PUD, first PMD, first PTE, second PTE... second PMD,
151 * etc.). If lower-level callbacks are omitted, walking depth is reduced.
152 *
153 * Each callback receives an entry pointer and the start and end of the
154 * associated range, and a copy of the original mm_walk for access to
155 * the ->private or ->mm fields.
156 *
157 * Usually no locks are taken, but splitting transparent huge page may
158 * take page table lock. And the bottom level iterator will map PTE
159 * directories from highmem if necessary.
160 *
161 * If any callback returns a non-zero value, the walk is aborted and
162 * the return value is propagated back to the caller. Otherwise 0 is returned.
163 *
164 * walk->mm->mmap_sem must be held for at least read if walk->hugetlb_entry
165 * is !NULL.
166 */
请参阅walk_page_range函数实现,以获取一个很好的示例。