-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Why the kernel needs the pagetable early_dynamic_pgts
?
#544
Comments
On x86_64: At the early (not very first) stages, early_dynamic_pgts is used as PUD (first 512 entries) and PMD (remaining entries) for mapping __PAGE_OFFSET: va = ffff880000000000, mode = ia32e, 2M page
So __PAGE_OFFSET is mapped with early_top_pgt[272], which points to early_dynamic_pgts. If you debug with gdb you can verify this by:
This entry should point to early_dynamic_pgts. And if you follow the paging mechnism you'll get to PMD level mapping the 2M pages. The kernel code is mapped through: va = ffffffff80000000, mode = ia32e, 2M page
Verify:
This should point to level3_kernel_pgt, and
should point to level2_kernel_pgt. This is the 2M PMD pages. |
Thanks for your reply, but you may misunderstand my question.
In
I don't know why this mapping is needed. After deleting |
This identity mapping is for page table switching. If no such mapping the IP will be invalid after setting cr3. Can you verify your test and feedback to us? |
Hi, @danix800
Thanks for your help! I have understood why this mapping is necessary. I have debugged my kernel step by step in Bochs and have found a strange behavior.
I ignore these warnings and make the kernel continue running the code. I find the kernel can reach
I guess that the Bochs detects the error and continue fetching instructions from physical memory even though it doesn't know what would happen. I have tested my kernel with VMware and QEMU, the former can also boot successfully but QEMU can't. I think this behavior may relate to CPU. |
I'm investigating this too. For QEMU when kvm is enabled (--enable-kvm) the kernel can boot also. So I think there's some page fault handling under the hood by KVM.
|
My Bochs and VMware don't have any KVM mechanism. Things get a little more interesting. |
Hi, @danix800 |
Yes nobody seems to be interested. I think it's all on us now. Currently I'm studying GRUB, I'll dig into it when I have time. |
I actually digged a little a few days ago, I've already setup a debugging environment and can break the But without deep understanding of KVM it's difficult to unearth all what's going on so I gave up for now. On qemu-devel list nobody replies. On linux-kernel list, here, also there's no useful info available. Happy debugging! |
I will also keep watching this question and hope that we can solve it in the future. 😃 |
Years since last comments, I'm also running into here :-) I think the behavior is related to TLB, as linux-kernel list indicates. I made some test on kernel v6.2 source with qemu. The related code including:
In If no However, this is more of a obscure guess than a solid proof. |
Hi,
I have finished Kernel initialization Part 1, but I still have some questions. Could you please give me some hints? Many Thanks.
In
arch/x86/kernel/head_64.S
, several pagetables are defined. After reading this part, I think the early paging is handled by 3 tables:The PMD table
level2_kernel_pgt
is filled with 256 entries, so it can map 512MB pyhsical space[0, 512MB)
.If a virtual address is
0xffffffff81000000
, these pagetables can map it to physical address0x1000000
. This is very straightforward. (I hope my understanding is correct)However, I noticed that from the label
early_dynamic_pgts
there are 2 tables are also filled. I think they arePUD
andPMD
too and are used to map the kernel from_text
to_end
. I don't know why these two tables are needed. After all, we already have three tables which can map 512MB physical space.The text was updated successfully, but these errors were encountered: