How can I impliment Paging

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
nexos
Member
Member
Posts: 1073
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: How can I impliment Paging

Post by nexos »

Even in that case there still is a race condition as what if the CPU speculatively reads from the junk PTE? Then you just read junk data into the pipeline
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
thewrongchristian
Member
Member
Posts: 415
Joined: Tue Apr 03, 2018 2:44 am

Re: How can I impliment Paging

Post by thewrongchristian »

iProgramInCpp wrote:
thewrongchristian wrote:Loading in uninitialised memory into the paging structure is very dangerous
I said specifically the last level. The memory associated with the last level (whose entry belongs in a PT on x86 32-bit) isn't associated with the paging structure, rather being actual usable memory. It doesn't matter if the TLB reads the entry associated with that page before it's mapped. In fact you don't strictly have to zero that page out at all! Sure, you will be able to read what was in that page, but you're the kernel, and when dishing out pages to user space you of course would zero them out anyway.

Of course the other levels need to be zeroed out before being inserted. I was saying that the whole time!
OK, understood, it's a difference in terminology.

When you say the last level, I took that as meaning the last level of the paging structure (i.e. the page table,) whereas you were talking about what the paging structure points to (the destination page of the PTE mapping.)
Xeno
Member
Member
Posts: 56
Joined: Tue Oct 10, 2023 7:40 pm

Re: How can I impliment Paging

Post by Xeno »

Hmmm, didn't see this thread grew...
Well thanks for all the input. I think I know how I will implement it, just havent really had time yet, got some drivers done... I am going a bit off the beaten path for my memory managment. Kernel is located at 0xFA0000000000, and quite a few other odd mapings I have chosen

But thanks for all the replies, I belive I now understand paging!
iProgramInCpp
Member
Member
Posts: 81
Joined: Sun Apr 21, 2019 7:39 am

Re: How can I impliment Paging

Post by iProgramInCpp »

nexos wrote:Even in that case there still is a race condition as what if the CPU speculatively reads from the junk PTE? Then you just read junk data into the pipeline
What junk PTE? There is no junk PTE. The last level means the actual page itself.

On 64-bit the page table layout is as follows, top to bottom:
* PML4 (pointed to by CR3)
* PML3 (pointed to by entries in the PML4)
* PML2
* PML1
* The pages themselves (pointed to by entries in the PML1, this is the last level I was talking about)

When mapping actual pages, you don't need to zero them out because they aren't part of the page table tree that's processed using the TLB.
Hey! I'm developing two operating systems:

NanoShell --- A 32-bit operating system whose GUI takes inspiration from Windows 9x and early UNIX desktop managers.
Boron --- A portable SMP operating system taking inspiration from the design of the Windows NT kernel.
Post Reply