Subject: Re: map user memory in kernel
To: Emmanuel Dreyfus <>
From: Wolfgang Solfrank <>
List: tech-kern
Date: 11/05/2005 12:22:45

> In order to fully implement Linux futex(2) in COMPAT_LINUX, I must be 
> able to have user processes sleep and wakeup (the futex system call is
> here to provide the sleep and wakeup facility) on userland addresses. 
> The thing must work for different userland addresses corresponding to
> the same memory mapped in different processes.
> I assume that I'd have the thing done by mapping the userland memory
> in kernel address space and relying on the kernel address to sleep.
> Does that look reasonnable?

There seems to be a common misconception about the "ident" parameter
used by sleep/wakeup.  Nothing really touches this address.  It's only
used to match the sleep against the wakeup.

That's one of the reasons that you shouldn't (mustn't!) rely on the
return from a sleep to really mean that the wakeup you intended to
wake this sleep actually did happen.  You should therefor test the
condition that made you go to sleep again after the return.

So no need to actually map the page into memory.  Just make a more or
less unique address out of the address given (like e.g. use the physical
address on machines where physical and virtual address sizes match) and be
done with it.

Note that I don't have an idea about Linux's futex semantics.  In case
it does guarrantee that a return from the sleep side means that the
wakeup side got called, you'd have to allocate a data structure to
match those sides and keep history of the wakeup call, and then you
probably should use the address of this data structure in the sleep/wakeup

Hope it helps.

ws@TooLs.DE                            Wolfgang Solfrank, TooLs GmbH