Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Jun 2013 21:59:53 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Luigi Rizzo <rizzo@iet.unipi.it>
Cc:        current@freebsd.org
Subject:   Re: copyin()/copyout() constraints ?
Message-ID:  <20130612185953.GK3146@kib.kiev.ua>
In-Reply-To: <20130612180115.GA27892@onelab2.iet.unipi.it>
References:  <20130612180115.GA27892@onelab2.iet.unipi.it>

next in thread | previous in thread | raw e-mail | index | archive | help

--3D7yMlnunRPwJqC7
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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)
>=20
> 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.

--3D7yMlnunRPwJqC7
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (FreeBSD)

iQIcBAEBAgAGBQJRuMUoAAoJEJDCuSvBvK1BwL8QAIDftQ6aDRdMIUkcD8Wvp4yD
+3eKFX0HgNmGjdO9PMn4iHUp11gQ6dYwX+4hAP2jUY8e+bwBPFpsyfiwSv1UeO+e
vUIJVUfwlyeP5XKo/RLXdfkzDN516qBhoyg/gyKzoLRlOrQ3CDTPKpiM/GilCjYS
Bckx5ksPlgNzsMHJch3eqBPccS5hey6xS0EsdWKbYI78gAg03Mhg/wux9Qq0xZvL
+2F18HpOFzPCdlc2PjjF5ZOv/3kSv7pyjK/TzrXkhTs4kQAWIL+lu9DF5lq/5yME
cpKd20rUsWkPsLQ37GnuLWl4L3idR6pP7C4/A5iQcXHIbVpfwpZiCXVAIQt2XEow
xTgShw1AUYU7QRTu6U12xuv6harsCPddKjsCl3jjLo6CLeRA0l6QKNWlDmi+ozFs
+6U/IJQtfNaS0XKTryuysWUIpfJ4Bhrs0Dwqb6Djewhe7vVshf7J5ZKosgb0oiLB
Dva/Ppwdqqit7QM4FbLxdzcMcDONUiYVez8SmBnBmpUL4teyr7Qcb7gx6ZWQ0EZ6
QY8rkqcBnCV2wrNeUjeNbO7snXqhQv0D2wy9B1DSSehMMjP3rtTboUgl2TaLyock
IVGERI7rSOsdmo2BHOgtXQLPM9ZWJCaJSG1ftQO5N4FsDvyiPn5ECyKaqipNEat+
cXIp9m+wHdHYsuppZEgN
=lTiP
-----END PGP SIGNATURE-----

--3D7yMlnunRPwJqC7--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130612185953.GK3146>