HOS wrote:
i'm sure this is a stupid question... but could somebody tell me why kernel/application address space must be in completely separate virtual addresses? is it because system calls do not really change the address space and therefore need to be able to see the kernel's memory and the current application's memory all at once? or is it for some other reason?
tia
Kernel memory must be present in every address space because every process must be able to call the kernel
As for this all, Tim is correct in just about all aspects, but 1.
It is not REQUIRED to have all that memory in all user address spaces. It is very useful though.
To access the kernel you only need a way to access it. That is through the IDT, through external interrupts (Linus forbid), through some arcane ways you devise yourself, or through normal switching of process contexts. However, all of these have a huge overhead. You need to poll in some cases, other cases have huge latencies so using these methods is very unpractical.
As the Intel engineers know their bit of stealing, and do some R&D too, they know of better ways. If you map in the kernel in each address space, then the kernel pages will always be available. To execute a kernel call, no matter how hard, would be trivial, since it's all there. They also thought about the security, because it's not a good thing to let user code write to kernel space (protection of tasks from each other is one of the major points of modern OSes, but it's hard).
Therefore, most people decide for a section of the memory space to be kernel only space. This allows for very quick switching between user and kernel space, and as such, fast operating systems on a whole. The fastest alleged entry I've seen is the AMD SYSCALL interface with 3 cycles latency (afaik). After that comes SYSENTER (Intel + 32-bit AMD's) with about 5, and after those follow interrupts with 10+ latency (afaik again).
It's also done because modern processors (something like ppro+ or so) allow pages to be global, which means they don't lose their tlb's on a cr3 change. That also speeds up the process.