mmap coherency kernel to user

Aug 31, 2005 6 Replies

Hi, I have written a driver that implements mmap using the nopage method. I handle the nopage simply by supplying a page that i get from get_free_page.



As a user I'm using mmap (share mode) to get the page. I write to the memory, then I cout its contents (in user mode), then I invoke an ioctl that simply prints the content of the first bytes of the page, from the kernel point of view.



The problem is that the kernel doesn't get updated often enough. i.e. if I wait a second and invoke the ioctl I might see the new value, but if I don't wait at all I see an older value.



I guess the problem has to do with cache coherency, but I couldn't find a way to solve it (I tried flush_dcache_page before printing the content of the page, I also tried changing the VMA prot mode to no_cache but non of them helped).



The other direction is true as well, if I change the buffer in the ioctl (after the mapping) I do not see the result in the user application.



I'm using arm xscale processor. Kernel 2.6.12.



Any suggestions?



I don't think it is a cache problem. After all, the cache is the same for user and kernel space.

Post some code.

best regards Wolfgang

Thanks for the response

I checked the code and it works fine on x86. I think it has to do with the ARM, or something I miss-configured in the kernel.

regards, Eransha

No it's not, not on ARM. The dcache is VTVI so you have to invalidate through the userspace virtual mapping to see the updated data in the buffer.

-Matt

Matt, How do you invalidate it in the user space?

Try calling mmap() with the O_SYNC flag.

didn't work.

I tired another thing: unmap the buffer as soon as I write the new value, then call the ioctl, but it didn't do the trick.

doesn't unmapping need to invalidate the cache?

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required