From nobody Mon Dec 06 17:32:45 2021 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 C343F18C48F3; Mon, 6 Dec 2021 17:32:45 +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 4J79Vj3MfWz3jk5; Mon, 6 Dec 2021 17:32:45 +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 49FEC1034F; Mon, 6 Dec 2021 17:32:45 +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 1B6HWjMn068500; Mon, 6 Dec 2021 17:32:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B6HWjI0068499; Mon, 6 Dec 2021 17:32:45 GMT (envelope-from git) Date: Mon, 6 Dec 2021 17:32:45 GMT Message-Id: <202112061732.1B6HWjI0068499@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: 8062e5759cb4 - main - ifnet: allocate index at the end of if_alloc_domain() 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: 8062e5759cb4886ad4630d52c212d8ca77ef9c95 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638811965; 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=dBf+LMvWUYGdV1dTm0/kADb2WxjswK5YVbycRb+3SyU=; b=n39dTd3tcJPIw1CM2B2kRm6CKCEuzPMC858NW5UwNZngQtzCTVAPFmdYZYTDRTqeW6zR5H NYqMNoqZdXqD5Az39qsN5pOxDUMjgr1Ir3L7oTCDWE8o8zMIPsqXbFJzMUi0B27aNI/Z/h mK1hQVVFyn7vPIuEchY+DpDH/6mSZiwSxBPE2cCIqQs7coIIphms9vwIIaKiIg86cCK3Mx 43J6CDfn/8eoVmFywV6JAIc7+UkEtYpFpXMvL8vf//KjERzf1PON0l+mdUHrAGlQEY2M5C GyxvgBZg9sWchd8fR3nRQ6Er5I1sV6e4AygTy8YEcFo4ePRUlKOjgZGPs4oG2w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638811965; a=rsa-sha256; cv=none; b=mnxpMLgK0D2dRlHTdr2cK8WlNtLwlXhPDXpbqs/PrR0KAb4iZXe4MBCMGBiBqQI6ZQVejW 2WbIm0bOBXaSWI2rqsNGLOryHJ94uMm7YxnMd2L1yjH+yXo7Wi+5g3qJeCZUA9L09FQhjH A5wpY/9JpzZTF+lw7CHDVU93CBeF1KqjOcGHjHFGlwqnIbroUE5FBXXGPgkgvKFujbIz/0 2RKvS2Y/eWwqAcnwW0F8EfrIbWUq3js+GB5VRDp5toNfPwzg4NhHRUy9Lpc3lFzyuldUKB 56/JGmAa9fAeyOIO379u3aa0NRTZiGSMrFoRXyIAZiMtR3IVeAm1FVFpqK2UrQ== 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=8062e5759cb4886ad4630d52c212d8ca77ef9c95 commit 8062e5759cb4886ad4630d52c212d8ca77ef9c95 Author: Gleb Smirnoff AuthorDate: 2021-12-04 17:49:35 +0000 Commit: Gleb Smirnoff CommitDate: 2021-12-06 17:32:30 +0000 ifnet: allocate index at the end of if_alloc_domain() Now that if_alloc_domain() never fails and actually doesn't expose ifnet to outside we can eliminate IFNET_HOLD and two step index allocation. Reviewed by: kp Differential revision: https://reviews.freebsd.org/D33259 --- sys/net/if.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 75e67c3dd8ba..520e8b4de393 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -331,13 +331,6 @@ struct sx ifnet_detach_sxlock; 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 - * need to select an index before we are ready to expose the interface for - * use, so will use this pointer value to indicate reservation. - */ -#define IFNET_HOLD (void *)(uintptr_t)(-1) - #ifdef VIMAGE #define VNET_IS_SHUTTING_DOWN(_vnet) \ ((_vnet)->vnet_shutdown && (_vnet)->vnet_state < SI_SUB_VNET_DONE) @@ -353,13 +346,11 @@ MALLOC_DEFINE(M_IFMADDR, "ether_multi", "link-level multicast address"); struct ifnet * ifnet_byindex(u_short idx) { - struct ifnet *ifp; if (__predict_false(idx > V_if_index)) return (NULL); - ifp = *(struct ifnet * const volatile *)(V_ifindex_table + idx); - return (__predict_false(ifp == IFNET_HOLD) ? NULL : ifp); + return (V_ifindex_table[idx]); } struct ifnet * @@ -422,6 +413,7 @@ static void ifnet_setbyindex(u_short idx, struct ifnet *ifp) { + ifp->if_index = idx; V_ifindex_table[idx] = ifp; } @@ -608,18 +600,6 @@ if_alloc_domain(u_char type, int numa_domain) else ifp = malloc_domainset(sizeof(struct ifnet), M_IFNET, DOMAINSET_PREF(numa_domain), M_WAITOK | M_ZERO); - restart: - IFNET_WLOCK(); - idx = ifindex_alloc(&old); - if (__predict_false(idx == USHRT_MAX)) { - IFNET_WUNLOCK(); - epoch_wait_preempt(net_epoch_preempt); - free(old, M_IFNET); - goto restart; - } - ifnet_setbyindex(idx, IFNET_HOLD); - IFNET_WUNLOCK(); - ifp->if_index = idx; ifp->if_type = type; ifp->if_alloctype = type; ifp->if_numa_domain = numa_domain; @@ -650,7 +630,19 @@ if_alloc_domain(u_char type, int numa_domain) ifp->if_counters[i] = counter_u64_alloc(M_WAITOK); ifp->if_get_counter = if_get_counter_default; ifp->if_pcp = IFNET_PCP_NONE; - ifnet_setbyindex(ifp->if_index, ifp); + +restart: + IFNET_WLOCK(); + idx = ifindex_alloc(&old); + if (__predict_false(idx == USHRT_MAX)) { + IFNET_WUNLOCK(); + epoch_wait_preempt(net_epoch_preempt); + free(old, M_IFNET); + goto restart; + } + ifnet_setbyindex(idx, ifp); + IFNET_WUNLOCK(); + return (ifp); }