Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In kernel 3.8, how the first user process is switched into user mode while kernel_execve is removed

Tags:

linux-kernel

In kernel 3.8.x and later version, the definition for run_init_process is changed.

The following is the new definition for run_init_proces in kernel 3.8.

 static int run_init_process(const char *init_filename) {
         argv_init[0] = init_filename;
        return do_execve(init_filename,
                (const char __user *const __user *)argv_init,
                 (const char __user *const __user *)envp_init); }

Compared to the definition in kernel 3.7.x and old version.

static int run_init_process(const char *init_filename) {
         argv_init[0] = init_filename;
         return kernel_execve(init_filename, argv_init, envp_init); }

The most critical part in kernel_execve is that it will call the ret_from_kernel_execve, which will switch into the user mode then.

In the new definition, kernel_execve is gone. My question is how the first user process is switched to the user mode then.

like image 884
hseagle Avatar asked Apr 16 '13 01:04

hseagle


People also ask

How a user mode is transferred to kernel mode?

The transition from user mode to kernel mode occurs when the application requests the help of operating system or an interrupt or a system call occurs. The mode bit is set to 1 in the user mode. It is changed from 1 to 0 when switching from user mode to kernel mode.

What is the first user space process started by the kernel?

The init process After the kernel is booted and initialized, the kernel starts the first user-space application. Init is executed by the kernel and not a user process, and expects to have a process id of 1.

How does kernel manage process?

Because kernel processes execute in the more privileged kernel protection domain, a kernel process can access data that user processes cannot. Kernel processes must be provided with a valid cross-memory descriptor to access address regions outside the kernel global address space or kernel process address space.

When the kernel decides that it should execute another process it does A_____?

An interrupt notifies the kernel when the device has satisfied the read, so the former process can resume the execution. One way to provide reentrancy is to write functions so that they modify only local variables and do not alter global data structures.


1 Answers

The successful do_execv() sets up the current process to run the new program (e.g. via load_elf_binary()), and then returns 0 to run_init_process(), which returns 0 to kernel_init(), which also returns 0, and was called as part of:

    kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);

This is where the rules from https://lwn.net/Articles/520227/ come in: our fn() has returned 0 after an execve, so "the thread will proceed into userland context created by that execve".

like image 80
SamB Avatar answered Nov 13 '22 14:11

SamB