Page 1 of 1

Paging and higher half kernels

Posted: Sun May 10, 2009 5:01 am
by kraks
Hi,

I think that I do understand paging, but it leaves two questions to me:
1) The wiki-page about paging doesn't mention this: Does each process need it's own page directory? (I think so but I'm not sure)
2) Does the kernel need a page-directory, too? And how does this work? Everytime control is passed to the kernel (by SysCalls or Interrupts), do I need to load the kernel-pd?

Regarding the higher-half kernel: Why needs the kernel to be mapped to user-processes? Is this to prevent the loading of kernel's page-directory? And how is the kernel-memory then protected from the user-processes? By the "user-/supervisor"-bit in the pages?

Greets,
kraks

Re: Paging and higher half kernels

Posted: Sun May 10, 2009 6:34 am
by quanganht
I'm not sure but it seems like the kernel doesn't need even a page, not to mention a page directory.

Re: Paging and higher half kernels

Posted: Sun May 10, 2009 8:18 am
by neon
kraks wrote:1) The wiki-page about paging doesn't mention this: Does each process need it's own page directory? (I think so but I'm not sure)
Yes.
kraks wrote:2) Does the kernel need a page-directory, too? And how does this work? Everytime control is passed to the kernel (by SysCalls or Interrupts), do I need to load the kernel-pd?
No. How can a user process call a SysCall or an interrupt if there is nothing there (the kernel) in that same directory address space to catch it?

The important parts of the kernel (or the entire kernel binary) should be mapped to kernel space in a processes address pace. When a new address space is created, it should be mapped to the new address space as well.

Thus it does need a page table (or several), not an entire page directory.
kraks wrote:Regarding the higher-half kernel: Why needs the kernel to be mapped to user-processes? Is this to prevent the loading of kernel's page-directory? And how is the kernel-memory then protected from the user-processes? By the "user-/supervisor"-bit in the pages?
The kernel shouldnt use its own page directory. See above. The reason is the limitation of the architecture that only one page directory can be used at once. If you are in a user process address space, and the kernel is in another, there is no way to task switch or control that process at all because there would be no way to return back to kernel land

Re: Paging and higher half kernels

Posted: Sun May 10, 2009 10:50 am
by blound
neon wrote: If you are in a user process address space, and the kernel is in another, there is no way to task switch or control that process at all because there would be no way to return back to kernel land
Are you referring to a full 4GB/4GB split of the address space? If so this is possible, osx does it.

Re: Paging and higher half kernels

Posted: Sun May 10, 2009 10:57 am
by Colonel Kernel
blound wrote:
neon wrote: If you are in a user process address space, and the kernel is in another, there is no way to task switch or control that process at all because there would be no way to return back to kernel land
Are you referring to a full 4GB/4GB split of the address space? If so this is possible, osx does it.
Sort of... There still needs to be part of the kernel mapped in each address space for system calls and interrupts. I think of the OS X "kernel address space" as just a big process that runs in ring 0.

Re: Paging and higher half kernels

Posted: Sun May 10, 2009 3:21 pm
by kraks
Ok, thank you very much neon, I think I understand now :)