From owner-dev-commits-src-branches@freebsd.org Wed Feb 17 14:30:14 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 095B75432C7; Wed, 17 Feb 2021 14:30:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DggGs6rJ2z3MsS; Wed, 17 Feb 2021 14:30:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D32F22613A; Wed, 17 Feb 2021 14:30:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 11HEUDHO073507; Wed, 17 Feb 2021 14:30:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 11HEUDEl073495; Wed, 17 Feb 2021 14:30:13 GMT (envelope-from git) Date: Wed, 17 Feb 2021 14:30:13 GMT Message-Id: <202102171430.11HEUDEl073495@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 9cc7bd9a6ab1 - stable/12 - Widen ifnet_detach_sxlock coverage MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 9cc7bd9a6ab1e2bfc12dabf4d9ef4ad463a05616 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Feb 2021 14:30:14 -0000 The branch stable/12 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=9cc7bd9a6ab1e2bfc12dabf4d9ef4ad463a05616 commit 9cc7bd9a6ab1e2bfc12dabf4d9ef4ad463a05616 Author: Kristof Provost AuthorDate: 2021-02-08 09:04:27 +0000 Commit: Kristof Provost CommitDate: 2021-02-17 13:13:04 +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. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D28530 (cherry picked from commit 6d2a10d96fb5d4ee42fd67b0b07a6d098db5d55a) --- 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 56b12f594814..2ae8121043b0 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -316,7 +316,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 @@ -552,9 +553,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); @@ -1108,9 +1107,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(); } @@ -3147,9 +3146,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 3767033d8265..44a920d844e2 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -600,6 +600,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 9a4321a8409b..3fd423d22d1d 100644 --- a/sys/net/vnet.c +++ b/sys/net/vnet.c @@ -281,7 +281,9 @@ vnet_destroy(struct vnet *vnet) VNET_LIST_WUNLOCK(); CURVNET_SET_QUIET(vnet); + sx_xlock(&ifnet_detach_sxlock); vnet_sysuninit(); + sx_xunlock(&ifnet_detach_sxlock); CURVNET_RESTORE(); /*