Re: [uml-devel] Re: [PATCH 07/10] uml: avoid fixing faults whileatomic

From: Linus Torvalds
Date: Thu Sep 22 2005 - 15:55:17 EST




On Thu, 22 Sep 2005, Blaisorblade wrote:
>
> Exactly - the point is: is it legal to call copy_from_user() while holding a
> spinlock (which is my original question)? Or should copy_from_user try to
> satisfy the fault, instead of seeing in_atomic() or something similar and
> fail?

It is not legal to call copy_to/from_user() under a spinlock in general.

But what _is_ legal to do is something slightly more complex, ie

spin_lock(...)
inc_preempt_count();
ret = __copy_from_user_inatomic(..)
dec_preempt_count();
spin_unlock();

but you have to realize that the copy-from-user will fail if the target is
swapped out (so the code that does things like this has to look at the
return value, and if the copy didn't copy anything it needs to release the
locks and do it all over again without the atomic thing).

We don't do it very much, because it gets more complicated and it hasn't
historically been legal, but it could in theory be very useful if you hold
a lock and want to avoid releasing and re-taking it just to do a user
access.

Right now the only case where that happens is the futex code, and maybe
that's a very special case. But maybe it isn't.

Linus
-
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/