Skip to contentSkip to conversation

how to translate virtual memory addresss into physical address ?

DISCUSSION BenHanokh Gabriel 2 participants 5 messages Sep 20, 2000 Memory management

lore
Share & tools
lore
#0 lore raw

hi

how do i get in a kernel module the physical address from a virtual memory addreess ( where the virual address can be either main-memory address or mmaped pci memory) ?

please CC me for any answer

regards
Benhanokh Gabriel

-----------------------------------------------------------------------------
"If you think C++ is not overly complicated, just what is a protected abstract virtual base class with a pure virtual private destructor, and when was the last time you needed one?"
-- Tom Cargil, C++ Journal, Fall 1990. --

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

#1 lore raw

Hi,

Quoted 4 lines · BenHanokh Gabriel

how do i get in a kernel module the physical address from a virtual memory addreess ( where the virual address can be either main-memory address or mmaped pci memory) ?

When you say "main memory", do you mean user space virtual addresses or just kernel space?

For kernel-space main memory, you just use virt_to_phys().

For pci memory, you usually don't do anything --- you *start* with the physical address and work from there, creating a virtual address with ioremap(). You can do the translation backwards, but only by walking page tables.

You might want to use map_user_kiobuf() for user-space addresses if you are running on 2.4 (or 2.2 with the raw IO patches). I've got diffs for a map_kernel_kiobuf() too, for 2.4 only. Those will also deal properly with things like locking user pages in memory and dealing with high memory on Intel boxes.

Cheers,
Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

#2 lore raw
Quoted 9 lines · Stephen C. Tweedie

Hi,

Quoted 2 lines · BenHanokh Gabriel

how do i get in a kernel module the physical address from a virtual memory addreess ( where the virual address can be either main-memory address or mmaped pci memory) ?

When you say "main memory", do you mean user space virtual addresses or just kernel space?

my module will have to deal with user space virtual addresses which are mapped either to the computer "main-memory" or to a pci-device memory.

Quoted 3 lines

For pci memory, you usually don't do anything --- you *start* with the physical address and work from there, creating a virtual address with ioremap().

this is only possible when my module is the pci-device driver, which is not the case here

Quoted 2 lines

You can do the translation backwards, but only by walking
page tables.

how do i do this ? i tought that pci-memory is not pageable

Quoted 6 lines

You might want to use map_user_kiobuf() for user-space addresses if you are running on 2.4 (or 2.2 with the raw IO patches). I've got diffs for a map_kernel_kiobuf() too, for 2.4 only. Those will also deal properly with things like locking user pages in memory and dealing with high memory on Intel boxes.

will the map_user_kiobuf handle pci-device memory correctly (AFAIK locking pci memory is meaningless and that its memory is not split into pages ) ?

regards
Benhanokh Gabriel

-----------------------------------------------------------------------------
"If you think C++ is not overly complicated, just what is a protected abstract virtual base class with a pure virtual private destructor, and when was the last time you needed one?"
-- Tom Cargil, C++ Journal, Fall 1990. --

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

#3 lore raw

Hi,

Quoted 2 lines · BenHanokh Gabriel

my module will have to deal with user space virtual addresses which are mapped either to the computer "main-memory" or to a pci-device memory.

User space virtual addresses aren't necessarily mapped anywhere. They can be swapped out, or for mmap they might not yet be faulted in at all. You have to deal with all the complications of faulting the page and pinning it in memory if you want to deal with user virtual addresses. I'd definitely use map_user_kiobuf for this, but that cannot yet deal with pci device memory.

Quoted 3 lines
Quoted 2 lines

You can do the translation backwards, but only by walking
page tables.

how do i do this ? i tought that pci-memory is not pageable

It's not pageable, but the virtual-to-physical address translation still uses page tables. "Non-pageable" just means that the page table entries cannot get paged out, not that they don't exist.

Quoted 2 lines

will the map_user_kiobuf handle pci-device memory correctly (AFAIK locking pci memory is meaningless and that its memory is not split into pages ) ?

Not yet, no. It can (and does) on the 2.2 version, but 2.4 encodes the kiobuf pages as "struct page *" pointers and we need to teach it how to generate such structs for dynamically-allocated memory regions such as PCI.

Cheers,
Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

#4 lore raw
Quoted 7 lines · Stephen C. Tweedie

User space virtual addresses aren't necessarily mapped anywhere. They can be swapped out, or for mmap they might not yet be faulted in at all. You have to deal with all the complications of faulting the page and pinning it in memory if you want to deal with user virtual addresses. I'd definitely use map_user_kiobuf for this, but that cannot yet deal with pci device memory.

how can i tell given a user-space virtual address, if that address is a "normal" main-memory address( which i can pass to map_user_kiobuf ) or that it is a pci mmaped address( which i have to deal with it myself ) ?

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

You can do the translation backwards, but only by walking
page tables.

how do i do this ? i tought that pci-memory is not pageable

It's not pageable, but the virtual-to-physical address translation still uses page tables.

can you explain please with more details how to translate from virtual user-space pci mmaped address to a physical address?

Quoted 2 lines

"Non-pageable" just means that the page table entries cannot get paged out, not that they don't exist.

does the kernel have a page emulation for pci-memory ?

Quoted 8 lines
Quoted 1 line

will the map_user_kiobuf handle pci-device memory correctly (AFAIK locking pci memory is meaningless and that its memory is not split into pages ) ?

Not yet, no. It can (and does) on the 2.2 version, but 2.4 encodes

the kiobuf pages as "struct page *" pointers and we need to teach it

how to generate such structs for dynamically-allocated memory regions such as PCI.

when do you think we are going to see implemenation of the map_user_kiobuf supporting pci-memory ? will this be done for kernel 2.4 or only for the 2.5

regards
Benhanokh Gabriel

-----------------------------------------------------------------------------
"If you think C++ is not overly complicated, just what is a protected abstract virtual base class with a pure virtual private destructor, and when was the last time you needed one?"
-- Tom Cargil, C++ Journal, Fall 1990. --

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/