kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: dhylands@gmail.com (Dave Hylands)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Contents of CR3 register when a kernel thread is executed
Date: Wed, 20 Apr 2011 18:33:05 -0700	[thread overview]
Message-ID: <BANLkTinr-FQ3D_LGQEsjgUFG9JoKAC7agA@mail.gmail.com> (raw)
In-Reply-To: <SNT111-DS213EE4C439C4B865D332CAA7930@phx.gbl>

Hi John,

2011/4/20 limp <johnkyr83@hotmail.com>:
> Thank you all for your replies,
>
>> yes, "borrow" in the sense that: ? kernel thread DOES NOT have any process
>> context, and so it can be executed in any process context, and which ever
>> process context it is executing, when u print the CR3 value, it will
> belong
>> to that process which the kernel thread is currently executing under.
>
> I've read on LKD by Robert Love book the following:
> "Because kernel threads do not have any pages in user-space, they do not
> really
> deserve their own memory descriptor and page tables. 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, kernel threads use the memory
> descriptor
> of whatever task ran previously"
>
> I can't really tell which are the data which are needed by kernel threads
> that the
> book is talking about..By combining the above with the following (from the
> same book):

The data being referred to is the memory which contains the page
tables which provide the mapping from virtual to physical addresses.

The page tables are actually allocated out of system memory. The MMU
only uses them, it doesn't have any memory of its own (except for
things like TLB caches).

> "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."
>
> I conclude the following:
> A kernel thread uses only the address space of the previously scheduled user
> process
> pertaining to kernel memory for accessing kernel memory. Also, a kernel
> thread is using
> the virtual memory mechanism of user process to access kernel memory. That
> is, it runs
> on user-space but accesses *only* kernel memory, right? - i.e. it is
> basically a user
> process that access only Kernel memory - Why kernel threads cannot directly
> access
> kernel memory and use a mechanism used in user-space for accessing it?

Well - yeah that's sort of right. Except that kernel threads aren't
really in any "process", unless perhaps you consider the entire kernel
to be one big process.

Every user process has the kernel space mapped into it, but it's not
accessible unless you're in "supervisor" mode. When you transition
from user space to kernel space, you switch to supervisor mode and you
can now access kernel memory.

For example, 0xc0000000 - 0xffffffff is typically your kernel space,
and 0x00000000 - 0xbfffffff is user space (there are lots of
variations, this is just an example).

Since the kernel threads don't access the memory below 0xc0000000,
every kernel thread sees the same mapping.

-- 
Dave Hylands
Shuswap, BC, Canada
http://www.davehylands.com

  reply	other threads:[~2011-04-21  1:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Acv9yv2t5DK6iTKkQTODS14CKbqf+w==>
2011-04-18 13:17 ` Contents of CR3 register when a kernel thread is executed limp
2011-04-18 19:36   ` Mulyadi Santosa
2011-04-19 12:49   ` Peter Teoh
2011-04-20 22:23     ` limp
2011-04-21  1:33       ` Dave Hylands [this message]
2011-04-21  4:15       ` Peter Teoh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTinr-FQ3D_LGQEsjgUFG9JoKAC7agA@mail.gmail.com \
    --to=dhylands@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).