From nobody Tue Jan 25 05:09:40 2022 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 E5D2E1980DA9; Tue, 25 Jan 2022 05:09:40 +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 4JjZfD5qj7z3Nnv; Tue, 25 Jan 2022 05:09:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643087380; 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=xiaeM+/0Br+FyGrUU4Y2tnWAzqBVTHSvYkno6SHvVvU=; b=eUdmkhgj6+ShNcBS5OpJ/Ec7c+O2nuNL84vY5h0Hv7IjEptJCibEguKa7Z1spd410MjgEL R5KngWo6rjl9gUPsTX0JT00ur1ZzlgjxMOdCiNvC+u/5E6V80NozIJmCTO2xIXgMtHPUoq MH1HGleuBKatYhiyzVVhNdHxnZE7mbaIIZrrEsa9elYu5E6iCHzncWnG4bM+d78BfLg+oa VoSlqVaTdps5S8YLLInD34S27ItzWnFoWdIoGwiqyxnSsHYSVJqb/uxXlXkpu/QatODqja 0WoAHrl+JNIyC2ptQCzGpBuO7Sh0K0KvUIjH9XcrSMt5TwuYtGFQWbq6LTPIng== 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 A3CF1236F0; Tue, 25 Jan 2022 05:09:40 +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 20P59eUj024339; Tue, 25 Jan 2022 05:09:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20P59ecs024338; Tue, 25 Jan 2022 05:09:40 GMT (envelope-from git) Date: Tue, 25 Jan 2022 05:09:40 GMT Message-Id: <202201250509.20P59ecs024338@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 54712fc42350 - main - if_vmove: improve restoration in cloner's ifgroup membership 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 54712fc42350acb4991d8bd8604b08562660e962 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643087380; 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=xiaeM+/0Br+FyGrUU4Y2tnWAzqBVTHSvYkno6SHvVvU=; b=QfcyzrHb9TciqP1HFYt6E76oq5WruMj2mrQ2fsG1sm7xZd8wtIuLeyUttK6YRjazSRG14g iCjlOKRG9JTa7M1YoVlGDEUbhvZB9ZRpCOxev+4EoTkK3i3EpeEf3o35w1Re4l/Z/R0Qe8 WE8o2W50lil6xl4jkgBi4mhtudxkUJhQd4VCDodQZtC4jUPzlhP4VOMgGwpro4gL4ZKqie 9VZk6MbHytANuU5MhwHBvdmlI9TF3zcly8MiYsE7eXR7qvL0ll6/r7KqbmU34FQYfIq7uA cZ+5YfdihUsQi30BBJhvhlqFr2iMh9jvakpw35pKmd8duRaLzWGeMbit94ADaQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643087380; a=rsa-sha256; cv=none; b=tk5RGGMfpah8wm6GCgsuz5PPLutdEomW73hmWROrcEa6dv1aavOZn5+k99uNbbH2TjkdsV dzgIW0llUz/f31rIX4/sUrCIW6doIpTCe2RYZCGZhTJzS+VF+MmjfdCzpCxl1mMxnYrvE+ qHM0v4qTUNj435StdpJMTF94P+VGOSthn2ZHhxJZ9X3HpFl1gs8bENsvONX7JGOkL62OmJ ai/09Mi82l9oBS5tjwipCIXw2d1eTg0aE3YB7aGb4v+RJC52ip5LFMbI0t4Dm81w3LoK7L 2sMYaL0jb8FUmQX5226AtwMI3WVUgiewRYfUeEfaLTKCayTO35E3Vf0zwYauTg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=54712fc42350acb4991d8bd8604b08562660e962 commit 54712fc42350acb4991d8bd8604b08562660e962 Author: Gleb Smirnoff AuthorDate: 2022-01-25 05:06:59 +0000 Commit: Gleb Smirnoff CommitDate: 2022-01-25 05:06:59 +0000 if_vmove: improve restoration in cloner's ifgroup membership * Do a single call into if_clone.c instead of two. The cloner can't disappear since the interface sits on its list. * Make restoration smarter - check that cloner with same name exists in the new vnet. Differential revision: https://reviews.freebsd.org/D33941 --- sys/net/if.c | 34 +++++++++++++--------------------- sys/net/if_clone.c | 47 +++++++++++++++++++++++------------------------ sys/net/if_clone.h | 3 +-- 3 files changed, 37 insertions(+), 47 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 8700485ff6a5..4622f978acd9 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -285,8 +285,8 @@ static void do_link_state_change(void *, int); static int if_getgroup(struct ifgroupreq *, struct ifnet *); static int if_getgroupmembers(struct ifgroupreq *); static void if_delgroups(struct ifnet *); -static void if_attach_internal(struct ifnet *, int, struct if_clone *); -static int if_detach_internal(struct ifnet *, int, struct if_clone **); +static void if_attach_internal(struct ifnet *, bool); +static int if_detach_internal(struct ifnet *, bool); static void if_siocaddmulti(void *, int); static void if_link_ifnet(struct ifnet *); static bool if_unlink_ifnet(struct ifnet *, bool); @@ -775,7 +775,7 @@ void if_attach(struct ifnet *ifp) { - if_attach_internal(ifp, 0, NULL); + if_attach_internal(ifp, false); } /* @@ -830,7 +830,7 @@ if_hw_tsomax_update(if_t ifp, struct ifnet_hw_tsomax *pmax) } static void -if_attach_internal(struct ifnet *ifp, int vmove, struct if_clone *ifc) +if_attach_internal(struct ifnet *ifp, bool vmove) { unsigned socksize, ifasize; int namelen, masklen; @@ -847,9 +847,11 @@ if_attach_internal(struct ifnet *ifp, int vmove, struct if_clone *ifc) if_addgroup(ifp, IFG_ALL); - /* Restore group membership for cloned interfaces. */ - if (vmove && ifc != NULL) - if_clone_addgroup(ifp, ifc); +#ifdef VIMAGE + /* Restore group membership for cloned interface. */ + if (vmove) + if_clone_restoregroup(ifp); +#endif getmicrotime(&ifp->if_lastchange); ifp->if_epoch = time_uptime; @@ -1097,7 +1099,7 @@ if_detach(struct ifnet *ifp) found = if_unlink_ifnet(ifp, false); if (found) { sx_xlock(&ifnet_detach_sxlock); - if_detach_internal(ifp, 0, NULL); + if_detach_internal(ifp, false); sx_xunlock(&ifnet_detach_sxlock); } CURVNET_RESTORE(); @@ -1114,7 +1116,7 @@ if_detach(struct ifnet *ifp) * the cloned interfaces are destoyed as first thing of teardown. */ static int -if_detach_internal(struct ifnet *ifp, int vmove, struct if_clone **ifcp) +if_detach_internal(struct ifnet *ifp, bool vmove) { struct ifaddr *ifa; int i; @@ -1149,15 +1151,6 @@ if_detach_internal(struct ifnet *ifp, int vmove, struct if_clone **ifcp) taskqueue_drain(taskqueue_swi, &ifp->if_linktask); taskqueue_drain(taskqueue_swi, &ifp->if_addmultitask); - /* - * Check if this is a cloned interface or not. Must do even if - * shutting down as a if_vmove_reclaim() would move the ifp and - * the if_clone_addgroup() will have a corrupted string overwise - * from a gibberish pointer. - */ - if (vmove && ifcp != NULL) - *ifcp = if_clone_findifc(ifp); - if_down(ifp); #ifdef VIMAGE @@ -1271,7 +1264,6 @@ finish_vnet_shutdown: static int if_vmove(struct ifnet *ifp, struct vnet *new_vnet) { - struct if_clone *ifc; #ifdef DEV_BPF u_int bif_dlt, bif_hdrlen; #endif @@ -1291,7 +1283,7 @@ if_vmove(struct ifnet *ifp, struct vnet *new_vnet) * mark as dead etc. so that the ifnet can be reattached later. * If we cannot find it, we lost the race to someone else. */ - rc = if_detach_internal(ifp, 1, &ifc); + rc = if_detach_internal(ifp, true); if (rc != 0) return (rc); @@ -1318,7 +1310,7 @@ if_vmove(struct ifnet *ifp, struct vnet *new_vnet) */ CURVNET_SET_QUIET(new_vnet); ifindex_alloc(ifp); - if_attach_internal(ifp, 1, ifc); + if_attach_internal(ifp, true); #ifdef DEV_BPF if (ifp->if_bpf == NULL) diff --git a/sys/net/if_clone.c b/sys/net/if_clone.c index a98e43328e0c..7660c91bd2e1 100644 --- a/sys/net/if_clone.c +++ b/sys/net/if_clone.c @@ -525,49 +525,48 @@ done: return (err); } +#ifdef VIMAGE /* - * if_clone_findifc() looks up ifnet from the current - * cloner list, and returns ifc if found. Note that ifc_refcnt - * is incremented. + * if_clone_restoregroup() is used in context of if_vmove(). + * + * Since if_detach_internal() has removed the interface from ALL groups, we + * need to "restore" interface membership in the cloner's group. Note that + * interface belongs to cloner in its home vnet, so we first find the original + * cloner, and then we confirm that cloner with the same name exists in the + * current vnet. */ -struct if_clone * -if_clone_findifc(struct ifnet *ifp) +void +if_clone_restoregroup(struct ifnet *ifp) { - struct if_clone *ifc, *ifc0; + struct if_clone *ifc; struct ifnet *ifcifp; + char ifc_name[IFCLOSIZ] = { [0] = '\0' }; - ifc0 = NULL; + CURVNET_SET_QUIET(ifp->if_home_vnet); IF_CLONERS_LOCK(); LIST_FOREACH(ifc, &V_if_cloners, ifc_list) { IF_CLONE_LOCK(ifc); LIST_FOREACH(ifcifp, &ifc->ifc_iflist, if_clones) { if (ifp == ifcifp) { - ifc0 = ifc; - IF_CLONE_ADDREF_LOCKED(ifc); + strncpy(ifc_name, ifc->ifc_name, IFCLOSIZ-1); break; } } IF_CLONE_UNLOCK(ifc); - if (ifc0 != NULL) + if (ifc_name[0] != '\0') break; } + CURVNET_RESTORE(); + LIST_FOREACH(ifc, &V_if_cloners, ifc_list) + if (strcmp(ifc->ifc_name, ifc_name) == 0 && + ((ifc->ifc_flags & IFC_NOGROUP) == 0)) + break; IF_CLONERS_UNLOCK(); - return (ifc0); -} - -/* - * if_clone_addgroup() decrements ifc_refcnt because it is called after - * if_clone_findifc(). - */ -void -if_clone_addgroup(struct ifnet *ifp, struct if_clone *ifc) -{ - if ((ifc->ifc_flags & IFC_NOGROUP) == 0) { - if_addgroup(ifp, ifc->ifc_name); - IF_CLONE_REMREF(ifc); - } + if (ifc != NULL) + if_addgroup(ifp, ifc_name); } +#endif /* * A utility function to extract unit numbers from interface names of diff --git a/sys/net/if_clone.h b/sys/net/if_clone.h index ed7d6f4d02d5..e454e5d57845 100644 --- a/sys/net/if_clone.h +++ b/sys/net/if_clone.h @@ -76,8 +76,7 @@ void vnet_if_clone_init(void); int if_clone_create(char *, size_t, caddr_t); int if_clone_destroy(const char *); int if_clone_list(struct if_clonereq *); -struct if_clone *if_clone_findifc(struct ifnet *); -void if_clone_addgroup(struct ifnet *, struct if_clone *); +void if_clone_restoregroup(struct ifnet *); /* The below interfaces are used only by epair(4). */ void if_clone_addif(struct if_clone *, struct ifnet *);