On 2009-04-16, Jeffrey Cao <[email protected]> wrote:
> On 2009-04-15, Peter Teoh <[email protected]> wrote:
>
>
>> "No process context" actually means that the taskstruct's
>> mm_struct->mm is NULL. This means that the pagetable CR3 are not
> That's not correct. mm is NULL does not mean no porcess context.
> Since all kernel processes/threads share the same upper 1G line address space,
> they do not have their own individual line address like user sapce proesses.
> All user space processes have their individual page table maps, but kernel
> processes share one page table maps. So mm is NULL for kernel processes.
I did some kernel source code investigation to prove my thought.
kernel_thread() calles do_fork() with the parameter CLONE_VM. that means
the kernel process will share the memory space of its parent. And this way
all the kernel threads share one memory space.
>
>> changed from its previous value. Therefore, whatever u read/write
>> to, u are reading/writing to the previous owner of the address space,
>> which is why when u do things like copy_to_user() from kernel threads,
>> u are copying to any arbitrary process that happened to be running
>> BEFORE the kernel thread is switched.
>>
>> For eg,
>>
>> /*
>> * Access another process' address space.
>> * Source/target buffer must be kernel space,
>> * Do not walk the page table directly, use get_user_pages
>> */
>> int access_process_vm(struct task_struct *tsk, unsigned long addr,
>> void *buf, int len, int write)
>> {
>> struct mm_struct *mm;
>> struct vm_area_struct *vma;
>> void *old_buf = buf;
>>
>> mm = get_task_mm(tsk);
>> if (!mm)
>> return 0;
>>
>> The above (!mm) check actually means that the API access_process_vm()
>> MUST NOT be executed from a kernel thread env, which does not have any
>> process context.
>>
> mm is NULL means the process is a kernel process, and it does not allow
> such access.
>
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to [email protected]
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [email protected]
Please read the FAQ at http://kernelnewbies.org/FAQ