Will physical addresses of all paging structures in Linux be mapped in the page tables

谁说我不能喝 提交于 2020-01-06 19:43:08

问题


In 64-bit Linux, IA-32E paging is used with 4 levels of paging structures (PML4/PDPT/PD/PT). The entries in the former three structures give the physical address of the corresponding next structure. My question is that will the physical addresses of all these paging structures be mapped in the paging table? If they are mapped, in which mode (User/Supervisor)? Thanks very much!

I captured some specific memory addresses which a vcpu have accessed during a period in KVM. These addresses are in the gfn(guest physical frame number) form. I wanted to tell if these gfns were mapped in kernel or userspace. So I traversed the guest's (virtual machine) paging table to find out the corresponding page table entries mapping to these gfns. See my previous question here.

I found that the physical addresses of some paging structures are mapped in the paging table while some are not. That is, the physical addresses of some paging structures (such as the address of PT given by a PDE) do not have valid corresponding PTE in the page table. Since I have changed the memory mechanism of the KVM a lot, I am afraid that maybe this phenomenon is caused by my code or maybe there is something wrong with my page-table-walking code.

So I want to know in a normal Linux, how these stuffs are handled.
Thanks very much!


回答1:


In 64-bit Linux, all physical addresses are always mapped with a Supervisor mapping in the kernel half of the address space.

You can convert a physical address to the corresponding virtual address in the linear kernel mapping by adding PAGE_OFFSET, which on x86-64 is 0xffff880000000000.

Are you sure that you are correctly handling 1GB and 2MB "huge pages" in your page table walker?




回答2:


In normal linux CR3 contains PA of frame containing PML4 of Page table. last bits of virtual address are offset in that frame. data at that offset contains PA of page frame for next level. In this way corresponding page frame, containing desired data,is accessed.Those addresses containing PT structs are not mapped in any Page table.

In case of KVM, guest physical pages are virtual addresses mmaped by kernel. Those addresses used by guest need mapping to physical frames which is duty and discretion of host kernel. So host kernel can map some pages and not others according to its own algorithm. So if some gfn are mapped while others not is a quite natural and correct phenomena.



来源:https://stackoverflow.com/questions/30541036/will-physical-addresses-of-all-paging-structures-in-linux-be-mapped-in-the-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!