From owner-svn-src-all@FreeBSD.ORG Thu Aug 9 14:46:53 2012 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 07ADE106564A; Thu, 9 Aug 2012 14:46:53 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CD78E8FC19; Thu, 9 Aug 2012 14:46:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q79EkqE7020525; Thu, 9 Aug 2012 14:46:52 GMT (envelope-from emaste@svn.freebsd.org) Received: (from emaste@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q79EkqtH020523; Thu, 9 Aug 2012 14:46:52 GMT (envelope-from emaste@svn.freebsd.org) Message-Id: <201208091446.q79EkqtH020523@svn.freebsd.org> From: Ed Maste Date: Thu, 9 Aug 2012 14:46:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r239149 - head/sys/dev/netmap 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: Thu, 09 Aug 2012 14:46:53 -0000 Author: emaste Date: Thu Aug 9 14:46:52 2012 New Revision: 239149 URL: http://svn.freebsd.org/changeset/base/239149 Log: Improve lock and unlock symmetry - Move destruction of per-ring locks to netmap_dtor_locked to mirror the initialization that happens in NIOCREGIF. Otherwise unloading a netmap- capable interface that was never put into netmap mode would try to mtx_destroy an uninitialized mutex, and panic. - Destroy core_lock in netmap_detach, mirroring init in netmap_attach. - Also comment out the knlist_destroy for now as there is currently no knlist_init. Sponsored by: ADARA Networks Reviewed by: luigi@ Modified: head/sys/dev/netmap/netmap.c Modified: head/sys/dev/netmap/netmap.c ============================================================================== --- head/sys/dev/netmap/netmap.c Wed Aug 8 20:21:33 2012 (r239148) +++ head/sys/dev/netmap/netmap.c Thu Aug 9 14:46:52 2012 (r239149) @@ -356,13 +356,20 @@ netmap_dtor_locked(void *data) lim = na->tx_rings[i].nkr_num_slots; for (j = 0; j < lim; j++) netmap_free_buf(nifp, ring->slot[j].buf_idx); + /* knlist_destroy(&na->tx_rings[i].si.si_note); */ + mtx_destroy(&na->tx_rings[i].q_lock); } for (i = 0; i < na->num_rx_rings + 1; i++) { struct netmap_ring *ring = na->rx_rings[i].ring; lim = na->rx_rings[i].nkr_num_slots; for (j = 0; j < lim; j++) netmap_free_buf(nifp, ring->slot[j].buf_idx); + /* knlist_destroy(&na->rx_rings[i].si.si_note); */ + mtx_destroy(&na->rx_rings[i].q_lock); } + /* XXX kqueue(9) needed; these will mirror knlist_init. */ + /* knlist_destroy(&na->tx_si.si_note); */ + /* knlist_destroy(&na->rx_si.si_note); */ NMA_UNLOCK(); netmap_free_rings(na); wakeup(na); @@ -1318,13 +1325,14 @@ netmap_attach(struct netmap_adapter *na, ifp->if_capabilities |= IFCAP_NETMAP; na = buf; + /* Core lock initialized here. Others are initialized after + * netmap_if_new. + */ + mtx_init(&na->core_lock, "netmap core lock", MTX_NETWORK_LOCK, + MTX_DEF); if (na->nm_lock == NULL) { ND("using default locks for %s", ifp->if_xname); na->nm_lock = netmap_lock_wrapper; - /* core lock initialized here. - * others initialized after netmap_if_new - */ - mtx_init(&na->core_lock, "netmap core lock", MTX_NETWORK_LOCK, MTX_DEF); } } #ifdef linux @@ -1348,22 +1356,13 @@ netmap_attach(struct netmap_adapter *na, void netmap_detach(struct ifnet *ifp) { - u_int i; struct netmap_adapter *na = NA(ifp); if (!na) return; - for (i = 0; i < na->num_tx_rings + 1; i++) { - knlist_destroy(&na->tx_rings[i].si.si_note); - mtx_destroy(&na->tx_rings[i].q_lock); - } - for (i = 0; i < na->num_rx_rings + 1; i++) { - knlist_destroy(&na->rx_rings[i].si.si_note); - mtx_destroy(&na->rx_rings[i].q_lock); - } - knlist_destroy(&na->tx_si.si_note); - knlist_destroy(&na->rx_si.si_note); + mtx_destroy(&na->core_lock); + bzero(na, sizeof(*na)); WNA(ifp) = NULL; free(na, M_DEVBUF);