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]

 



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/



[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