cdevpriv and mmap(2)

From: Kostik Belousov <kostikbel_at_gmail.com>
Date: Sun, 14 Sep 2008 20:48:01 +0300
When implementing cdevpriv, I completeley missed the support for
d_mmap() driver method. This method is called by the kernel (at least)
twice: one time to validate the mmaped region and protection mode (see
vm/device_pager.c:dev_pager_alloc()), and second time to obtain the
physical address when serving page fault (see dev_pager_getpages()).

Support for cdevpriv for the first call(s) is trivial, and is
implemented by the patch below. Second calls are much harder and
essentially require attaching cdevpriv bookkeeping data to the struct
vm_map_entry. In fact, I am not sure whether this support for the second
time calls is needed at all in real usage.

I Cc:ed people that pointed me to the issue, please evaluate the
patch against your needs. I think I will commit it shortly after your
feedback. On the other hand, I would think about implementing full
support for d_mmap only if actually needed.

Thanks !

diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c
index 7e6b04f..c3f08b0 100644
--- a/sys/vm/vm_mmap.c
+++ b/sys/vm/vm_mmap.c
_at__at_ -391,8 +391,10 _at__at_ map:
 		goto done;
 	}
 
+	td->td_fpop = fp;
 	error = vm_mmap(&vms->vm_map, &addr, size, prot, maxprot,
 	    flags, handle_type, handle, pos);
+	td->td_fpop = NULL;
 #ifdef HWPMC_HOOKS
 	/* inform hwpmc(4) if an executable is being mapped */
 	if (error == 0 && handle_type == OBJT_VNODE &&

Received on Sun Sep 14 2008 - 15:48:09 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:35 UTC