mmap coherency kernel to user

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?

Reply to
eransha
Loading thread data ...

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

Reply to
Wolfgang Mües

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

Reply to
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

Reply to
Matt Porter

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

Reply to
eransha

Try calling mmap() with the O_SYNC flag.

Reply to
Geronimo W. Christ Esq

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?

Reply to
eransha

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.