Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Oct 2018 13:25:26 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r339588 - head/sys/net
Message-ID:  <201810221325.w9MDPQs5077120@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Mon Oct 22 13:25:26 2018
New Revision: 339588
URL: https://svnweb.freebsd.org/changeset/base/339588

Log:
  Resolve deadlock between epoch(9) and various network interface
  SX-locks, during if_purgeaddrs(), by not allowing to hold the epoch
  read lock over typical network IOCTL code paths. This is a regression
  issue after r334305.
  
  Reviewed by:		ae (network)
  Differential revision:	https://reviews.freebsd.org/D17647
  MFC after:		1 week
  Sponsored by:		Mellanox Technologies

Modified:
  head/sys/net/if.c

Modified: head/sys/net/if.c
==============================================================================
--- head/sys/net/if.c	Mon Oct 22 11:58:30 2018	(r339587)
+++ head/sys/net/if.c	Mon Oct 22 13:25:26 2018	(r339588)
@@ -964,12 +964,18 @@ if_attachdomain1(struct ifnet *ifp)
 void
 if_purgeaddrs(struct ifnet *ifp)
 {
-	struct ifaddr *ifa, *next;
+	struct ifaddr *ifa;
 
-	NET_EPOCH_ENTER();
-	CK_STAILQ_FOREACH_SAFE(ifa, &ifp->if_addrhead, ifa_link, next) {
-		if (ifa->ifa_addr->sa_family == AF_LINK)
-			continue;
+	while (1) {
+		NET_EPOCH_ENTER();
+		CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
+			if (ifa->ifa_addr->sa_family != AF_LINK)
+				break;
+		}
+		NET_EPOCH_EXIT();
+
+		if (ifa == NULL)
+			break;
 #ifdef INET
 		/* XXX: Ugly!! ad hoc just for INET */
 		if (ifa->ifa_addr->sa_family == AF_INET) {
@@ -996,7 +1002,6 @@ if_purgeaddrs(struct ifnet *ifp)
 		IF_ADDR_WUNLOCK(ifp);
 		ifa_free(ifa);
 	}
-	NET_EPOCH_EXIT();
 }
 
 /*



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