Original URL: http://www.mike.org.cn/articles/linux-kernel-mode-and-user-mode-distinction/
The kernel state and user state are two operating levels of the OS, and Intel CPUs provide ring0-ring3 four levels of operating mode. RING0 level is highest, Ring3 lowest.
When a task (process) executes a system call and is executed in the kernel code, we say that the process is in the kernel run state (or simply the kernel state). At this point the processor is executed in the highest privileged (level 0) kernel code. When the process is in the kernel state, the kernel code that executes will use the kernel stack of the current process. Each process has its own kernel stack. When the process executes the user's own code, it is said to be in the user's running state (user state). That is, the processor is running in the least privileged (level 3) user code.
In the kernel state, the CPU can execute any instruction and the CPU will only perform the non-privileged instruction under the user state. When the CPU is in the kernel state, can enter the user state freely, and when the CPU is in the user state, the user switch from the user state to the kernel state only in the system call and interrupt, the general program is run in the user state, when the program needs to use the system resources, you must call the soft interrupt into the kernel state.
Linux uses the RING3 level to run the user state, RING0 as the kernel state, without using Ring1 and Ring2. The RING3 state cannot access RING0 's address space, including code and data. The 4GB address space of the Linux process, the 3g-4g part is shared, is the kernel-State address space, which is stored in the entire kernel code and all kernel modules, as well as the data maintained by the kernel. The user runs a program, the process created by the program is run in the user state, if you want to perform file operations, network data transmission, and so on, must be called through Write,send, and other system calls, these system calls will call the kernel code to complete the operation, then, you must switch to RING0, Then enter the kernel address space in the 3GB-4GB to execute the code to complete the operation, after completion, switch back to Ring3, back to the user state. In this way, the user-state program can not arbitrarily operate the kernel address space, with a certain degree of security protection.
The difference between "go" Linux kernel State and user state