-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map complete physical memory instead of using recursive page tables? #545
Comments
I found the recursive technique pretty interesting, and you explained it pretty clearly. For simplicity's sake on a 46 bits CPU, nothing beats identity mapping. Recursive mapping remains as a powerful technique that might be interpolated to other architectures (with less MMU bits) so I think it is worth keeping. |
@koutheir Thanks for the feedback! I plan to keep the explanation of recursive paging around, either as part of the new post or in a linked extra post. |
@phil-opp Could you explain the pros/cons of the two approaches? I'm pondering now on whether to wait for the new post or go ahead with the current one. From what I read it seems like recursive page tables are more complex, but far more flexible, while the mapping approach is simpler and can support more architectures. Am I on the right track? What are the other main differences? |
@bemeurer Yes, you're on the right track. From my current draft of the new post:
I wouldn't say that recursive page tables are more flexible. It's more the other way around: A mapping of the complete physical memory allows accessing arbitrary physical frames, including page table frames of other address spaces or frames used for DMA. So I think that it's the better choice for the blog. I just pushed my current prototype implementation of the new code in the I'll do my best to finish the new post soon. |
Where can I find the code needed to do this minimal amount of setup? Also, is it independent of the bootloader? |
There was a comment on hacker news that proposed a complete mapping of the physical address space instead of using recursive page tables:
I originally did not implement it this way because I didn't want to map too much virtual memory in the bootloader (so that the kernel can decide on its own mapping scheme). The recursive page table is only a single entry and can easily be undone by the kernel, so it seemed like a way to give the kernel all possibilities.
However, recursive page tables are a complicated concept. I heard from a lot of people that they were struggeling with the paging posts of the first edition, which also used recursive page tables. I tried my best to make the second edition post as accessible as possible, but maybe a complete mapping of the physical memory is a better choice for learnability.
I thought a bit on how we could implement it:
Add Cargo features to the bootloader:
recursive_level_4_table
feature enables the recursive mapping of a level 4 entry that we currently have. Provides aRECURSIVE_LEVEL_4_TABLE_ADDR
constant to the kernel.map_physical_memory
feature maps the complete physical address space to some virtual address. Provides aPHYSICAL_MEMORY_OFFSET
constant to the kernel.This way both variants are supported by the bootloader and users can decide which one to use (or maybe both of them).
Add a
Mapper
implementation that supports this approach tox86_64
. Alternatively, add a generic mapper implementation that works with any phys->virt closure.With this implemented, we could deprecate the advanced paging post and release a new "Paging Implementation" post that uses the mapped physical memory.
Thoughts?
The text was updated successfully, but these errors were encountered: