vitual address to physicall address mapping happens inside kernel which has the control over the page tables.Is there any way to get the physical address corresponding to a given virtual address.?
Asked
Active
Viewed 309 times
0
-
In kernel space or in user space? – Some programmer dude Sep 11 '14 at 07:27
-
possible duplicate of [Simplest way to get physical address from the logical one in linux kernel module](http://stackoverflow.com/questions/6252063/simplest-way-to-get-physical-address-from-the-logical-one-in-linux-kernel-module) – Paul R Sep 11 '14 at 07:27
-
possible duplicate of [Is there any API for determining the physical address from virtual address in Linux](http://stackoverflow.com/questions/5748492/is-there-any-api-for-determining-the-physical-address-from-virtual-address-in-li) – Michael Petch Sep 11 '14 at 07:38
-
There are often multiple *virtual* addresses mapping to the same physical address. – artless noise Sep 15 '14 at 14:42
2 Answers
3
You can you use __pa(virtual_address)
macro to get physical address from a virtual address.
All physical pages are stored in the global mem_map[page number]
and from this global you can also map physical and virtual addresses.
As well, you can try to use the virt_to_phys()
function.

artless noise
- 21,212
- 6
- 68
- 105

Pradeep Goswami
- 1,785
- 1
- 15
- 24
0
If you're talking kernel space, virt_to_phys() can be used.
virt_to_phys: The returned physical address is the physical (CPU) mapping for the memory address given. It is only valid to use this function on addresses directly mapped or allocated via kmalloc. It means It is used by the kernel to translate kernel virtual address (not user virtual address) to physical address

JnRambo
- 55
- 7