my understanding is that user task can access both 3G of user space and 1G of kernel space. But kernel task can only access its only 1G kernel space. But in task_struct, it links to vm_area_struct which points to user space, am I right? If right, then this means kernel task can also access user space directly?
Share
Below is from Robert Love’s LKD3: The mm_struct and Kernel Threads (P309)
Kernel threads do not have a process address space and therefore do not have an associ-
ated memory descriptor.Thus, the mm field of a kernel thread’s process descriptor is NULL .
This is the definition of a kernel thread—processes that have no user context.
This lack of an address space is fine because kernel threads do not ever access any user-
space memory. (Whose would they access?) Because kernel threads do not have any pages
in user-space, they do not deserve their own memory descriptor and page tables. (Page
tables are discussed later in the chapter.) Despite this, kernel threads need some of the
data, such as the page tables, even to access kernel memory.To provide kernel threads the
needed data, without wasting memory on a memory descriptor and page tables, or wast-
ing processor cycles to switch to a new address space whenever a kernel thread begins
running, kernel threads use the memory descriptor of whatever task ran previously.
Whenever a process is scheduled, the process address space referenced by the process’s
mm field is loaded.The active_mm field in the process descriptor is then updated to refer
to the new address space. Kernel threads do not have an address space and mm is NULL .
Therefore, when a kernel thread is scheduled, the kernel notices that mm is NULL and keeps
the previous process’s address space loaded.The kernel then updates the active_mm field
of the kernel thread’s process descriptor to refer to the previous process’s memory
descriptor.The kernel thread can then use the previous process’s page tables as needed.
Because kernel threads do not access user-space memory, they make use of only the
information in the address space pertaining to kernel memory, which is the same for all
processes.