Re: Re: does pmd_offset return the physical address or virtual address of the page table?

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

 



Thx Nitin & Raj,

So MMU takes care of the va-->pa part, CPU (or kernel) just operates in the
va way, in the other words, every thing comes to va->pa issues then it comes
to MMU.

pgd_offset gives the va of its entry (relevant to the given mm argument) and
pmd_offset takes the pgd_t from pgd_offset, grab the va inside pgd_t struct
and gives the va(base address) of the relevant PMD

pgd_t *pgd;
pmd_t *pmd;
pte_t *ptep, pte;

pgd=pgd_offset(mm, va);
pmd=pmd_offset(pgd, va);

once the va(base address) of the relevant PMD is passed to pte_offset, it
gives the va of its entry, pte_t, which wraps the va(base address) of the
corresponding page inside and can be extract easily via pte = *ptep

ptep=pte_offset(pmd,va);
pte=*ptep;

following up these, I guess every PGD entry, pgd_t, hold a virtual address
of the PMD, every PMD entry, pmd_t, holds the virtual address of the PTE,
finally, PTE entries hold the virtual address of the page.

whoopee !! is that right ?

Tsai



----- Original Message ----- 
From: "nitin ahuja" <nitin2ahuja@xxxxxxxxxxxxx>
To: <rajagopalan.duraisamy@xxxxxxxxx>
Cc: <kernelnewbies@xxxxxxxxxxxx>
Sent: Wednesday, April 06, 2005 11:11 PM
Subject: Re: Re: does pmd_offset return the physical address or virtual
address of the page table?


Hi Folks,

Let me explain you the complete scenario.

When you access any address inside kernel (as seen by cpu), it is virtual
address. So, all the pointers(pgd, pmd, pte etc) in kernel point to
somewhere within the virtual address space .

Virtual to physical address translation is done by MMU and is transparent to
the cpu. To translate a virtual address to corresponding physical address,
MMU uses page table global directory and page tables. To start translation
MMU needs address of the page global directory in cr3.

    But, this address in cr3 has to be physical  address, otherwise it would
cause chicken and egg problem as MMU doesn't know anything about virtual
address (you are translating virtual address and you come across a virtual
address). So, conceptually and from MMU's tenet, pgd is a physical address.
Now, pgd's offset is just a 32-bit positive value which is added to pgd's
base address (inside cr3 register) to find which page table or which middle
level page directory. It is just like added a 32-bit positive value to
32-bit physical address, which results in a 32-bit physical address again
(pmd is also physical address from MMU's tenet). Same is the case with pmd
and pte.

Above para explains as seen or done by MMU (hardware transparent to cpu or
kernel), but when you are inside kernel and want to access pgd's, pmd's or
pte's then address is virtual address.

For example:

Value of the pgd/pgdir of a process is converted to physical address and
then loaded in cr3 register when process switch is made.

#define load_cr3(pgdir) \
        asm volatile("movl %0,%%cr3": :"r" (__pa(pgdir)))

refer file "include/asm-i386/processor.h"

NOTE: pgdir is virtual address (being inside or accessed by kernel) whereas
__pa(pgdir) returns corresponding physical address.

Nitin


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           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