copyin()/copyout() constraints ?

Konstantin Belousov kostikbel at gmail.com
Wed Jun 12 18:59:58 UTC 2013


On Wed, Jun 12, 2013 at 08:01:15PM +0200, Luigi Rizzo wrote:
> hi,
> is it possible to run copyin() or copyout() in one of these cases:
> 1. while holding a spinlock
> 2. while holding a regular mutex/lock
> 3. while holding a read lock (on an RWLOCK or RMLOCK)
> 4. while holding a write lock (on an RWLOCK or RMLOCK)
> 
> I suspect #1 is forbidden, but am a bit unclear for the
> other cases.

The rules for copyin/copyout/uiomove come from the fact that usermode
access might require VM handling the page fault, which might further
require VM access to the VFS/filesystem and device.  If the filesystem
is NFS, then there is a network access down the stack.

As result, you cannot hold any lock which may be recursed, or any
non-sleepable lock.  In other word, answer to all your four questions
is no, since kernel cannot sleep while owning spinlock, mutex,
rmlock or rwlock.

In practical terms, you could only own some private sleepable lock which is
before any other kernel lock.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-current/attachments/20130612/043f7c5c/attachment.sig>


More information about the freebsd-current mailing list