1

I have a virtual address that lies in the kernel virtual address space i.e 3GB <= vaddr <= 4GB which I want to translate to a physical address.

Taking a look at the kernel source I can see virt_to_phys () function which in turn uses : __pa(x) ((unsigned long)(x) - VIRT_PHYS_OFFSET). So does this mean that any virtual address can be converted to a physical address by this equation ?

phys_addr = virt_addr - PAGE_OFFSET (where 3GB <= virt_addr <= 4GB) or does this address translation works for some different range of virt_addr.

Does this mean that if the address of the .text section of a dynamically loaded kernel module KMod 0xf23dc038, then the physical address at which the module symbols are available will be 0xf23dc038 - 0xc0000000 ?

If this is the case then what is the use of Kernel page tables ?

Thanks in advance.

sbunny
  • 433
  • 6
  • 25
  • possible [duplicate](https://stackoverflow.com/questions/4826810/kernel-virtual-address-translation?rq=1)? – Jason Dec 29 '15 at 18:08
  • I have already gone through that question, but wasn't able to locate a clear answer – sbunny Dec 29 '15 at 18:13
  • *"So does this mean that **any** virtual address can be converted to a physical address by this equation ?"* -- No. *Virtual* means that there may not be actual physical memory to represent that address, e.g. when the page is swapped out. That function requires that the physical page of that virtual address to be resident (i.e. a mapping has to exist). – sawdust Dec 29 '15 at 20:13
  • 1
    above formula is applicable only for kmalloc and get_free_pages() , this mapping is called linear mapping but on the other hand if you vmalloc or mmap this not true entirely, there much more detailed theory behind this . – Pradeep Goswami Dec 30 '15 at 15:11
  • @PradeepGoswami, thanks for the reply, so can I use this mapping for converting virtual addresses that lie in the lower ~256MB of the kernel space reserved for the kernel ? – sbunny Dec 30 '15 at 17:41

0 Answers0