From nobody Mon Apr 13 04:39:48 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4fvF7T1FKkz6YGBV for ; Mon, 13 Apr 2026 04:39:49 +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 "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fvF7S5wlxz43KT for ; Mon, 13 Apr 2026 04:39:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776055188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xi6JL43Mh7J/OTgcNhAr8NFHNwJ2Kamy203YKwkbAIc=; b=k3TdYhXHgFDYFiCvco/yqDTNXVrXdsvvKMQOSCr3xgH2y6ScNimwrZRjA11u702zcRJvA7 vDIPjYz2/guMVVi4HtCTzILi6nAhQ6YONCpoh4yWzc6YFcidUQeF23q8UBhuUw60kdl3P2 zCRIEwWun81PrVpzEjSWd1QYa6hJNoAgmf3Xr2W6BTwlkY/5Bldp/2xmm3dB+2nKeB+k4R jk7GeCSHPO+jmyIHkKsVSdwzZBXUbPt8/DhctRGhXSc30gh4t1hR+c8dR52JluxbygoSX+ 3knlY+0GqULiNU03kuS/xKU+cbDiLuMq+If3O9/kdQc95oZSdhIkFZAqmVM/4A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776055188; a=rsa-sha256; cv=none; b=b24gCCV2VfWtKnjK2B+0UDW7DjP/en1lAWnkm0o7/X/57pSmovL4xVHTFKXUs0Z1cSJxAd KC0pza8mD7X6IeuFFWaf5c3GbRH/HvP3rkhZm7xJ4s0TqCIPmZ9cThyASFlMkfPDV79b8m b7Y59/Dx3K6dldXpi33JbFuhb7PpxfNuyuznp9tpMbIaSlDjcOwKw6+/iWyKzA1kn4kBLK wA2Zy/sqJGKoEulD0FU+6tO5h6mWXKII9KmHOT2Ag23gqf8t9cfrMe4UnQXqhzyn0SVXFN nPWTdaaHaewp7U1oP6jDg3uuwm+Y2+PDa2cBBR5CBlreIcNL9SmrIKeHua+1xA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776055188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xi6JL43Mh7J/OTgcNhAr8NFHNwJ2Kamy203YKwkbAIc=; b=cd/P8LJoX25Tu4dMx0Stja0xcxTjb+8d6rHBAC6Y2WBcm/vX4iljexHkIhTgjsa27HPBHb FRhXcQ/9JB3/9w7tqndzAryRQ2NR8jARyzea/tkxkOZwSeup/B1o9iEqFBm3JXv0SraUCE A+44iUMg4xMpXw75FROkUCD+xYokIgn6OZaQ4FFgHiqOjF96p6/7jR3xcFiA1VOYur0CVh jLTn1TbAuAD5jMmEtdqDLkV5tWe72e15Dqz0RsSHg/y43JUXa/cslE56DuZqzPanrStNdV kfowxTKnYI9+HjTbRt94yA4xhrxIVBqAhFPwmQaLKrWMx0fEsMbe2dzdfXLz7w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fvF7S5GzNzppM for ; Mon, 13 Apr 2026 04:39:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 203c3 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 13 Apr 2026 04:39:48 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Zhenlei Huang Subject: git: e9fc0c538264 - main - if_clone: Make ifnet_detach_sxlock opaque to consumers List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: zlei X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e9fc0c538264355bd3fd9120c650078281c2a290 Auto-Submitted: auto-generated Date: Mon, 13 Apr 2026 04:39:48 +0000 Message-Id: <69dc7394.203c3.3a41c692@gitrepo.freebsd.org> The branch main has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=e9fc0c538264355bd3fd9120c650078281c2a290 commit e9fc0c538264355bd3fd9120c650078281c2a290 Author: Zhenlei Huang AuthorDate: 2026-04-13 04:38:44 +0000 Commit: Zhenlei Huang CommitDate: 2026-04-13 04:38:44 +0000 if_clone: Make ifnet_detach_sxlock opaque to consumers The change e133271fc1b5e introduced ifnet_detach_sxlock, and change 6d2a10d96fb5 widened its coverage, but there are still consumers, net80211 and tuntap e.g., want it. Instead of sprinkling it everywhere, make it opaque to consumers. Out of tree drivers shall also benefit from this change. Reviewed by: kp MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D56298 --- sys/net/if.c | 5 +---- sys/net/if_clone.c | 17 ++++++++++++++++- sys/netlink/route/iface.c | 3 --- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 1d73c55aa69f..760ae94e842b 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -2904,11 +2904,8 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) case SIOCIFDESTROY: error = priv_check(td, PRIV_NET_IFDESTROY); - if (error == 0) { - sx_xlock(&ifnet_detach_sxlock); + if (error == 0) error = if_clone_destroy(ifr->ifr_name); - sx_xunlock(&ifnet_detach_sxlock); - } goto out_noref; case SIOCIFGCLONERS: diff --git a/sys/net/if_clone.c b/sys/net/if_clone.c index 4bc04130da1e..db3db78c1b76 100644 --- a/sys/net/if_clone.c +++ b/sys/net/if_clone.c @@ -441,6 +441,14 @@ if_clone_destroyif_flags(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags { int err; + /* + * XXXZL: To avoid racing with if_vmove() so that we will have + * stable if_vnet. + * This have a good effect, that is, the destroying of tightly + * coupled cloned interfaces such as epair(4) is serialized, + * although the driver is responsible to take care of that. + */ + sx_assert(&ifnet_detach_sxlock, SA_XLOCKED); /* * Given that the cloned ifnet might be attached to a different * vnet from where its cloner was registered, we have to @@ -467,7 +475,12 @@ if_clone_destroyif_flags(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags int if_clone_destroyif(struct if_clone *ifc, struct ifnet *ifp) { - return (if_clone_destroyif_flags(ifc, ifp, 0)); + int err; + + sx_xlock(&ifnet_detach_sxlock); + err = if_clone_destroyif_flags(ifc, ifp, 0); + sx_xunlock(&ifnet_detach_sxlock); + return (err); } static struct if_clone * @@ -670,9 +683,11 @@ if_clone_detach(struct if_clone *ifc) V_if_cloners_count--; IF_CLONERS_UNLOCK(); + sx_xlock(&ifnet_detach_sxlock); /* destroy all interfaces for this cloner */ while (!LIST_EMPTY(&ifc->ifc_iflist)) if_clone_destroyif_flags(ifc, LIST_FIRST(&ifc->ifc_iflist), IFC_F_FORCE); + sx_xunlock(&ifnet_detach_sxlock); IF_CLONE_REMREF(ifc); } diff --git a/sys/netlink/route/iface.c b/sys/netlink/route/iface.c index 3e30d74a3793..d449e4114f24 100644 --- a/sys/netlink/route/iface.c +++ b/sys/netlink/route/iface.c @@ -556,10 +556,7 @@ rtnl_handle_dellink(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *n } NLP_LOG(LOG_DEBUG3, nlp, "mapped ifindex %u to %s", attrs.ifi_index, if_name(ifp)); - sx_xlock(&ifnet_detach_sxlock); error = if_clone_destroy(if_name(ifp)); - sx_xunlock(&ifnet_detach_sxlock); - NLP_LOG(LOG_DEBUG2, nlp, "deleting interface %s returned %d", if_name(ifp), error); if_rele(ifp);