Re: Why no trylock for read/write_bh?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 16, 2009 at 9:56 AM, Jeffrey Cao <jcao.linux@xxxxxxxxx> wrote:
> On 2009-04-16, Jeffrey Cao <jcao.linux@xxxxxxxxx> wrote:
>> On 2009-04-15, Peter Teoh <htmldeveloper@xxxxxxxxx> 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.

Which is memory space of kernel itself, right?
And off course this means a kernel thread can be cloned from an existing kernel
thread only.

CMIIW

Thanks,

>
>>
>>> 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 ecartis@xxxxxxxxxxxx
>> Please read the FAQ at http://kernelnewbies.org/FAQ
>>
>>
>
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>



-- 
Pradeep

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux