From owner-svn-src-all@FreeBSD.ORG Thu Sep 27 13:37:31 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A5F66106564A; Thu, 27 Sep 2012 13:37:31 +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 8F3408FC0C; Thu, 27 Sep 2012 13:37:31 +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 q8RDbVkr026642; Thu, 27 Sep 2012 13:37:31 GMT (envelope-from emaste@svn.freebsd.org) Received: (from emaste@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q8RDbVoC026640; Thu, 27 Sep 2012 13:37:31 GMT (envelope-from emaste@svn.freebsd.org) Message-Id: <201209271337.q8RDbVoC026640@svn.freebsd.org> From: Ed Maste Date: Thu, 27 Sep 2012 13:37:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r240995 - stable/9/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, 27 Sep 2012 13:37:31 -0000 Author: emaste Date: Thu Sep 27 13:37:30 2012 New Revision: 240995 URL: http://svn.freebsd.org/changeset/base/240995 Log: MFC part of r238812 and remainder of r239149 From r238812, move mtx_init of per-ring locks into NIOCREGIF ioctl handler. (Otherwise they're overwritten with zeros in netmap_if_new.) From r239149: 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. Modified: stable/9/sys/dev/netmap/netmap.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/dev/netmap/netmap.c ============================================================================== --- stable/9/sys/dev/netmap/netmap.c Thu Sep 27 10:56:25 2012 (r240994) +++ stable/9/sys/dev/netmap/netmap.c Thu Sep 27 13:37:30 2012 (r240995) @@ -186,13 +186,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); @@ -593,6 +600,10 @@ netmap_ioctl(__unused struct cdev *dev, /* Otherwise set the card in netmap mode * and make it use the shared buffers. */ + for (i = 0 ; i < na->num_tx_rings + 1; i++) + mtx_init(&na->tx_rings[i].q_lock, "nm_txq_lock", NULL, MTX_DEF); + for (i = 0 ; i < na->num_rx_rings + 1; i++) + mtx_init(&na->rx_rings[i].q_lock, "nm_rxq_lock", NULL, MTX_DEF); error = na->nm_register(ifp, 1); /* mode on */ if (error) netmap_dtor_locked(priv); @@ -970,7 +981,7 @@ netmap_lock_wrapper(struct ifnet *dev, i int netmap_attach(struct netmap_adapter *na, int num_queues) { - int i, n, size; + int n, size; void *buf; struct ifnet *ifp = na->ifp; @@ -999,13 +1010,14 @@ netmap_attach(struct netmap_adapter *na, ifp->if_capabilities |= IFCAP_NETMAP; na = buf; - if (na->nm_lock == NULL) - na->nm_lock = netmap_lock_wrapper; + /* Core lock initialized here. Others are initialized after + * netmap_if_new. + */ mtx_init(&na->core_lock, "netmap core lock", NULL, MTX_DEF); - for (i = 0 ; i < na->num_tx_rings + 1; i++) - mtx_init(&na->tx_rings[i].q_lock, "netmap txq lock", NULL, MTX_DEF); - for (i = 0 ; i < na->num_rx_rings + 1; i++) - mtx_init(&na->rx_rings[i].q_lock, "netmap rxq lock", NULL, MTX_DEF); + if (na->nm_lock == NULL) { + ND("using default locks for %s", ifp->if_xname); + na->nm_lock = netmap_lock_wrapper; + } } #ifdef linux D("netdev_ops %p", ifp->netdev_ops); @@ -1026,24 +1038,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); - } mtx_destroy(&na->core_lock); - /* XXX kqueue(9) needed; these will mirror knlist_init. */ - /* knlist_destroy(&na->tx_si.si_note); */ - /* knlist_destroy(&na->rx_si.si_note); */ + bzero(na, sizeof(*na)); WNA(ifp) = NULL; free(na, M_DEVBUF);