Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Feb 2021 16:50:26 GMT
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 23f8fe51af0b - releng/13.0 - Widen ifnet_detach_sxlock coverage
Message-ID:  <202102171650.11HGoQ8I061021@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch releng/13.0 has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=23f8fe51af0b192857feef2d19be2aa8eb888000

commit 23f8fe51af0b192857feef2d19be2aa8eb888000
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2021-02-08 09:04:27 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2021-02-17 16:49:28 +0000

    Widen ifnet_detach_sxlock coverage
    
    Widen the ifnet_detach_sxlock to cover the entire vnet sysuninit code.
    This ensures that we can't end up having the vnet_sysuninit free the UDP
    pcb while the detach code is running and trying to purge the UDP pcb.
    
    Approved by:    re (gjb)
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D28530
    
    (cherry picked from commit 6d2a10d96fb5d4ee42fd67b0b07a6d098db5d55a)
    (cherry picked from commit 05530211165f59b8dabc02adaf26ea29c2726ebc)
---
 sys/net/if.c   | 13 ++++++-------
 sys/net/if.h   |  3 +++
 sys/net/vnet.c |  2 ++
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/sys/net/if.c b/sys/net/if.c
index 74fdd066fd2d..c85cfab19bf6 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -315,7 +315,8 @@ struct sx ifnet_sxlock;
 SX_SYSINIT_FLAGS(ifnet_sx, &ifnet_sxlock, "ifnet_sx", SX_RECURSE);
 
 struct sx ifnet_detach_sxlock;
-SX_SYSINIT(ifnet_detach, &ifnet_detach_sxlock, "ifnet_detach_sx");
+SX_SYSINIT_FLAGS(ifnet_detach, &ifnet_detach_sxlock, "ifnet_detach_sx",
+    SX_RECURSE);
 
 /*
  * The allocation of network interfaces is a rather non-atomic affair; we
@@ -546,9 +547,7 @@ vnet_if_return(const void *unused __unused)
 	IFNET_WUNLOCK();
 
 	for (int j = 0; j < i; j++) {
-		sx_xlock(&ifnet_detach_sxlock);
 		if_vmove(pending[j], pending[j]->if_home_vnet);
-		sx_xunlock(&ifnet_detach_sxlock);
 	}
 
 	free(pending, M_IFNET);
@@ -1124,9 +1123,9 @@ if_detach(struct ifnet *ifp)
 	CURVNET_SET_QUIET(ifp->if_vnet);
 	found = if_unlink_ifnet(ifp, false);
 	if (found) {
-		sx_slock(&ifnet_detach_sxlock);
+		sx_xlock(&ifnet_detach_sxlock);
 		if_detach_internal(ifp, 0, NULL);
-		sx_sunlock(&ifnet_detach_sxlock);
+		sx_xunlock(&ifnet_detach_sxlock);
 	}
 	CURVNET_RESTORE();
 }
@@ -3015,9 +3014,9 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td)
 		error = priv_check(td, PRIV_NET_IFDESTROY);
 
 		if (error == 0) {
-			sx_slock(&ifnet_detach_sxlock);
+			sx_xlock(&ifnet_detach_sxlock);
 			error = if_clone_destroy(ifr->ifr_name);
-			sx_sunlock(&ifnet_detach_sxlock);
+			sx_xunlock(&ifnet_detach_sxlock);
 		}
 		goto out_noref;
 
diff --git a/sys/net/if.h b/sys/net/if.h
index a886474780dd..83597a7d390a 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -604,6 +604,9 @@ struct ifdownreason {
 MALLOC_DECLARE(M_IFADDR);
 MALLOC_DECLARE(M_IFMADDR);
 #endif
+
+extern struct sx ifnet_detach_sxlock;
+
 #endif
 
 #ifndef _KERNEL
diff --git a/sys/net/vnet.c b/sys/net/vnet.c
index c5dafedbc6b2..2480fc8dd86c 100644
--- a/sys/net/vnet.c
+++ b/sys/net/vnet.c
@@ -283,7 +283,9 @@ vnet_destroy(struct vnet *vnet)
 	vnet->vnet_shutdown = true;
 
 	CURVNET_SET_QUIET(vnet);
+	sx_xlock(&ifnet_detach_sxlock);
 	vnet_sysuninit();
+	sx_xunlock(&ifnet_detach_sxlock);
 	CURVNET_RESTORE();
 
 	/*



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