Subject: Re: map user memory in kernel
To: Eric Haszlakiewicz <erh@nimenees.com>
From: Jaromir Dolecek <jdolecek@NetBSD.org>
List: tech-kern
Date: 11/06/2005 20:41:02
On Sun, Nov 06, 2005 at 12:47:09PM -0600, Eric Haszlakiewicz wrote:
> On Sun, Nov 06, 2005 at 12:45:43PM -0600, Eric Haszlakiewicz wrote:
> > 	The problem is that the only way you have to recognize that you're 
> > the intended target it with the userland address passed to sys_futex().
> > For this to work right, both proc's va's need to refer to the same
> > underlying memory, so there should be either a vm_page or a vm_object
> 
> er.. I meant vm_anon, not vm_page.

vm_anon is per-process thing, so we don't want to use that -
we need to use the vm_page or vm_object.

I thought this might be unsafe at first - the underlying pages
can be deallocated and memory of the previous structure could
be reused for different purpose, while we sleep blocked in futex
wait.

However, this would only happen if the page gets unmapped from
all the processes using the futex, _including_ the one currently
blocked in futex wait. In other words, this realistically cannot
ever happen. In no other scenario could the UVM structure memory
be reused for different object or purpose AFAICS.

Thus, it seems that is pretty safe to use, and we neither need
to actually map the page within the kernel nor maintain
any other context for the futex, which is neat.

Now, how do we handle page offsets? The linux futex syscall
enforces int32 alignment of the address, so single page
can hold at most 1024 futexes. We could safely provide
sizeof(struct vm_page) wait channels per mapping, so have
1024/sizeof(struct vm_page) per channel. As pointed out
by David earlier, any waiter must re-evalute the wait
condition after wakeup, so it should be safe to have several
unrelated waiters on same wait channel.

Thus, it seems implementation using vm_page kernel address
as base should be pretty workable.

Jaromir
-- 
Jaromir Dolecek <jdolecek@NetBSD.org>            http://www.NetBSD.cz/
-=- We can walk our road together if our goals are all the same;     -=-
-=- We can run alone and free if we pursue a different aim.          -=-
-- 
Jaromir Dolecek <jdolecek@NetBSD.org>            http://www.NetBSD.cz/
-=- We can walk our road together if our goals are all the same;     -=-
-=- We can run alone and free if we pursue a different aim.          -=-