Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Oct 2018 13:17:41 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r339859 - stable/12/sys/net
Message-ID:  <201810291317.w9TDHf7F000637@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Mon Oct 29 13:17:41 2018
New Revision: 339859
URL: https://svnweb.freebsd.org/changeset/base/339859

Log:
  MFC r339588:
  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)
  Approved by:		re (kib)
  Differential revision:	https://reviews.freebsd.org/D17647
  Sponsored by:		Mellanox Technologies

Modified:
  stable/12/sys/net/if.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/net/if.c
==============================================================================
--- stable/12/sys/net/if.c	Mon Oct 29 12:48:30 2018	(r339858)
+++ stable/12/sys/net/if.c	Mon Oct 29 13:17:41 2018	(r339859)
@@ -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?201810291317.w9TDHf7F000637>