Capturing all writes as fault on a memory mapped page.

Greg KH greg at kroah.com
Wed May 28 10:25:29 EDT 2014


On Wed, May 28, 2014 at 07:13:55PM +0530, Pranay Srivastava wrote:
> Actually trying to do something like if there's a write being done on
> the page by a task currently then other tasks should wait( was hoping
> that the fault handler code would be called for write but doesn't
> happen that way).

If you have multiple writers on the same page, why would you want any
other writer to wait?  That's the joy of mmap, you don't have to worry
about any of this from userspace, the kernel backing store handles it
all for you automatically.

> Yes through write operation I can do with mutex but I was wondering
> what if this has to be done through mmap of my misc_device then no
> read/write calls involved so just wanted to see how would I stop
> multiple writes to my misc_device.

Either you don't allow multiple opens, or you just live with the mess
that userspace is wanting to do here.

> Perhaps there are other methods as to how device memory can be mapped
> to user space? or they aren't at all? Not really sure just reading and
> trying.

As you mapped it to userspace, it's now up to the user to deal with any
serialization that it wants to enforce, it's out of the hands of your
misc driver.

good luck,

greg k-h



More information about the Kernelnewbies mailing list