Welcome! Log In Create A New Profile

custom mmap() in a driver

Posted by yoush 
custom mmap() in a driver
November 16, 2009 07:14AM
Hi

I'm looking for a way to implement a mapping of several pages prepared by kernel into caller process's space from within ioctl() call. The ioctl() in question is a sort of "bind to subdevice", and making some area accessibly read-only by the calling process is semantically part of operation.

Yes I may implement that by requiring calling process to issue mmap() after my ioctl().
And I may also call do_mmap_pgoff() from my ioctl() and then get control in my device's mmap method.

But that both will allow for mmap()'s independently of "bind ioctl", which is somewhat ugly in my case where pages to map are actually prepared by ioctl() so call to mmap() not related to call to ioctl() is incorrect operation and should be protected against.

Is there a way to implement exactly what I need - that means, map a set of vmalloc()ed pages info current process memory space from particular point in kernel code, and nothing more?
Re: custom mmap() in a driver
November 24, 2009 03:02PM
Replyint to myself.

Restricting driver's mmap() method to accept calls only from within driver is easy - just save current task before call to do_mmap_pgoff(), reset saved value after return, and check it inside mmap() method and return -EINVAL if mismatch.

However, it look like other operations with mapped area are completely out of driver's control. And it leads to issues if at unmap time - driver may not be sure that area wher it mapped it's memory is still that and not something else.

So better to require manual calls to mmap() / munmap() from userspave, thus moving responsibility for correct mapping there.

Not good sad smiley
Author:

Your Email:


Subject:


Message: