LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Convert vmalloc address to physical address (https://www.linuxquestions.org/questions/linux-kernel-70/convert-vmalloc-address-to-physical-address-908464/)

prabagaranvt 10-16-2011 01:23 PM

Convert vmalloc address to physical address
 
Hi all ,

vmalloc returns the virtual address.
How to convert this virtual address to physical address.

FYI : address returned by kmalloc can be converted to physical address using __pa(addr) macro.

Regards,
Prabagaran.

smallpond 10-18-2011 04:00 PM

Quote:

Originally Posted by prabagaranvt (Post 4499948)
Hi all ,

vmalloc returns the virtual address.
How to convert this virtual address to physical address.

FYI : address returned by kmalloc can be converted to physical address using __pa(addr) macro.

Virtual address ranges a) might not exist in physical memory, and b) might not be contiguous, so what you are asking for is not possible in the general case.

prabagaranvt 10-19-2011 08:31 AM

Hi,

I have a statement

addr = vmalloc(size);

Now addr is the virtual address.
I need to know where it is located in the RAM(ie., physical address).
How can i know the physical address of this addr?.

smallpond 10-19-2011 01:17 PM

Quote:

Originally Posted by prabagaranvt (Post 4502509)
Hi,

I have a statement

addr = vmalloc(size);

Now addr is the virtual address.
I need to know where it is located in the RAM(ie., physical address).
How can i know the physical address of this addr?.

I guess you either didn't read my reply or didn't believe me, so please see here:
http://www.makelinux.net/ldd3/chp-8-sect-4
"When a driver needs a real physical address (such as a DMA address, used by peripheral hardware to drive the system's bus), you can't easily use vmalloc."

sundialsvcs 10-21-2011 08:24 AM

Indeed ... please read that manual section carefully!

Now consider, "why is it so?" The answer, of course, is that this function allocates virtual memory. This is a chunk of memory as perceived by the user-land process. It will now exist in the process's address space and be accessible to that process at thus-and-so virtual address (since by definition every address perceived by a userland program is a virtual address).

What does that mean to the kernel? As always, it means that the area is physically divided into pages ... and any of those pages may or may not at any point in time actually be resident in RAM. Actually, it might not yet exist, since physical pages (and swap space) are allocated only on-demand. (The area appears as zeroes until the process, or you, actually write to it.)

Kernel code has the prerogative to use either virtual or physical addresses, and in the case of kernel threads they can even tolerate page faults. But you must very clearly understand at all times what is going on. "With great power comes great responsibility."


All times are GMT -5. The time now is 06:18 AM.