mapping driver allocated memory to process

Malte Vesper malte.vesper at postgrad.manchester.ac.uk
Wed Mar 25 22:28:07 EDT 2015


Hello,

I am working on a DMA driver and noticed that consistent dma performs 
rapidly better than streaming dma. Since I want to employ zero copy dma 
I want to map the memory the driver allocates with dmam_alloc_coherent 
into the user process. I would like to implement this using IOCTL rather 
than mmap.


I had a look at dma_mmap_attrs, which expects a vm_area struct. Is it ok 
to simply allocate one and fill it with apropriate data like in 
mmap_region(lxr.free-electrons.com/source/mm/mmap.c#L1594), if so I 
noticed that the kernel uses a memory pool (vm_area_cachep), which I 
apparently can't access (dmesg: Unknown symbol vm_area_cachep (err 0)), 
can I just wildly allocate or is there some black magic connected that 
relies on vma structs beeing in the area of the pool?

I also looked at install_special_mapping which seems even closer to what 
I want to do (I do not need to provide a vma), however it is not 
exported as well. Is there a way to use it in a dynamic module anyway? I 
saw it used mainly in arch specific code.

do_mmap, seems to have disappeared (at least it is not in any sane place 
in the 3.19 lxr),
do_mmap_pgoff seems to be wrong for the job since I do not see how to 
tell that function that I have struct** page, rather than a file to back 
the mapping.

I would greatly appreciate pointers on up to date summaries on the 
memory system, http://linux-mm.org/ seems slightly stale, 
https://www.kernel.org/doc/gorman/pdf/understand.pdf was helpful, 
although I could not entirly read it (yet).

Any pointers to helpful functions, or gotchas are much appreciated. (I 
hope I managed to make it clear, that I tried to do my research + trial 
and lots of error...).

Thanks,
Malte



More information about the Kernelnewbies mailing list