Using mmap() for sharing memory between application and driver
by anujsingh.kr from LinuxQuestions.org on (#55WGC)
I am facing some problem while trying to share memory between an application and driver using mmap().
Background:
- I have an application and a corresponding driver for a device.
- I call mmap() for x-mega bytes from application mchar_mmap() is implemented in the driver to handle this call.
- In driver I allocate contiguous memory using dma_alloc_coferent() for x-megabytes (CMA is configured on the system)
- Inside mchar_mmap(), I associate the allocated memory to the user provided virtual address: remap_pfn_range(vma, vma->vm_start, mapoffset>>PAGE_SHIFT, vma->vm_end - vma->vm_start, PAGE_SHARED);
Hence the mmap() call from application passes and application receives a user virtual address corresponding(mapped) to the memory shared by the driver.
Problem description:
Now, when the application writes some data to the range, I expect it to be seen from the driver. But when I read the the address range(which was allocated and shared by driver) from driver, I am not able to get the same data which application has written.
Please suggest the possibilities of mistakes I could have done, or, is my expectation wrong.


Background:
- I have an application and a corresponding driver for a device.
- I call mmap() for x-mega bytes from application mchar_mmap() is implemented in the driver to handle this call.
- In driver I allocate contiguous memory using dma_alloc_coferent() for x-megabytes (CMA is configured on the system)
- Inside mchar_mmap(), I associate the allocated memory to the user provided virtual address: remap_pfn_range(vma, vma->vm_start, mapoffset>>PAGE_SHIFT, vma->vm_end - vma->vm_start, PAGE_SHARED);
Hence the mmap() call from application passes and application receives a user virtual address corresponding(mapped) to the memory shared by the driver.
Problem description:
Now, when the application writes some data to the range, I expect it to be seen from the driver. But when I read the the address range(which was allocated and shared by driver) from driver, I am not able to get the same data which application has written.
Please suggest the possibilities of mistakes I could have done, or, is my expectation wrong.