I will allocate memory in user application using malloc
and send the malloc
returned address to a kernel module through character driver interface.
I will pin the pages for this memory using get_user_pages_fast
in kernel module.
Can I use virt_to_phys
to get the address returned by malloc
.
Is it valid? If not then how can I get proper physical address?
My aim is to get physical address of user space allocated memory. I m limiting my transfer size to pagesize (4KB).
dma_map_page()
on a pinned page, or usedma_map_sg()
if you have created a scatter-gather list from the pinned pages. If you want CPU access to the page, you can usekmap_atomic()
to get a kernel virtual address for the page. Note that pages mapped withkmap_atomic()
need to be unmapped in exactly reverse order to the order they were mapped. – Ian Abbott