Jason
Jason

Reputation: 29

The relationship between kernel mode and kernel space, user mode and user space?

The virtual memory in Linux can be split into two parts: user address space and kernel address space.

The task works in either kernel mode or user mode according to the privilege level.

But considering i386 arch, what's the relationship between kernel mode and kernel address space, user mode and user address space?

Upvotes: 0

Views: 726

Answers (1)

Jason
Jason

Reputation: 29

According to the comments and personal research, generally there is not a forced relationship between kernel mode and kernel address space, user mode and user address space. For modern OS(Linux), the relationship is 100% controlled by OS software which can map user address space for kernel mode can access to, typically with highmem.
Basically, the division of virtual memory space is a convention reduces fragmentation and make it easy to recognize when programming. For the 86x86 arch, there does have a "relationship" based on the following facts.

  1. When the task is trapped to kernel mode, the CPL within cs register is set to 0 which means highest privilege. Technically, it can access to all the virtual memory space. A kind of map, normally highmen, is used to make kernel safely access to user address space.
  2. When the task is in user mode, the CPL within cs register is set to 3 which means lowest privilege. It can only access to the segment whose DPL field is 3. However, the segments in kernel address space all filled with the 0 DPL which means user mode task does not have the privilege to access. The two points don't consider the RPL, there should only be a condition that DPL >= max(RPL,CPL) the segment can be accessed.

Upvotes: 1

Related Questions