Advanced Paging #1012
Replies: 24 comments
-
BTW there seems to be a discussion on Hacker News about how recursive page tables are unnecessary. I'm not qualified to opine here, and I haven't actually even gone through this post yet, I just wanted to make sure you saw it. |
Beta Was this translation helpful? Give feedback.
-
Fantastic article! This is the best explanation of page tables I have read, great examples with a few typos I was able to correct easily so code works. Thanks :) |
Beta Was this translation helpful? Give feedback.
-
@wwestlake Thanks so much! @lilyball Thanks for the pointer! I'll post an answer over there. Edit: See #545 |
Beta Was this translation helpful? Give feedback.
-
Thanks for the great post! I wonder if how the kernel stack is initialized in the page table. As far as I understand, the kernel stack should already be initialized before |
Beta Was this translation helpful? Give feedback.
-
@jeehoonkang Yes, that's completely correct. The stack initialization happens here. |
Beta Was this translation helpful? Give feedback.
-
In the Translating Addresses section, the definition of More generally, that function makes the assumption that the level 4, 3, and 2 index portions of The fact that it relies on these unstated assumptions is what made it confusing for me. |
Beta Was this translation helpful? Give feedback.
-
In Creating a new Mapping, let map_to_result = unsafe {
recursive_page_table.map_to(page, frame, flags, frame_allocator)
}; And indeed the documentation for |
Beta Was this translation helpful? Give feedback.
-
Looking further, it appears that version |
Beta Was this translation helpful? Give feedback.
-
Ah, now that I've read further, you tell me to update to |
Beta Was this translation helpful? Give feedback.
-
@lilyball Thanks for the feedback!
Yeah, I updated the blog to version
Good points! I rewrote that section in 6fe3313, I hope that it is more understandable now. |
Beta Was this translation helpful? Give feedback.
-
Absolutely brilliant! when do you think the second edition will be complete? @phill-opp |
Beta Was this translation helpful? Give feedback.
-
@mental32 Thank you! Depends what you mean with "complete". There is only a single topic from the first edition missing in the second edition (kernel heap). But of course I will continue the series from there and explore new topics such as multithreading, multiprocessing, and userspace programs. There's no shortage on interesting topics, so I think I'll just keep going as long as I have the necessary time :). |
Beta Was this translation helpful? Give feedback.
-
Ah yes I do suppose "correct" is relative, I suppose I mean topics like filesystems, POSIX compliance, porting libc, multitasking. Also it would be cool to see how a bootloader is written, while I have no issues with bootimage for now it'd be interesting to see it be done manually. Do you have a roadmap or something setup where I can see what topics you plan on covering? |
Beta Was this translation helpful? Give feedback.
-
Also would version of this edition that can be downloaded locally, and distributed easily like a pdf, be avaliable? |
Beta Was this translation helpful? Give feedback.
-
@mental32 I don't have a complete roadmap. I have concrete plans for the next two or three posts (kernel heap, multitasking, multi-core), but after that I don't know yet. A post on the bootloader is planned too, I just need to find some time to write it.
We don't have a PDF version at the moment. Maybe I'll create one when there is more content. |
Beta Was this translation helpful? Give feedback.
-
Will the concept of a "higher half" kernel come into play at some point in your tutorials? I'm very interested in how that would be done for a Rust kernel! |
Beta Was this translation helpful? Give feedback.
-
@Rua Not until we add support for userspace processes because it only becomes relevant then. But I'm not sure whether address space sharing is still the way to go given the Spectre vulnerability. Putting the kernel in the higher half should be relatively straightforward with our bootloader because the bootloader already maps the kernel to its specified virtual addresses. So you would just need to create a linker script that sets the starting virtual address to your desired address and specify the linker script in your target configuration ( The linker script could look like this:
Let me know if you need further help! |
Beta Was this translation helpful? Give feedback.
-
Really nice explanation, it's awesome, thank you :) |
Beta Was this translation helpful? Give feedback.
-
@tanguc Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi ! (I came here because your blog is referenced by utteranc.es as a good usage of their comment system and I was needing one for mine. Now I'm writing an OS in rust ! ^^)
When building with When I modify the example mapping as: pub fn create_example_mapping(
recursive_page_table: &mut RecursivePageTable,
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
) {
use x86_64::structures::paging::PageTableFlags as Flags;
- let page: Page = Page::containing_address(VirtAddr::new(0x1000));
+ let page: Page = Page::containing_address(VirtAddr::new(0xdeadbeaf900));
let frame = PhysFrame::containing_address(PhysAddr::new(0xb8000));
let flags = Flags::PRESENT | Flags::WRITABLE;
let map_to_result = unsafe { recursive_page_table.map_to(page, frame, flags, frame_allocator) };
map_to_result.expect("map_to failed").flush();
} it works OK. 😍 Would you mind if I create a PR to fix that typos, I can do that tomorrow or so ? Anyway, thanks for the blog. Long time I haven't done low-level stuff and it is really a pleasure to do it with Rust (I destroyed a board doing this https://github.com/tychota/ADXL345/blob/master/i2c-adxl345-input.c ^^). Your explanations are really valuable too. |
Beta Was this translation helpful? Give feedback.
-
Hi @tychota,
That's a good story :D. Utterances works great for me so far!
Yes, I think that's a typo. I think I renamed that function but apparently forgot to update some references. A PR that fixes this would be great!
We first map page
You're welcome, I'm glad that you like it! |
Beta Was this translation helpful? Give feedback.
-
I know it sounds silly, but I get clippy warnings because |
Beta Was this translation helpful? Give feedback.
-
I don't think that it's an improvement for the deadbeaf address. But it definitely makes |
Beta Was this translation helpful? Give feedback.
-
Brace yourself, PR is coming. |
Beta Was this translation helpful? Give feedback.
-
This is a general purpose comment thread for the “Advanced Paging” post.
Beta Was this translation helpful? Give feedback.
All reactions