Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ioremapped address in kernel

I have basic query about ioremap used to map device IO addressed into kernel's virtual memory.

I would like to know if returned address from ioremap is passed to routines like virt_to_phys(), would it return back Device IO address ?

Thanks

like image 265
Amit Singh Tomar Avatar asked Aug 04 '16 07:08

Amit Singh Tomar


People also ask

What is address space in kernel?

The book uses the term "kernel address space" to refer to the partition of the virtual address space that is allocated for the kernel. Recently, Linux and other OSes have implemented page-table isolation (PTI) to mitigate the Meltdown security vulnerability.

Does the kernel use virtual addresses?

Whenever we work with virtual memory we work with two types of addresses: virtual address and physical address. All CPU access (including from kernel space) uses virtual addresses that are translated by the MMU into physical addresses with the help of page tables.

Does kernel have its own address space?

The kernel address space is statically mapped into the address space. The top 1 GB of the user's space is reserved for system elements while the bottom 1 GB holds the user code, data, stack, and heap.

Can kernel access physical memory?

The physical memory can only be directly accessed in kernel-mode debugging.


1 Answers

virt_to_phys() is only valid for virtual addresses within the kernel linear map, since it's just some fast address arithmetic, not a full software table walk. The linear map normally only covers RAM. The virtual address returned by ioremap(), however, will usually (probably always, but I don't have the patience to check every implementation) be a vmalloc address, so if you pass that to virt_to_phys() you'll get nonsense back.

like image 113
Notlikethat Avatar answered Oct 16 '22 10:10

Notlikethat