From owner-svn-src-all@FreeBSD.ORG Sun Mar 22 13:11:58 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1A9D7894; Sun, 22 Mar 2015 13:11:58 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DEC6CE98; Sun, 22 Mar 2015 13:11:57 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t2MDBvrA089289; Sun, 22 Mar 2015 13:11:57 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t2MDBvpA089288; Sun, 22 Mar 2015 13:11:57 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201503221311.t2MDBvpA089288@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Sun, 22 Mar 2015 13:11:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r280345 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 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, 22 Mar 2015 13:11:58 -0000 Author: hselasky Date: Sun Mar 22 13:11:56 2015 New Revision: 280345 URL: https://svnweb.freebsd.org/changeset/base/280345 Log: Fix for out of order device destruction notifications when using the delist_dev() function. In addition to this change: - add a proper description of this function - add a proper witness assert inside this function - switch a nearby line to use the "cdp" pointer instead of cdev2priv() MFC after: 3 days Modified: head/sys/kern/kern_conf.c Modified: head/sys/kern/kern_conf.c ============================================================================== --- head/sys/kern/kern_conf.c Sun Mar 22 12:49:57 2015 (r280344) +++ head/sys/kern/kern_conf.c Sun Mar 22 13:11:56 2015 (r280345) @@ -1093,9 +1093,12 @@ destroy_devl(struct cdev *dev) } dev_unlock(); - notify_destroy(dev); + if ((cdp->cdp_flags & CDP_UNREF_DTR) == 0) { + /* avoid out of order notify events */ + notify_destroy(dev); + } mtx_lock(&cdevpriv_mtx); - while ((p = LIST_FIRST(&cdev2priv(dev)->cdp_fdpriv)) != NULL) { + while ((p = LIST_FIRST(&cdp->cdp_fdpriv)) != NULL) { devfs_destroy_cdevpriv(p); mtx_lock(&cdevpriv_mtx); } @@ -1141,12 +1144,25 @@ delist_dev_locked(struct cdev *dev) devfs_destroy(dev); LIST_FOREACH(child, &dev->si_children, si_siblings) delist_dev_locked(child); + dev_unlock(); + /* ensure the destroy event is queued in order */ + notify_destroy(dev); + dev_lock(); } +/* + * This function will delist a character device and its children from + * the directory listing and create a destroy event without waiting + * for all character device references to go away. At some later point + * destroy_dev() must be called to complete the character device + * destruction. After calling this function the character device name + * can instantly be re-used. + */ void delist_dev(struct cdev *dev) { + WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "delist_dev"); dev_lock(); delist_dev_locked(dev); dev_unlock();