From owner-freebsd-hackers@FreeBSD.ORG Wed Mar 11 14:38:40 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 36634106566C for ; Wed, 11 Mar 2009 14:38:40 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.terabit.net.ua (mail.terabit.net.ua [195.137.202.147]) by mx1.freebsd.org (Postfix) with ESMTP id CD0CB8FC0C for ; Wed, 11 Mar 2009 14:38:39 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from skuns.zoral.com.ua ([91.193.166.194] helo=mail.zoral.com.ua) by mail.terabit.net.ua with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63 (FreeBSD)) (envelope-from ) id 1LhPZu-000N7s-3O; Wed, 11 Mar 2009 16:38:38 +0200 Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id n2BEcULU002094 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 11 Mar 2009 16:38:30 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3) with ESMTP id n2BEcUe9015166; Wed, 11 Mar 2009 16:38:30 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3/Submit) id n2BEcUej015165; Wed, 11 Mar 2009 16:38:30 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 11 Mar 2009 16:38:30 +0200 From: Kostik Belousov To: pluknet Message-ID: <20090311143830.GJ41617@deviant.kiev.zoral.com.ua> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="jlzMyYUOO8BCbMOc" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: ClamAV version 0.94.2, clamav-milter version 0.94.2 on skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua X-Virus-Scanned: mail.terabit.net.ua 1LhPZu-000N7s-3O a65ca15d9dad767a3ca1ffc160bf96a9 X-Terabit: YES Cc: freebsd-hackers@freebsd.org Subject: Re: Non-existing p_vmspace. When is it possible? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Mar 2009 14:38:40 -0000 --jlzMyYUOO8BCbMOc Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Mar 11, 2009 at 04:38:39PM +0300, pluknet wrote: > Hi. >=20 > I perform in FOREACH_PROC_IN_SYSTEM(), where I conditionally > look at p_vmspace internals. I'd like to know the safe way to > reference p_vmspace fields without potential null-dereference. >=20 > I see an example in vm_pageout_oom(), where making access to > p->p_vmspace fields is done without additional checks. > Nevertheless I want to further catch on how it works. >=20 > Currently I additionally explicitly check on P_SYSTEM and PRS_NEW, > then p->p_vmspace against NULL. >=20 > So I'd wish to understand if a time-window between > 1) placing a new process to proclist > =9Aand > 2) attaching vmspace to this process > is possible at all, and then in what cases. >=20 > I see in fork1() that a new process' (named p2 here) state is set to > PRS_NEW just before LIST_INSERT_HEAD(&allproc, p2, p_list) and then > (after vmspace is already attached in vm_forkproc()) is set to PRS_NORMAL. >=20 > So an additional check on p_vmspace !=3D NULL is not need. > Am I right? The canonical sequence of doing this is, assuming p is a held pointer to a process: vm =3D vmspace_acquire_ref(p); if (vm =3D=3D NULL) { PRELE(p); return ?; } use vm; vmspace_free(vm); Look around the tree for the vmspace_acquire_ref usage. --jlzMyYUOO8BCbMOc Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkm3zOUACgkQC3+MBN1Mb4hfJACfWipoAwAy+EovspIQAF/z+Z+e iGQAn3VAiyQVG0d58CX1rgKdgmCQAC6f =d3Nx -----END PGP SIGNATURE----- --jlzMyYUOO8BCbMOc--