<br><br><div class="gmail_quote">2011/4/21 limp <span dir="ltr"><<a href="mailto:johnkyr83@hotmail.com">johnkyr83@hotmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Thank you all for your replies,<br>
<div class="im"><br>
> yes, "borrow" in the sense that: kernel thread DOES NOT have any process<br>
> context, and so it can be executed in any process context, and which ever<br>
> process context it is executing, when u print the CR3 value, it will<br>
belong<br>
> to that process which the kernel thread is currently executing under.<br>
<br>
</div>I've read on LKD by Robert Love book the following:<br>
"Because kernel threads do not have any pages in user-space, they do not<br>
really<br>
deserve their own memory descriptor and page tables. Despite this, kernel<br>
threads<br>
need some of the data, such as the page tables, even to access kernel<br>
memory.<br>
To provide kernel threads the needed data, kernel threads use the memory<br>
descriptor<br>
of whatever task ran previously"<br>
<br>
I can't really tell which are the data which are needed by kernel threads<br>
that the<br>
book is talking about..By combining the above with the following (from the<br>
same book):<br>
<br>
"The kernel thread can then use the previous process's page tables as<br>
needed. Because<br>
kernel threads do not access user-space memory, they make use of only the<br>
information<br>
in the address space pertaining to kernel memory, which is the same for all<br>
processes."<br>
<br>
I conclude the following:<br>
A kernel thread uses only the address space of the previously scheduled user<br>
process<br>
pertaining to kernel memory for accessing kernel memory. Also, a kernel<br>
thread is using<br>
the virtual memory mechanism of user process to access kernel memory. That<br>
is, it runs<br>
on user-space but accesses *only* kernel memory, right? - i.e. it is<br>
basically a user<br>
process that access only Kernel memory - Why kernel threads cannot directly<br>
access<br>
kernel memory and use a mechanism used in user-space for accessing it?<br>
<br></blockquote><div>because all virtual memory access need a page table, so since the kernel thread DOES not have a page table (as it does not have a process context), as pagetable are stored per-process (why? because so that through the MMU translation mechanism, each process thought that it has 4GB of memory available), so it has no choice but to use the process's pagetable. </div>
<div><br></div><div>but because of the kernel area is shared, and therefore, the pagetable for the kernel part is also shared by all process's pagetable. and the base of this table is pointed to by hardware - CR3, but only when protected mode is setup.</div>
<div><br></div><div>note too there is a such a thing as linear and non-linear mapping: getting physical address from virtual address is easy....just reference the page table. but getting the reverse is easy - if it is linearly mapped - which is true for the kernel memory (GFP_KERNEL) but not true for the highmem part (GFP_HIGHMEM). Looking into vmalloc.c for non-linear memory allocation.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Sorry for the many questions, any help will be greatly appreciated guys.<br>
<br>
P.S. Please correct me if I interpreted something wrong.<br>
<br>
Regards,<br>
<br>
John K.<br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br>Regards,<br>Peter Teoh<br>