MMU notifier callbacks and forking

From: Kyle Hubert
Date: Wed Apr 18 2012 - 10:51:01 EST


Hi,

I'm writing a driver that pins user memory and stores it in a page
table so the device's own IOMMU can translate into host physical
addresses. I built up the MMU notifier callbacks (invalidate_page and
invalidate_range_start) to unpin the pages when the VM state changes.
This works as I expect for mmap/munmap. However, when fork() occurs,
copy_page_range will call invalidate_range_[start|end] if the range is
a COW mapping. I think it makes sense because the page range of both
the parent and child will be changed to remove VM_MAYWRITE. If anyone
tries to write, we take a page fault, then copy and mark the page as
VM_MAYWRITE in both MMs. Do I understand this correctly?

My problem is, in my callbacks I can't distinguish between
invalidate_range_start indicating the page should be freed or the
pages permissions are changing. Is it sufficient to set the VM flags
to VM_SHARED? What is the API to do this (or is it just find_vma and
modify the vm_flags while holding the mmap_sem)? If I understand the
code, this will prevent invalidate_range_[start|end] from being called
when forking. Are there other side effects when setting this?

Thanks for your help,
-Kyle Hubert
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/