I see. Your explanation makes sense, and close won't affect the mmap
(unless you explicitly trigger it in the driver, which you should).
Other drivers deal with this; you may want to go grepping for do_munmap
and see how they handle it.
[ > pw@osc.edu said: ]
> > However, do_munmap() will call zap_page_range() for you and take care of
> > cache and TLB flushing if you're going to do this in the kernel.
>
> I'm not sure if I could use do_munmap() -- how will I know if the user
> program has called munmap() already, and then mmap()ed something else in the
> same place? Then I'd be killing the wrong mapping...
Look at drivers/char/drm, for example. At mmap time they allocate a
vm_ops to the address space. With that you catch changes to the vma
structure initiated by a user mmap, munmap, etc. You could also
dynamically map the pages in using the nopage method (optional).
The less elegant way of doing this is to put in your userspace API some
conditions which say: if you do the following:
open(fd);
ioctl(fd, give_me_the_buf);
munmap(some_or_all_of_the_buf);
buf2 = mmap(...);
close(fd); /* or ioctl(fd, shrink_the_buf); */
buf2[27] = 3;
you will be killed with a sigbus. I.e. don't manually munmap the
region.
-- Pete
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/