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
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.
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.
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.
The physical memory can only be directly accessed in kernel-mode debugging.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With