Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Sep 2012 13:37:31 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r240995 - stable/9/sys/dev/netmap
Message-ID:  <201209271337.q8RDbVoC026640@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201209271337.q8RDbVoC026640>