From owner-svn-src-all@FreeBSD.ORG Sun Dec 21 22:10:20 2008 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 39B1C1065670; Sun, 21 Dec 2008 22:10:20 +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 D0AC68FC08; Sun, 21 Dec 2008 22:10:19 +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 1LEWV8-0002nb-KG; Mon, 22 Dec 2008 00:10:18 +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 mBLMAFVi039187 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 22 Dec 2008 00:10:15 +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 mBLMAFUL022820; Mon, 22 Dec 2008 00:10:15 +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 mBLMAErl022819; Mon, 22 Dec 2008 00:10:14 +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: Mon, 22 Dec 2008 00:10:14 +0200 From: Kostik Belousov To: Ed Schouten Message-ID: <20081221221014.GJ2038@deviant.kiev.zoral.com.ua> References: <200812212116.mBLLGvPj042566@svn.freebsd.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="B3dAGXc5YVwcSxdz" Content-Disposition: inline In-Reply-To: <200812212116.mBLLGvPj042566@svn.freebsd.org> 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 1LEWV8-0002nb-KG 45bc878977a629a23c85d8fa14d131ae X-Terabit: YES Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r186382 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Dec 2008 22:10:20 -0000 --B3dAGXc5YVwcSxdz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Dec 21, 2008 at 09:16:57PM +0000, Ed Schouten wrote: > Author: ed > Date: Sun Dec 21 21:16:57 2008 > New Revision: 186382 > URL: http://svn.freebsd.org/changeset/base/186382 >=20 > Log: > Set PTS_FINISHED before waking up any threads. > =20 > Inside ptsdrv_{in,out}wakeup() we call KNOTE_LOCKED() to wake up any > kevent(2) users. Because the kqueue handlers are executed synchronously, > we must set PTS_FINISHED before calling ptsdrv_{in,out}wakeup(). > =20 > Discovered by: nork >=20 > Modified: > head/sys/kern/tty_pts.c >=20 > Modified: head/sys/kern/tty_pts.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- head/sys/kern/tty_pts.c Sun Dec 21 20:30:14 2008 (r186381) > +++ head/sys/kern/tty_pts.c Sun Dec 21 21:16:57 2008 (r186382) > @@ -630,10 +630,9 @@ ptsdrv_close(struct tty *tp) > struct pts_softc *psc =3D tty_softc(tp); > =20 > /* Wake up any blocked readers/writers. */ > + psc->pts_flags |=3D PTS_FINISHED; > ptsdrv_outwakeup(tp); > ptsdrv_inwakeup(tp); > - > - psc->pts_flags |=3D PTS_FINISHED; > } > =20 > static void I was always curious whether our cv code guarantees that there is no a spurious wakeup. If the spurious wakeup can happen, then setting PTS_FINISHED before calling cv_broadcast() still does not solve the possible race. Assume that waiting thread is woken up, and ptsdrv_close() still did not set PTS_FINISHED. The ptsdev_read() locked the mutex, rechecked the condition (that is false still), and preempted for the ptsdrv_close() thread. This thread sets flag and issues broadcast. Then, the ptsdrv_read() thread is put to sleep, having lost a wakeup. I think that mutex shall be acquired around setting flag and wakeups. scheduled, it=20 --B3dAGXc5YVwcSxdz Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAklOvsYACgkQC3+MBN1Mb4hbWACeJQqGDApaXHqwG0sJadHZQxpa XHMAn1cDnBcINM391qHSoNY+oMr3kwio =OvVb -----END PGP SIGNATURE----- --B3dAGXc5YVwcSxdz--