From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 5 10:06:53 2010 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 31AAB106566B for ; Fri, 5 Feb 2010 10:06:53 +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 7945C8FC13 for ; Fri, 5 Feb 2010 10:06:51 +0000 (UTC) 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 o15A6iJx002934 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 5 Feb 2010 12:06:44 +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 o15A6il5003635; Fri, 5 Feb 2010 12:06:44 +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 o15A6hAR003634; Fri, 5 Feb 2010 12:06:43 +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, 5 Feb 2010 12:06:43 +0200 From: Kostik Belousov To: Andrew Gallatin Message-ID: <20100205100643.GQ15587@deviant.kiev.zoral.com.ua> References: <4B6B30BC.7030107@cs.duke.edu> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="U+NfgObvpQT1Q9Yq" Content-Disposition: inline In-Reply-To: <4B6B30BC.7030107@cs.duke.edu> 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=-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 Cc: freebsd-hackers@freebsd.org Subject: Re: devfs panic w/INVARIANTS 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: Fri, 05 Feb 2010 10:06:53 -0000 --U+NfgObvpQT1Q9Yq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Feb 04, 2010 at 03:40:28PM -0500, Andrew Gallatin wrote: > I've got a commercial driver that uses device cloning. > At unload time, the driver calls clone_cleanup(). When I unload > the driver when the kernel is built with INVARIANTS, I'll see a > panic in devfs_populate_loop(). This happens in 6-stable, > as well as 8-stable. >=20 > From what I can see the clone has been freed, but it > remains on the devfs cdevp_list. Then the next time > devfs_populate_loop() is called, it trips over the bad > entry (cdp->cdp_dirents points to 0xdeadc0dedeadc0de) > See appended kgdb session. >=20 > If I trace the code path, it looks like clone_cleanup() > calls destroy_devl(). And destroy_devl() will eventually > call devfs_free() if the si_refcnt is zero. But I don't > see anything which will get the cdev removed from > the cdevp_list prior to it being freed. >=20 > The only code I see which will get the cdev removed from > the cdevp_list() seems to be the "GC any lingering devices" > block in devfs_populate_loop >=20 > What am I missing? You did not mentioned it, but my guess is that you create clones from the dev_clone event handler. Please note that devfs_lookup() that fires dev_clone event, consumes a device reference. Thus clone handlers shall do dev_ref(). Due to races with cleanup, you should use MAKEDEV_REF flag for make_dev_credv(9) KPI instead of doing make_dev()/dev_ref() pair. That said, do you really need clones at all ? --U+NfgObvpQT1Q9Yq Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iEYEARECAAYFAktr7bMACgkQC3+MBN1Mb4jGpgCg3IgMWZSS8Y5S5VoYdizbL5Zg 6xIAoLj2BoZxbjtThCVR+lG1uWtttqkk =i4F5 -----END PGP SIGNATURE----- --U+NfgObvpQT1Q9Yq--