From owner-freebsd-current@FreeBSD.ORG Fri Jan 27 09:38:52 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5060A1065672 for ; Fri, 27 Jan 2012 09:38:52 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id B63528FC13 for ; Fri, 27 Jan 2012 09:38:51 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q0R9anSL095315 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 27 Jan 2012 11:36:49 +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.5/8.14.5) with ESMTP id q0R8uvFt041229; Fri, 27 Jan 2012 10:56:57 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q0R8uurH041228; Fri, 27 Jan 2012 10:56:56 +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: Fri, 27 Jan 2012 10:56:56 +0200 From: Kostik Belousov To: Doug Ambrisko Message-ID: <20120127085656.GY2726@deviant.kiev.zoral.com.ua> References: <201201262103.q0QL3QWr083496@ambrisko.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ed2sj0fx90rgoibw" Content-Disposition: inline In-Reply-To: <201201262103.q0QL3QWr083496@ambrisko.com> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-3.9 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 Cc: freebsd-current@freebsd.org Subject: Re: knlist_empty locking fix X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jan 2012 09:38:52 -0000 --ed2sj0fx90rgoibw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jan 26, 2012 at 01:03:26PM -0800, Doug Ambrisko wrote: > Ran into problems with running kqueue/aio with WITNESS etc. Sometimes > things are locked sometimes not. knlist_remove is called telling it > whether it is locked or not ie: > extern void knlist_remove(struct knlist *knl, struct knote *kn, int = islocked); > so I changed: > extern int knlist_empty(struct knlist *knl); > to: > extern int knlist_empty(struct knlist *knl, int islocked); >=20 > and then updated things to reflect that following what that state of the > lock for knlist_remove. If it is not locked, it gets a lock and=20 > frees it after. >=20 > This now fixes a panic when a process using kqueue/aio is killed on > shutdown with WITNESS. >=20 > It changes an API/ABI so it probably can't merged back. If there are > no objections then I'll commit it. >=20 Change to knlist_init() does not make sense at all, the knlist shall not be exposed to other consumers during initialization, so no need to exclude the parallel access. Regarding the knlist_empty(), I propose to keep it as is. Locking the knlist inside knlist_empty() does not make sense, because lock is immediately dropped afterward, and relocked for remove. This way, the entry could be removed from the list meantime (can it, really ?). I think that you should take a lock around the whole if() {} statement, and call knlist_remove with locked =3D=3D 1. --ed2sj0fx90rgoibw Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iEYEARECAAYFAk8iZtgACgkQC3+MBN1Mb4i2CgCfWHZPTo8+ZH45enS5lsoeFrMw 1GAAn1J1OhCzi0Q7vNZwgEA9YCTz29TE =tzJl -----END PGP SIGNATURE----- --ed2sj0fx90rgoibw--