pte_page
I use the 'pgt_offset', 'pmd_offset', 'pte_offset' and 'pte_page' inside a module to get the physical address of a user space virtual address. The physical address returned by 'pte_page' is not page aligned whereas the virtual address was page aligned. Can somebody tell me the reason?
Also, can i use these functions to get the physical address of a kernel virtual address using init_mm?
regards,
Daljeet.
Quoted 8 lines · [email protected] wrote:
I use the '
pgt_offset', 'pmd_offset', 'pte_offset' and 'pte_page' inside a module to get the physical address of a user space virtual address. The physical address returned by 'pte_page' is not page aligned whereas the virtual address was page aligned. Can somebody tell me the reason?Also, can i use these functions to get the physical address of a kernel virtual address using
init_mm?
pte_page() returns the struct page * for the page, not the page address. To get the physical address of a page use __pa(virtaddr), but this works if and only if the page is not highmem and not vmalloced.
Signature · 1 line
Brian Gerst
Quoted 8 lines · Brian Gerst
Quoted 6 lines · [email protected] wrote:
I use the '
pgt_offset', 'pmd_offset', 'pte_offset' and 'pte_page' inside a module to get the physical address of a user space virtual address. The physical address returned by 'pte_page' is not page aligned whereas the virtual address was page aligned. Can somebody tell me the reason?
Quoted 6 lines
Quoted 2 lines
Also, can i use these functions to get the physical address of a kernel virtual address using
init_mm?
pte_page()returns the struct page * for the page, not the page address. To get the physical address of a page use__pa(virtaddr), but this works if and only if the page is not highmem and not vmalloced.
Oops, I forgot that you said user page... __pa() only works for kernel addresses. I don't see any other macros that can help you. Maybe one of the VM gurus can add something here?
Signature · 1 line
Brian Gerst
Quoted 5 lines · On Wed, 30 May 2001 [email protected] wrote:
I use the '
pgt_offset', 'pmd_offset', 'pte_offset' and 'pte_page' inside a module to get the physical address of a user space virtual address. The physical address returned by 'pte_page' is not page aligned whereas the virtual address was page aligned. Can somebody tell me the reason?
__pa(page_address(pte_page(pte))) is the address you want. [or pte_val(*pte) & (PAGE_SIZE-1) on x86 but this is platform-dependent.]
Quoted 2 lines
Also, can i use these functions to get the physical address of a kernel virtual address using
init_mm?
nope. Eg. on x86 these functions only walk normal 4K page pagetables, they do not walk 4MB pages correctly. (which are set up on pentiums and better CPUs, unless mem=nopentium is specified.)
a kernel virtual address can be decoded by simply doing __pa(kaddr). If the page is a highmem page [and you have the struct page pointer] then you can do [(page-mem_map) << PAGE_SHIFT] to get the physical address, but only on systems where mem_map[] starts at physical address 0.
Ingo
Quoted 9 lines · [email protected] said:
Quoted 5 lines · On Wed, 30 May 2001 [email protected] wrote:
I use the '
pgt_offset', 'pmd_offset', 'pte_offset' and 'pte_page' inside a module to get the physical address of a user space virtual address. The physical address returned by 'pte_page' is not page aligned whereas the virtual address was page aligned. Can somebody tell me the reason?__pa(page_address(pte_page(pte))) is the address you want. [or
pte_val(*pte)& (PAGE_SIZE-1) on x86 but this is platform-dependent.]
Does this work on x86 non-kmapped highmem user pages too? (i.e. is page->virtual valid for every potential user page.)
-- Pete
Quoted 11 lines
Quoted 2 lines
Also, can i use these functions to get the physical address of a kernel virtual address using
init_mm?nope. Eg. on x86 these functions only walk normal 4K page pagetables, they do not walk 4MB pages correctly. (which are set up on pentiums and better CPUs, unless mem=nopentium is specified.)
a kernel virtual address can be decoded by simply doing
__pa(kaddr). If the page is a highmem page [and you have the struct page pointer] then you can do [(page-mem_map) <<PAGE_SHIFT] to get the physical address, but only on systems where mem_map[] starts at physical address 0.
Quoted 5 lines · Pete Wyckoff
Quoted 2 lines
__pa(page_address(pte_page(pte))) is the address you want. [or
pte_val(*pte)& (PAGE_SIZE-1) on x86 but this is platform-dependent.]Does this work on x86 non-kmapped highmem user pages too? (i.e. is
page->virtualvalid for every potential user page.)
you are right, the highmem-compatible solution is to use page-mem_map as the physical page index.
Ingo