Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Apr 2010 11:51:45 +0000 (UTC)
From:      "Bjoern A. Zeeb" <bz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r206470 - head/sys/net
Message-ID:  <201004111151.o3BBpjlJ088724@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bz
Date: Sun Apr 11 11:51:44 2010
New Revision: 206470
URL: http://svn.freebsd.org/changeset/base/206470

Log:
  In if_detach_internal() we cannot hold the af_data lock over the
  dom_ifdetach() calls as they might sleep for callout_drain().
  Do as we do in if_attachdomain1() [r121470] and handle
  if_afdata_initialized earlier and call dom_ifdetach() unlocked.
  
  Discussed with:	rwatson
  MFC after:	10 days

Modified:
  head/sys/net/if.c

Modified: head/sys/net/if.c
==============================================================================
--- head/sys/net/if.c	Sun Apr 11 11:49:24 2010	(r206469)
+++ head/sys/net/if.c	Sun Apr 11 11:51:44 2010	(r206470)
@@ -897,14 +897,20 @@ if_detach_internal(struct ifnet *ifp, in
 		devctl_notify("IFNET", ifp->if_xname, "DETACH", NULL);
 	if_delgroups(ifp);
 
+	/*
+	 * We cannot hold the lock over dom_ifdetach calls as they might
+	 * sleep, for example trying to drain a callout, thus open up the
+	 * theoretical race with re-attaching.
+	 */
 	IF_AFDATA_LOCK(ifp);
-	for (dp = domains; ifp->if_afdata_initialized > 0 && dp; dp = dp->dom_next) {
+	i = ifp->if_afdata_initialized;
+	ifp->if_afdata_initialized = 0;
+	IF_AFDATA_UNLOCK(ifp);
+	for (dp = domains; i > 0 && dp; dp = dp->dom_next) {
 		if (dp->dom_ifdetach && ifp->if_afdata[dp->dom_family])
 			(*dp->dom_ifdetach)(ifp,
 			    ifp->if_afdata[dp->dom_family]);
 	}
-	ifp->if_afdata_initialized = 0;
-	IF_AFDATA_UNLOCK(ifp);
 }
 
 #ifdef VIMAGE



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