From nobody Tue Nov 23 03:59:44 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 49FC01888F97; Tue, 23 Nov 2021 03:59: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 4Hyr4d0wLCz3mjk; Tue, 23 Nov 2021 03:59: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 E05277880; Tue, 23 Nov 2021 03:59:44 +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 1AN3xi1E073341; Tue, 23 Nov 2021 03:59:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AN3xiXs073340; Tue, 23 Nov 2021 03:59:44 GMT (envelope-from git) Date: Tue, 23 Nov 2021 03:59:44 GMT Message-Id: <202111230359.1AN3xiXs073340@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: 3bc40f39fd86 - main - if_free: add a comment explaining why ifindex_free() is performed here 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: 3bc40f39fd8668f0be71ca6ee5da513054080d7d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=3bc40f39fd8668f0be71ca6ee5da513054080d7d commit 3bc40f39fd8668f0be71ca6ee5da513054080d7d Author: Gleb Smirnoff AuthorDate: 2021-11-23 03:53:12 +0000 Commit: Gleb Smirnoff CommitDate: 2021-11-23 03:59:27 +0000 if_free: add a comment explaining why ifindex_free() is performed here --- sys/net/if.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sys/net/if.c b/sys/net/if.c index 3e640ebfa679..85bf7e91fe1c 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -710,6 +710,22 @@ if_free(struct ifnet *ifp) ifp->if_flags |= IFF_DYING; /* XXX: Locking */ + /* + * XXXGL: An interface index is really an alias to ifp pointer. + * Why would we clear the alias now, and not in the deferred + * context? Indeed there is nothing wrong with some network + * thread obtaining ifp via ifnet_byindex() inside the network + * epoch and then dereferencing ifp while we peform if_free(), + * and after if_free() finished, too. + * + * The reason is the VIMAGE. For some reason it was designed + * to require all sockets drained before destroying, but not all + * ifnets. A vnet destruction calls if_vmove() on ifnet, which + * causes ID change. But ID change and a possible misidentification + * of an ifnet later is a lesser problem, as it doesn't crash kernel. + * A worse problem is that removed interface may outlive the vnet it + * belongs too! The if_free_deferred() would see ifp->if_vnet freed. + */ CURVNET_SET_QUIET(ifp->if_vnet); IFNET_WLOCK(); KASSERT(ifp == ifnet_byindex(ifp->if_index),